Model linier dan NON-linier


Sebelumnya telah dibahas bentuk umum dari model regresi linier adalah sebagai berikut:
Y=ß0+ß1X1+...+ßpXp+?
Atau,
yi=ß0+ß1x1i+...+ßpxpi+?i;i=1,...,n
dengan n adalah ukuran sampel.
Contoh 1
Dengan contoh data:
n<-1000
a<-20
b<-3
x<-runif(n,0,60)
epsilon<-rnorm(n,0,1)
y<-a+(b+epsilon)*x+epsilon
mydata<-data.frame(x,y)
plot(x,y)
plot1
reg<-lm(y~x, data=mydata)
summary(reg)
## 
## Call:
## lm(formula = y ~ x, data = mydata)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -139.793  -16.406   -0.279   16.384  136.525 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 19.69017    2.24159   8.784   <2e-16 ***
## x            2.99270    0.06405  46.726   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 35.51 on 998 degrees of freedom
## Multiple R-squared:  0.6863, Adjusted R-squared:  0.686 
## F-statistic:  2183 on 1 and 998 DF,  p-value: < 2.2e-16
diperoleh taksiran regresi:
y^=21.54118+2.92189
Contoh 2 Bagaimana dengan data berikut?
n<-10
x<-runif(n,1,5)
x1<-1/x
epsilon<-rnorm(n,0,1)
a<-20
b<--5
y<-a+b*x1+epsilon
plot(x1,y)
plot2
reg1<-lm(y~x1)
summary(reg1)
## 
## Call:
## lm(formula = y ~ x1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.0220 -1.0983 -0.2073  0.8132  2.4107 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   20.512      1.131  18.136 8.78e-08 ***
## x1            -4.855      2.650  -1.832    0.104    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.546 on 8 degrees of freedom
## Multiple R-squared:  0.2956, Adjusted R-squared:  0.2076 
## F-statistic: 3.358 on 1 and 8 DF,  p-value: 0.1043
dengan taksiran regresi
y1=19.4661+-3.8671x
Contoh 3 Bagaimana dengan data berikut?
n<-10
x<-runif(n,1,5)
x2<-x^2
epsilon<-rnorm(n,0,1)
a<-20
b1<--5
b2<-3
y<-a+b1*x+b2*x2+epsilon
plot(x,y)
plot3
reg2<-lm(y~x+x2)
summary(reg2)
## 
## Call:
## lm(formula = y ~ x + x2)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.51684 -0.30445  0.04815  0.25249  0.70930 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  20.6618     1.1983  17.243 5.42e-07 ***
## x            -5.5020     0.8793  -6.257 0.000421 ***
## x2            3.1381     0.1447  21.689 1.12e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4425 on 7 degrees of freedom
## Multiple R-squared:  0.9994, Adjusted R-squared:  0.9992 
## F-statistic:  5675 on 2 and 7 DF,  p-value: 5.813e-12
dengan model:
y=ß0+ß1x1+ß2x2
dengan x1=x,x2=x2, diperoleh taksiran regresi
y^=20.1519+-5.3006x1+3.0358x2
Contoh 4 Bagaimana dengan data berikut?
n<-10
x<-runif(n,1,5)
x3<-log(x)
epsilon<-rnorm(n,0,1)
a<-20
b<--5
y<-a+b*x3+epsilon
plot(x,y)
plot4
reg3<-lm(y~x3)
summary(reg3)
## 
## Call:
## lm(formula = y ~ x3)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.9032 -0.3924 -0.2774  0.4752  1.4207 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  19.5957     0.7114  27.547 3.25e-09 ***
## x3           -4.5603     0.6752  -6.754 0.000145 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.031 on 8 degrees of freedom
## Multiple R-squared:  0.8508, Adjusted R-squared:  0.8321 
## F-statistic: 45.61 on 1 and 8 DF,  p-value: 0.0001445
dengan model:
y=ß0+ß1log(x)
diperoleh taksiran regresi
y^=20.3090+-5.3388log(x)
Contoh 5 Bagaimana dengan data berikut?
n<-10
x<-runif(n,1,5)
epsilon<-rnorm(n,0,1)
a<-1
b<-2
y<-exp(a+b*x+epsilon)
reg4<-lm(y~x)
summary(reg4)
## 
## Call:
## lm(formula = y ~ x)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -11730  -5874  -1888   3510  18550 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)  
## (Intercept)   -25745      11516  -2.236   0.0558 .
## x              11780       4000   2.945   0.0186 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9384 on 8 degrees of freedom
## Multiple R-squared:  0.5203, Adjusted R-squared:  0.4603 
## F-statistic: 8.675 on 1 and 8 DF,  p-value: 0.01856
par(mfrow=c(1,2))
plot(x,y)
abline(reg=lm(y~x), col="red", lwd=2, main="Model Reg4")
plot(x,log(y))
abline(reg=lm(log(y)~x), col="blue", lwd=2, main="Model Reg5")
diperoleh hasil taksiran:
y^=-12411+8145x
Bandingkan dengan hasil berikut:
reg5<-lm(log(y)~x)
summary(reg5)
## 
## Call:
## lm(formula = log(y) ~ x)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.2907 -0.5751  0.0904  0.3546  1.6692 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  -1.3557     1.0730  -1.264    0.242    
## x             2.9665     0.3726   7.961 4.52e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8743 on 8 degrees of freedom
## Multiple R-squared:  0.8879, Adjusted R-squared:  0.8739 
## F-statistic: 63.38 on 1 and 8 DF,  p-value: 4.524e-05
log(y)^=0.7368+2.0703x
Dari kelima contoh di atas, yang manakah yang merupakan model linier? Kenapa?

Tidak ada komentar:

Posting Komentar

Relevant & Respectful Comments Only.