Académique Documents
Professionnel Documents
Culture Documents
RenitaSetyowati (16305141053)
Rohmadi Ahmad Ridwan (16305141057)
Diana Islamiyati (16305141070)
Laila BadriyatusZahro (16305144014)
Matematika E 2016
Analisis Regresi Terapan
Script :
#regresi polinomial kuadratik
library(readr)
LungCapData2=read.table("E:\\LungCapData.txt", header=T)
View(LungCapData2)
names(LungCapData2)
attach(LungCapData2)
summary(LungCapData2)
head(LungCapData2)
plot(Height, LungCap, main="Polynomial Regression")
model1<-lm(LungCap~Height,LungCapData2)
summary(model1)
abline(model1,lwd=3,col="red")
#cara 1
model2a<-lm(LungCap~Height+I(Height^2),LungCapData2)
summary(model2a)
#cara 2
HeightSquare<-(LungCapData2$Height)^2
model2b<-lm(LungCap~Height+HeightSquare,LungCapData2)
summary(model2b)
#cara 3
model2c<-lm(LungCap~poly(Height,degree=2,raw=T),LungCapData2)
#orthogonal polynomials raw=F
summary(model2c)
model3<-lm(LungCap~Height+I(Height^2)+I(Height^3),LungCapData2)
summary(model3)
lines(smooth.spline(Height,predict(model3)),col="green",lwd=3,lt
y=3)
legend(46,15,legend=c("model1:linear","model2c:poly
x^2","model3:poly x^3"),
col=c("red","blue","green"),lty=c(1,1,3),lwd=3,bty="n",cex=0.9)
Output :
Call:
lm(formula = LungCap ~ Height, data = LungCapData2)
Residuals:
Min 1Q Median 3Q Max
-3.3619 -0.7014 -0.0032 0.7787 3.2938
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -13.996829 0.367451 -38.09 <2e-16 ***
Height 0.337157 0.005633 59.86 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> abline(model1,lwd=3,col="red")
> #cara 1
> model2a<-lm(LungCap~Height+I(Height^2),LungCapData2)
> summary(model2a)
Call:
lm(formula = LungCap ~ Height + I(Height^2), data = LungCapData2)
Residuals:
Min 1Q Median 3Q Max
-3.4210 -0.6812 -0.0175 0.7805 3.3711
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -1.875e+01 2.656e+00 -7.059 3.96e-12 ***
Height 4.876e-01 8.344e-02 5.843 7.75e-09 ***
I(Height^2) -1.175e-03 6.502e-04 -1.807 0.0712 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> #cara 2
> HeightSquare<-(LungCapData2$Height)^2
> model2b<-lm(LungCap~Height+HeightSquare,LungCapData2)
> summary(model2b)
Call:
lm(formula = LungCap ~ Height + HeightSquare, data = LungCapData2)
Residuals:
Min 1Q Median 3Q Max
-3.4210 -0.6812 -0.0175 0.7805 3.3711
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -1.875e+01 2.656e+00 -7.059 3.96e-12 ***
Height 4.876e-01 8.344e-02 5.843 7.75e-09 ***
HeightSquare -1.175e-03 6.502e-04 -1.807 0.0712 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Call:
lm(formula = LungCap ~ poly(Height, degree = 2, raw = T), data = LungCapData2
)
Residuals:
Min 1Q Median 3Q Max
-3.4210 -0.6812 -0.0175 0.7805 3.3711
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -1.875e+01 2.656e+00 -7.059 3.96e-12 ***
poly(Height, degree = 2, raw = T)1 4.876e-01 8.344e-02 5.843 7.75e-09 ***
poly(Height, degree = 2, raw = T)2 -1.175e-03 6.502e-04 -1.807 0.0712 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> model3<-lm(LungCap~Height+I(Height^2)+I(Height^3),LungCapData2)
> summary(model3)
Call:
lm(formula = LungCap ~ Height + I(Height^2) + I(Height^3), data = LungCapData
2)
Residuals:
Min 1Q Median 3Q Max
-3.4258 -0.6834 -0.0120 0.7801 3.3719
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -1.180e+01 1.806e+01 -0.653 0.514
Height 1.531e-01 8.639e-01 0.177 0.859
I(Height^2) 4.132e-03 1.366e-02 0.303 0.762
I(Height^3) -2.777e-05 7.140e-05 -0.389 0.697
> lines(smooth.spline(Height,predict(model3)),col="green",lwd=3,lty=3)
> legend(46,15,legend=c("model1:linear","model2c:poly x^2","model3:poly x^3")
, col=c("red","blue","green"),lty=c(1,1,3),lwd=3,bty="n",cex=0.9)
>
> #regresi polinomial orde dua
> HeightSquare<-(LungCapData2$Height)^2
> AgeSquare<-(LungCapData2$Age)^2
> HeightAge<-(LungCapData2$Height)*(LungCapData2$Age)
> model4<-lm(LungCap~Height+Age+HeightSquare+AgeSquare+HeightAge,LungCapData2
)
> summary(model4)
Call:
lm(formula = LungCap ~ Height + Age + HeightSquare + AgeSquare +
HeightAge, data = LungCapData2)
Residuals:
Min 1Q Median 3Q Max
-3.4814 -0.6907 -0.0120 0.7206 3.2006
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -18.145561 4.217388 -4.303 1.92e-05 ***
Height 0.528582 0.173625 3.044 0.00242 **
Age -0.134723 0.273887 -0.492 0.62295
HeightSquare -0.002528 0.001851 -1.365 0.17254
AgeSquare -0.006023 0.006361 -0.947 0.34400
HeightAge 0.006278 0.006262 1.003 0.31643
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Interpretasi
Dari cara 1 sampai cara 3, dapat ditarik kesimpulan :
Karena p-value = 2.2e-16 maka H0 ditolak. Jadi dengan taraf nyata 0.05 dapat disimpulkan
bahwa terdapat perbedaan antara model tersebut.
> data.frame(coef(model4),confint(model4))
coef.model4. X2.5.. X97.5..
(Intercept) -18.145560596 -26.425427088 -9.865694104
Height 0.528581953 0.187709052 0.869454854
Age -0.134722648 -0.672436902 0.402991606
HeightSquare -0.002528113 -0.006163053 0.001106827
AgeSquare -0.006023500 -0.018512084 0.006465085
HeightAge 0.006277631 -0.006016063 0.018571324
Gambar 1
Gambar 2
Gambar 3
Gambar 4
Gambar 5