logo

[basic-stat-r] 절편의 고정

cars 데이터에서 dist는 거리를 뜻한다. 앞선 분석 결과에서 speed가 0일 때 dist가 -17.5791이 되는데 거리가 마이너스가 될 수는 없으므로 해석이 어색하다.

이런 경우 모형식에 0 +를 추가하여 모형에서 절편을 제거한다. 절편을 제거하면, 절편을 0으로 고정시킨 것과 같아진다.

model = lm(dist ~ 0 + speed, data = cars)
summary(model)

Call:
lm(formula = dist ~ 0 + speed, data = cars)

Residuals:
    Min      1Q  Median      3Q     Max
-26.183 -12.637  -5.455   4.590  50.181

Coefficients:
      Estimate Std. Error t value Pr(>|t|)
speed   2.9091     0.1414   20.58   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 16.26 on 49 degrees of freedom
Multiple R-squared:  0.8963,	Adjusted R-squared:  0.8942
F-statistic: 423.5 on 1 and 49 DF,  p-value: < 2.2e-16

단, R제곱을 해석할 때 주의가 필요하다. 절편이 있는 경우와 없는 경우 계산 방식이 다르기 때문이다. 절편이 있는 경우에 R제곱은 종속변수의 분산에서 설명하는 비율을 나타내지만, 절편이 없는 경우는 종속변수의 제곱의 평균에서 설명하는 비율을 나타낸다.

Previous
회귀분석 실시하기