반로그함수 모형을 전미분하면
인데 의 추정치는 1.4이지만 X 및 Y의 어떤 자료로 탄력성을 구하는 지 불 분명하므로 선형함수 모형은 기울기를 구하는데 적합하다.
Coefficients:
Estimate Std. Error t value Pr(>|t|) (Intercept) 0.400 1.625 0.246 0.8214 x 1.400 0.383 3.656 0.0354 *
---Signif. codes:
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
둘째, 전대수함수 모형을 추정하면 탄력도는 0.7755로써 독립변수 X가 1% 상승 하면 종속변수 Y는 0.7755% 상승하는 것으로 해석할 수 있다. 동 모형에서 기울기 는
인데 의 추정치는 0.7755이지만 X 및 Y의 어떤 자료로 기울기를 구하는 지 불분명하므로 전대수함수 모형은 탄력도를 구하는데 적합하다.
Coefficients:
Estimate Std. Error t value Pr(>|t|) (Intercept) 0.7112 0.3150 2.258 0.1092 lx 0.7755 0.2296 3.377 0.0432 *
---Signif. codes:
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
b2-ch2-3.R의 실행결과
> x<-c(2,3,4,5,6)
> y<-c(4,4,6,6,10)
> x;y
[1] 2 3 4 5 6
[1] 4 4 6 6 10
> lx<-log(x)
> ly<-log(y)
> lx;ly
[1] 0.6931472 1.0986123 1.3862944 1.6094379 1.7917595 [1] 1.386294 1.386294 1.791759 1.791759 2.302585
> rx<-1/x
> rx
[1] 0.5000000 0.3333333 0.2500000 0.2000000 0.1666667
> lm(y~x)
Call:
lm(formula = y ~ x)
Coefficients:
(Intercept) x 0.4 1.4
> ols1<-lm(y~x)
> summary(ols1)
Call:
lm(formula = y ~ x)
Residuals:
1 2 3 4 5 8.000e-01 -6.000e-01 7.404e-17 -1.400e+00 1.200e+00
Coefficients:
Estimate Std. Error t value Pr(>|t|) (Intercept) 0.400 1.625 0.246 0.8214 x 1.400 0.383 3.656 0.0354 *
---Signif. codes:
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 1.211 on 3 degrees of freedom
Multiple R-squared: 0.8167, Adjusted R-squared: 0.7556 F-statistic: 13.36 on 1 and 3 DF, p-value: 0.03535
> lm(ly~lx)
Call:
lm(formula = ly ~ lx)
Coefficients:
(Intercept) lx 0.7112 0.7755
> ols2<-lm(ly~lx)
> summary(ols2)
Call:
lm(formula = ly ~ lx)
Residuals:
1 2 3 4 5 0.137490 -0.176966 0.005388 -0.167670 0.201757
Coefficients:
Estimate Std. Error t value Pr(>|t|) (Intercept) 0.7112 0.3150 2.258 0.1092 lx 0.7755 0.2296 3.377 0.0432 *
---Signif. codes:
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.1992 on 3 degrees of freedom
Multiple R-squared: 0.7917, Adjusted R-squared: 0.7223 F-statistic: 11.41 on 1 and 3 DF, p-value: 0.04318
> lm(y~rx)
Call:
lm(formula = y ~ rx)
Coefficients:
(Intercept) rx 10.09 -14.11
> ols3<-lm(y~rx)
> summary(ols3)
Call:
lm(formula = y ~ rx)
Residuals:
1 2 3 4 5 0.9624 -1.3887 -0.5643 -1.2696 2.2602
Coefficients:
Estimate Std. Error t value Pr(>|t|) (Intercept) 10.091 2.138 4.719 0.018 * rx -14.107 6.821 -2.068 0.130
---Signif. codes:
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 1.816 on 3 degrees of freedom
Multiple R-squared: 0.5878, Adjusted R-squared: 0.4504 F-statistic: 4.278 on 1 and 3 DF, p-value: 0.1305
> lm(ly~x)
Call:
lm(formula = ly ~ x)
Coefficients:
(Intercept) x 0.8365 0.2238
> ols4<-lm(ly~x)
> summary(ols4)
Call:
lm(formula = ly ~ x)
Residuals:
1 2 3 4 5 0.10217 -0.12164 0.06002 -0.16378 0.12324
Coefficients:
Estimate Std. Error t value Pr(>|t|) (Intercept) 0.8365 0.2062 4.057 0.0270 * x 0.2238 0.0486 4.605 0.0193 *
---Signif. codes:
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.1537 on 3 degrees of freedom Multiple R-squared: 0.8761, Adjusted R-squared: 0.8348
F-statistic: 21.21 on 1 and 3 DF, p-value: 0.01925
> lm(y~lx)
Call:
lm(formula = y ~ lx)
Coefficients:
(Intercept) lx -0.2655 4.7615
> ols5<-lm(y~lx)
> summary(ols5)
Call:
lm(formula = y ~ lx)
Residuals:
1 2 3 4 5 0.9650 -0.9656 -0.3354 -1.3979 1.7339
Coefficients:
Estimate Std. Error t value Pr(>|t|) (Intercept) -0.2655 2.4046 -0.110 0.9191 lx 4.7615 1.7528 2.716 0.0728 .
---Signif. codes:
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 1.521 on 3 degrees of freedom
Multiple R-squared: 0.711, Adjusted R-squared: 0.6146 F-statistic: 7.379 on 1 and 3 DF, p-value: 0.07277
(예제 2-1)을 OLS, MLE, LAD로 추정한 b2-ch2-5.R을 실행해 보면 다음과 같 은 결과를 얻을 수 있다. 그림에서 점선은 보통최소자승법에 의한 추정 회귀식이고, 파란 선은 최소절대편차 추정법에 의한 추정 회귀식을 나타낸다,
첫째, OLS에 의한 회귀계수의 추정치는 이고, 교란항의 표준오차 추정치는 이다.
둘째, LAD에 의한 회귀계수의 추정치는 인데 해가 유일하지 않 다는 메시지가 나왔다.
이를 좀 더 구체적으로 살펴보기 위하여 다음과 같은 LAD에 의한 두 개의 추정 회귀식을 얻는 b2-ch2-4.R을 실행해 보면 아래 그림에서 확인할 수 있듯이 최소한 두 개의 데이터 포인트를 지나는 다음과 같은 두 개의 추정 회귀식을 얻을 수 있다.
Coefficients:
Estimate Std. Error t value Pr(>|t|) (Intercept) 0.400 1.625 0.246 0.8214 x 1.400 0.383 3.656 0.0354 *
---Signif. codes:
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 1.211 on 3 degrees of freedom
Coefficients:
coefficients lower bd upper bd (Intercept) 2.000000e+00 -1.797693e+308 1.797693e+308 x 1.000000e+00 -1.797693e+308 1.797693e+308
1: In rq.fit.br(x, y, tau = tau, ...) : Solution may be nonunique 2: In rq.fit.br(x, y, tau = tau, ...) : Solution may be nonunique 3: In rq.fit.br(x, y, tau = tau, ci = TRUE, ...) :
Solution may be nonunique
추정 회귀식 1 : 추정 회귀식 2 :
이 두 회귀선이 교차하면서 발생하는 두 회귀선 사이의 영역에 최소절댓값 추정 법의 다수 해가 존재한다.
b2-ch2-4.R의 실행결과
> library(openxlsx)
> library(bbmle)
> library(quantreg)
> x<-c(2,3,4,5,6)
> y<-c(4,4,6,6,10)
> # LAD estimator
> taus<-c(0.5, 0.7)
> rq(y~x) Call:
rq(formula = y ~ x)
Coefficients:
(Intercept) x 2 1
Degrees of freedom: 5 total; 3 residual
> lad<-rq(y~x, tau=taus)
> summary(lad)
Call: rq(formula = y ~ x, tau = taus)
tau: [1] 0.5
Coefficients:
coefficients lower bd upper bd (Intercept) 2.000000e+00 -1.797693e+308 1.797693e+308 x 1.000000e+00 -1.797693e+308 1.797693e+308
Call: rq(formula = y ~ x, tau = taus)
tau: [1] 0.7
Coefficients:
coefficients lower bd upper bd (Intercept) 1.000000e+00 -1.797693e+308 1.797693e+308 x 1.500000e+00 -1.797693e+308 1.797693e+308
> plot(x,y,type = "n", cex = .8,xlim=c(0,7), ylim=c(0,11))
> points(x,y,cex = .8,col="blue",xlim=c(0,7), ylim=c(0,11))
> abline(rq(y~x, tau=0.5),col="red",lty = 2)
> abline(rq(y~x, tau=0.7), col="blue") Warning messages:
1: In rq.fit.br(x, y, tau = tau, ...) : Solution may be nonunique 2: In rq.fit.br(x, y, tau = tau, ...) : Solution may be nonunique 3: In rq.fit.br(x, y, tau = tau, ci = TRUE, ...) :
Solution may be nonunique
4: In rq.fit.br(x, y, tau = tau, ci = TRUE, ...) : Solution may be nonunique
5: In rq.fit.br(x, y, tau = tau, ...) : Solution may be nonunique
셋째, MLE에 의한 회귀계수의 추정치는 이고, 교란항의 표준오 차 추정치는 이다. 회귀계수의 추정치는 OLS 및 MLE가 동일하지만 교 란항의 표준편차 추정치는 다르게 나타나고 있다. 그 이유는 교란항의 분산을 구할 때, OLS의 경우 잔차의 제곱의 합을 자유도(여기서는 3)로 나누어 주는 반면에 MLE의 경우 잔차의 제곱의 합을 관측치 수(여기서는 5)로 나누어주기 때문이다.
0 1 2 3 4 5 6 7
0246810
x
y
Coefficients:
Estimate Std. Error z value Pr(z) b0 0.40000 1.25857 0.3178 0.750621 b1 1.40000 0.29665 4.7194 2.365e-06 ***
sigma 0.93808 0.29665 3.1623 0.001565 **
---Signif. codes:
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
b2-ch2-5.R의 실행결과 library(openxlsx)
library(bbmle) library(quantreg)
x<-c(2,3,4,5,6) y<-c(4,4,6,6,10)
(n<-length(y))
# OLS estimator lm(y~x)
ols<-lm(y~x) summary(ols) confint(ols)
# LAD estimator
#taus<-c(.05,.1,.25,.75,.9, 0.95) rq(y~x)
lad<-rq(y~x) summary(lad)
# MLE
fn<-function(b0, b1, sigma) {
(n/2)*log(sigma^2)+1/(2*sigma^2)*(sum((y-b0-b1*x)^2)) }
res<-mle2(fn,start=list(b0=0.5, b1=0.5, sigma=1)) summary(res)
plot(x,y,type = "n", cex=.8, xlim=c(0,7), ylim=c(0,11)) points(x,y,cex=.8,col="blue",xlim=c(0,7), ylim=c(0,11)) abline(lm(y~x),col="red",lty = 2)
abline(rq(y~x), col="blue")
한편, 가상적인 데이터를 이용하여 OLS, MLE, LAD로 추정한 b2-ch2-6.R을 실 행해 보면 다음과 같은 결과를 얻을 수 있는데 우리가 관심을 가지고 있는 기울기 의 경우 세 추정치 모두 거의 같고, 특히 OLS 및 MEL 추정치는 거의 같음을 보여 주고 있고, 그림에서 보듯이 OLS와 LAD의 추정 회귀식도 유사하여 어 세 가지 추 정방법의 유용성을 확인할 수 있다.
0 1 2 3 4 5 6 7
0246810
x
y
구분 OLS LAD MLE
0.47172 0.6 0.471688
0.59583 0.6 0.595838
b2-ch2-6.R의 실행결과
> library(openxlsx)
> library(bbmle)
> library(quantreg)
> x<-c(0,1.9,4,6,8.5,0.5,2.5,4.5,6.6,9,1,3,5,7,10,1.5,3.5,5.5,7)
> y<-c(1,2,2.7,3.6,6,0.9,2.4,3.5,2.7,6,0.7,3.2,1,5.7,7.3,1.5,2,4,4.6)
> (n<-length(y)) [1] 19
> # OLS estimator
> lm(y~x)
Call:
lm(formula = y ~ x)
Coefficients:
(Intercept) x 0.4717 0.5958
> ols<-lm(y~x)
> summary(ols)
Call:
lm(formula = y ~ x)
Residuals:
Min 1Q Median 3Q Max -2.4509 -0.2613 0.1658 0.4512 1.0575
Coefficients:
Estimate Std. Error t value Pr(>|t|) (Intercept) 0.47172 0.38219 1.234 0.234 x 0.59583 0.07059 8.440 1.75e-07 ***
---Signif. codes:
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.8889 on 17 degrees of freedom Multiple R-squared: 0.8073, Adjusted R-squared: 0.796 F-statistic: 71.24 on 1 and 17 DF, p-value: 1.746e-07
> confint(ols)
2.5 % 97.5 % (Intercept) -0.3346268 1.2780661 x 0.4468945 0.7447682
> # LAD estimator
> rq(y~x) Call:
rq(formula = y ~ x)
Coefficients:
(Intercept) x 0.6 0.6
Degrees of freedom: 19 total; 17 residual
> lad<-rq(y~x, model=T)
> summary(lad)
Call: rq(formula = y ~ x, model = T)
tau: [1] 0.5
Coefficients:
coefficients lower bd upper bd (Intercept) 0.60000 0.06835 0.95858 x 0.60000 0.51754 0.67755
> # MLE
> fn<-function(b0, b1, sigma) {
+ (n/2)*log(sigma^2)+1/(2*sigma^2)*(sum((y-b0-b1*x)^2)) + }
> res<-mle2(fn,start=list(b0=0.5, b1=0.5, sigma=1))
> summary(res)
Maximum likelihood estimation
Call:
mle2(minuslogl = fn, start = list(b0 = 0.5, b1 = 0.5, sigma = 1))
Coefficients:
Estimate Std. Error z value Pr(z) b0 0.471688 0.361513 1.3048 0.192 b1 0.595838 0.066774 8.9233 < 2.2e-16 ***
sigma 0.840795 0.136395 6.1644 7.074e-10 ***
---Signif. codes:
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
-2 log L: 12.41055
> plot(x,y,type = "n", cex = .8)
> points(x,y,cex = .8,col="blue")
> abline(lm(y~x),col="red",lty = 2)
> abline(rq(y~x), col="blue")
8. OLS 추정량의 특성
좋은 추정량의 기준으로 볼 때 OLS 추정량인 은 어떠한 추정량인가? 이에 대한 대답은 은 선형성, 불편성 및 최소분산의 특성을 가지고 있다는 것이다.
이러한 특성을 가진 추정량을 최량선형불편추정량(Best Linear Unbiased Estimator: BLUE)이라고 하는데 OLS 추정량은 BLUE임을 보여주는 것이 Gauss-Markov 정리이다.
Gauss-Markov 정리
고전적 회귀모형이 있을 때 최소자승법으로 구한 추정량 및 는 선형불편추정량 중에서 최소의 분산을 갖는다. 즉, 최소자승법으로 구한 추정량은 BLUE(Best Linear Unbiased Estimator)이다
0 2 4 6 8 10
1234567
x
y