Professional Documents
Culture Documents
SCRIPT & CONSOLE LungCap2
SCRIPT & CONSOLE LungCap2
SCRIPT & CONSOLE LungCap2
#Polynomial Regression
attach(LungCapData2)
summary(LungCapData2)
#Checking Linearity
#Regression
model1<-lm(LungCap~Height)
summary(model1)
#Wrong Method
model2<-lm(LungCap~Height+Height^2)
summary(model2)
model2<-lm(LungCap~Height + I(Height^2))
summary(model2)
summary(model2lagi)
summary(model2)
#Line for Model 2
#Comparing 2 models
anova(model1, model2)
summary(model3)
anova(model2, model3)
#Legend
legend(46,15, legend = c("model1 : linear", "model2 : poly x ^2", "model3 : poly x ^3"), col =
c("red","blue","green"), lty = c(1,1,3), lwd = 3, bty = "n", cex = 0.9)
CONSOLE
> library(readxl)
> LungCapData2 <- read_excel("D:/MBA UGM/Kuliah online PRA MBA/Statistic for Business
Decision/R Studio/LungCapData2.xlsx")
> View(LungCapData2)
> attach(LungCapData2)
> summary(LungCapData2)
1st Qu.: 8.000 1st Qu.: 3.943 1st Qu.:57.00 Class :character
Smoke
Length:654
Class :character
Mode :character
> #Regression
> model1<-lm(LungCap~Height)
> summary(model1)
Call:
Residuals:
Coefficients:
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> model2<-lm(LungCap~Height+Height^2)
> summary(model2)
Call:
Residuals:
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> summary(model2)
Call:
Residuals:
Coefficients:
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> summary(model2lagi)
Call:
Residuals:
Coefficients:
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> summary(model2)
Call:
Coefficients:
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> #Apakah model2 lebih baik dari model1? Cek menggunakan anova
1 652 1088.41
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> #Cubic Method --> dipangkatkan 3, apakah lebih signifikan?
> summary(model3)
Call:
Residuals:
Coefficients:
1 651 998.09
> #Legend
> legend(46,15, legend = c("model1 : linear", "model2 : poly x ^2", "model3 : poly x ^3"), col =
c("red","blue","green"), lty = c(1,1,3), lwd = 3, bty = "n", cex = 0.9)