This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
# ASUMSI REGRESI LINEAR SEDERHANA
library(readxl)
ANREGP4<-read_excel("C:/Users/Me/Downloads/ANREGP4.xlsx")
head(ANREGP4)
## # A tibble: 6 × 3
## Sex Height HandSpan
## <chr> <chr> <chr>
## 1 Female 68 21.5
## 2 Male 71 23.5
## 3 Male 73 22.5
## 4 Female 64 18
## 5 Male 68 23.5
## 6 Female 59 20
# Eksplorasi data
summary(ANREGP4)
## Sex Height HandSpan
## Length:167 Length:167 Length:167
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
plot(ANREGP4$Height, ANREGP4$HandSpan,xlab="Height",ylab="HandSpan",pch=16)
model2 <- lm(HandSpan~Height, data=ANREGP4)
summary(model2)
##
## Call:
## lm(formula = HandSpan ~ Height, data = ANREGP4)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.1429 -0.7273 0.0000 0.8536 2.4333
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 16.000 1.295 12.354 < 2e-16 ***
## Height59 4.000 1.832 2.184 0.030614 *
## Height60 2.333 1.496 1.560 0.120932
## Height61 2.000 1.586 1.261 0.209429
## Height61.5 2.750 1.586 1.734 0.085146 .
## Height62 2.125 1.448 1.468 0.144446
## Height63 3.500 1.374 2.548 0.011903 *
## Height63.75 5.500 1.832 3.003 0.003162 **
## Height64 3.036 1.341 2.264 0.025062 *
## Height64.25 6.000 1.832 3.276 0.001324 **
## Height64.5 3.500 1.832 1.911 0.058035 .
## Height65 3.812 1.374 2.775 0.006258 **
## Height66 3.727 1.353 2.755 0.006632 **
## Height67 4.605 1.329 3.466 0.000700 ***
## Height67.5 4.500 1.496 3.009 0.003102 **
## Height68 5.067 1.338 3.788 0.000224 ***
## Height69 5.143 1.341 3.836 0.000187 ***
## Height70 6.000 1.385 4.333 2.76e-05 ***
## Height71 5.433 1.338 4.062 8.02e-05 ***
## Height72 5.722 1.365 4.191 4.85e-05 ***
## Height73 6.650 1.358 4.896 2.63e-06 ***
## Height74 7.650 1.358 5.632 9.23e-08 ***
## Height75 6.625 1.448 4.575 1.03e-05 ***
## Height76 7.667 1.496 5.126 9.49e-07 ***
## Height78 9.500 1.832 5.187 7.24e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.295 on 142 degrees of freedom
## Multiple R-squared: 0.6135, Adjusted R-squared: 0.5482
## F-statistic: 9.393 on 24 and 142 DF, p-value: < 2.2e-16
# Asumsi 1 : Rata-rata galat diasumsikan bernilai nol
plot(ANREGP4$Height,model2$residuals,
xlab="Height (X)",ylab="Residuals",
main="Plot Uji Asumsi Rata-rata Galat bernilai nol")
# Asumsi 2 : Galat saling bebas
c<-(1:167)
ANREGP4<-cbind(ANREGP4,c)
head(ANREGP4)
## 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 4
## 5 Male 68 23.5 5
## 6 Female 59 20 6
plot(ANREGP4$c,model2$residuals,
xlab="Amatan",ylab="Residuals",
main="Plot Uji Asumsi Galat Saling Bebas")
# Asumsi 3 : Galat berdistribusi normal
c<-(1:167)
ytopi<-model2$fitted.values
ei<-model2$residuals
eiterurut<-sort(model2$residuals)
anova(model2) #baca nilai KTG
## Analysis of Variance Table
##
## Response: HandSpan
## Df Sum Sq Mean Sq F value Pr(>F)
## Height 24 378.14 15.7558 9.393 < 2.2e-16 ***
## Residuals 142 238.19 1.6774
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
hi<-sqrt(1.6774)*qnorm((c-0.375)/(168+0.25))
Hi<-cbind(ANREGP4,ytopi,ei,eiterurut,hi)
head(Hi)
## Sex Height HandSpan c ytopi ei eiterurut hi
## 1 Female 68 21.5 1 21.06667 4.333333e-01 -3.142857 -3.467047
## 2 Male 71 23.5 2 21.43333 2.066667e+00 -3.000000 -3.029818
## 3 Male 73 22.5 3 22.65000 -1.500000e-01 -3.000000 -2.790347
## 4 Female 64 18 4 19.03571 -1.035714e+00 -2.933333 -2.619858
## 5 Male 68 23.5 5 21.06667 2.433333e+00 -2.642857 -2.485451
## 6 Female 59 20 6 20.00000 -7.077672e-15 -2.605263 -2.373459
plot(hi,eiterurut,
xlab="hi",ylab="eiterurut",
main="Plot Uji Galat Berdistribusi Normal")
hist(model2$residuals,5)
#Atau gunakan fungsi qqnorm dan qqline di R sebagai berikut
qqnorm(model2$residuals,ylab = "Raw Residuals")
qqline(model2$residuals)
hist(model2$residuals,168) #interval data ada 168
boxplot(model2$residuals)
# Asumsi 4 : Ragam galat diasumsikan konstan
ytopi<-model2$fitted.values
ei<-model2$residuals
plot(ytopi,ei,
xlab="fitted values",ylab="residuals",
main="Plot Uji Ragam Galat Konstan")
# Asumsi 5 : X dan Y berhubungan linear
plot(ANREGP4$Height,ANREGP4$HandSpan,main="Plot Data")
# Asumsi 6 : Tidak ada outlier
plot(ANREGP4$Height,ANREGP4$HandSpan,main="Plot Data")
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.