20 Maret, 2024handheight<-read.table("C:/Users/LENOVO/OneDrive/Documents/Learning R/Semester 2/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
summary(handheight)
## Sex Height HandSpan
## Length:167 Min. :57.00 Min. :16.00
## Class :character 1st Qu.:65.00 1st Qu.:19.50
## Mode :character Median :68.00 Median :21.00
## Mean :68.07 Mean :20.86
## 3rd Qu.:71.00 3rd Qu.:22.00
## Max. :78.00 Max. :25.50
plot(handheight$Height, handheight$HandSpan, xlab="Height", ylab="HandSpan", pch=10)
model2 <- lm(HandSpan ~ Height, data = handheight)
summary(model2)
##
## Call:
## lm(formula = HandSpan ~ Height, data = handheight)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.3888 -0.9348 0.0135 1.0365 2.6629
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -3.00161 1.69394 -1.772 0.0782 .
## Height 0.35057 0.02484 14.113 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.301 on 165 degrees of freedom
## Multiple R-squared: 0.5469, Adjusted R-squared: 0.5442
## F-statistic: 199.2 on 1 and 165 DF, p-value: < 2.2e-16
plot(handheight$Height, handheight$HandSpan,
xlab="Height", ylab="HandSpan", pch=10,
main="Plot Uji Asumsi Rata-rata Galat bernilai nol")
c <- (1:167)
handheight <- cbind(handheight, c)
head(handheight)
## 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(handheight$c, model2$residuals,
xlab = "amatan", ylab = "residuals", type = "l",
main = "Plot Uji Asumsi Galat Saling Bebas")
plot(handheight$c,model2$residuals,
xlab="Amatan",ylab="Residuals",
main="Plot Uji Asumsi Galat Saling Bebas")
c <- (1:167)
ytopi <- model2$fitted.values
ei <- model2$residuals
eiterurut <- sort(model2$residuals)
anova(model2)
## 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<-sqrt(1.69)*qnorm((c-0.375)/(167+0.25))
Hi<-cbind(handheight, ytopi, ei, eiterurut, hi)
head(Hi)
## Sex Height HandSpan c ytopi ei eiterurut hi
## 1 Female 68 21.5 1 20.83708 0.66291514 -3.388792 -3.477447
## 2 Male 71 23.5 2 21.88879 1.61120802 -3.187654 -3.038280
## 3 Male 73 22.5 3 22.58993 -0.08993006 -2.791068 -2.797719
## 4 Female 64 18.0 4 19.43481 -1.43480870 -2.687654 -2.626440
## 5 Male 68 23.5 5 20.83708 2.66291514 -2.584240 -2.491399
## 6 Female 59 20.0 6 17.68196 2.31803650 -2.538223 -2.378873
plot(hi,eiterurut,
xlab="hi",ylab="eiterurut",
main="Plot Uji Galat Berdistribusi Normal")
qqnorm(model2$residuals, ylab = "raw residuals")
qqline(model2$residuals)
hist(model2$residuals, main="Histogram Uji Galat Berdistribusi Normal")
hist(model2$residuals, 167, main="Histogram Uji Galat Berdistribusi Normal untuk Interval Data = 167")
boxplot(model2$residuals, main="Boxplot")
ytopi<-model2$fitted.values
ei<-model2$residuals
plot(ytopi,ei,
xlab="fitted values", ylab="residuals",
main="Plot Uji Ragam Galat Konstan")
plot(handheight$Height, handheight$HandSpan, main="Plot Data")
plot(handheight$Height, handheight$HandSpan, main="Plot Data")
Nama Anggota