Data yang digunakan dalam praktikum ini adalah data handheight.
handheight<-read.table(file = "C:/Users/qurro/OneDrive/Documents/Semester_2/Analisis Regresi/handheight.txt",
header = TRUE)
head(handheight)
## Sex Height HandSpan
## 1 Female 68 21.5
## 2 Male 71 23.5
## 3 Male 73 22.5
## 4 Female 64 18.0
## 5 Male 68 23.5
## 6 Female 59 20.0
modelhandheight <- lm(HandSpan ~ Height, data = handheight)
modelhandheight
##
## Call:
## lm(formula = HandSpan ~ Height, data = handheight)
##
## Coefficients:
## (Intercept) Height
## -3.0016 0.3506
#Asumsi 1: Rata-rata galat diasumsikan bernilai nol
plot(handheight$Height,modelhandheight$residuals,
xlab="Height(X)",ylab="Residuals",
main="Plot Uji Asumsi Rata2 Galat bernilai nol")
#Asumsi 2: Galat saling bebas
c <- (1:167)
handheightbaru <- cbind(handheight, c); head(handheightbaru)
## Sex Height HandSpan c
## 1 Female 68 21.5 1
## 2 Male 71 23.5 2
## 3 Male 73 22.5 3
## 4 Female 64 18.0 4
## 5 Male 68 23.5 5
## 6 Female 59 20.0 6
#Plot Uji Asumsi Galat Saling Bebas
plot(handheightbaru$c, modelhandheight$residuals,
xlab = "amatan", ylab = "residuals", type = "l",
main = "Plot Uji Asumsi Galat Saling Bebas")
#Asumsi 3: Galat berdistribusi normal
c <- (1:167)
ytopi.handheight <- modelhandheight$fitted.values
ei.handheight <- modelhandheight$residuals
eiterurut.handheight <- sort(modelhandheight$residuals)
anova(modelhandheight)
## Analysis of Variance Table
##
## Response: HandSpan
## Df Sum Sq Mean Sq F value Pr(>F)
## Height 1 337.08 337.08 199.17 < 2.2e-16 ***
## Residuals 165 279.25 1.69
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
hi.handheight <- sqrt(1.69)*qnorm((c-0.375)/(167+0.25))
hi.shandheight <- cbind(handheightbaru, ytopi.handheight, ei.handheight,
eiterurut.handheight, hi.handheight);head(hi.handheight)
## [1] -3.477447 -3.038280 -2.797719 -2.626440 -2.491399 -2.378873
#Plot Uji Galat Berdistribusi Normal
plot(hi.handheight, eiterurut.handheight, xlab = "hi", ylab = "ei terurut",
main = "Plot Uji Galat Berdistribusi Normal")
hist(modelhandheight$residuals, 5)
qqnorm(modelhandheight$residuals, ylab = "raw residuals")
qqline(modelhandheight$residuals)
hist(modelhandheight$residuals,25)
boxplot(modelhandheight$residuals)
#Asumsi 4: Ragam galat diasumsikan konstan
ytopi.handheight <- modelhandheight$fitted.values
ei.handheight <- modelhandheight$residuals
plot(ytopi.handheight, ei.handheight,
xlab = "fitted values", ylab = "residuals",
main = "Plot Uji Ragam Galat Konstan")
abline(h=0, col="red", lty=2)
#Asumsi 5: X dan Y berhubungan linear
plot(handheight$Height,handheight$HandSpan,
main = "Plot Data")
abline(modelhandheight, col="red")
#Asumsi 6: tidak ada outliner
plot(handheight$Height, handheight$HandSpan,
main = "Plot Data handheight")
Sekian Praktikum dari kelompok kami. Mohon maaf jika ada kesalahan, tapi sepertinya tidak, karena cewek selalu benar.