#Memanggil library
library(stats)
library(car)
## Warning: package 'car' was built under R version 4.5.3
## Loading required package: carData
## Warning: package 'carData' was built under R version 4.5.3
library(lmtest)
## Warning: package 'lmtest' was built under R version 4.5.3
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 4.5.3
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
library(zoo)
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.5.3
#Memanggil Dataset 1
data=read.table(file.choose(), header=T)
data
## Y X1 X2 X3
## 1 57.5 78 2.75 29.5
## 2 52.8 69 2.15 26.3
## 3 61.3 77 4.41 32.2
## 4 67.0 88 5.52 36.5
## 5 53.5 67 3.21 27.2
## 6 62.7 80 4.32 27.7
## 7 56.2 74 2.31 28.3
## 8 68.5 94 4.30 30.3
## 9 69.2 102 3.71 28.7
#ANALISIS REGRESI LINIER
#ANALISIS MODEL REGRESI LINIER 1 (Y (Panjang Bayi (cm)) dengan X1 (Umur (hari)))
#Membuat Scatterplot Y (Panjang Bayi (cm)) dengan X1 (Umur (hari))
ggplot(data, aes(x = X1, y = Y)) +
geom_point(size = 2.5, alpha = 0.6, color = "darkblue") +
geom_smooth(
method = "lm",
se = FALSE,
color = "pink"
) +
labs(
title = "Scatterplot Variabel Panjang Bayi (cm) dengan Umur (hari)",
x = "Umur (hari)",
y = "Panjang Bayi (cm)"
) +
theme_minimal() +
theme(
plot.title = element_text(face = "bold", hjust = 0.5),
axis.title = element_text(face = "bold")
)
## `geom_smooth()` using formula = 'y ~ x'

#ANALISIS MODEL REGRESI LINIER 2 (Y (Panjang Bayi (cm)) dengan X2 (Berat Badan (kg)))
#Membuat Scatterplot Y (Panjang Bayi (cm)) dengan X2 (Berat Badan (kg))
ggplot(data, aes(x = X2, y = Y)) +
geom_point(size = 2.5, alpha = 0.6, color = "pink") +
geom_smooth(
method = "lm",
se = FALSE,
color = "darkblue"
) +
labs(
title = "Scatterplot Variabel Panjang Bayi (cm) dengan Berat Badan (kg)",
x = "Berat Badan (kg)",
y = "Panjang Bayi (cm)"
) +
theme_minimal() +
theme(
plot.title = element_text(face = "bold", hjust = 0.5),
axis.title = element_text(face = "bold")
)
## `geom_smooth()` using formula = 'y ~ x'

#ANALISIS MODEL REGRESI LINIER 3 (Y (Panjang Bayi (cm)) dengan X3 (Lingkar dada (cm)))
#Membuat Scatterplot Y (Panjang Bayi (cm)) dengan X3 (Lingkar dada (cm))
ggplot(data, aes(x = X3, y = Y)) +
geom_point(size = 2.5, alpha = 0.6, color = "purple") +
geom_smooth(
method = "lm",
se = FALSE,
color = "darkgreen"
) +
labs(
title = "Scatterplot Variabel Panjang Bayi (cm) dengan Lingkar dada (cm)",
x = "Lingkar dada (cm)",
y = "Panjang Bayi (cm)"
) +
theme_minimal() +
theme(
plot.title = element_text(face = "bold", hjust = 0.5),
axis.title = element_text(face = "bold")
)
## `geom_smooth()` using formula = 'y ~ x'

#ANALISIS REGRESI LINIER BERGANDA (Y ~ X1 + X2 + X3)
M1 = lm(Y ~ X1 + X2 + X3, data = data)
summary(M1)
##
## Call:
## lm(formula = Y ~ X1 + X2 + X3, data = data)
##
## Residuals:
## 1 2 3 4 5 6 7 8 9
## -0.2981 -0.2142 0.4714 -0.4746 -0.9524 0.4761 0.9274 0.7466 -0.6823
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 21.87353 4.07389 5.369 0.00302 **
## X1 0.41277 0.03067 13.460 4.05e-05 ***
## X2 2.20267 0.47199 4.667 0.00550 **
## X3 -0.07895 0.15551 -0.508 0.63330
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.8484 on 5 degrees of freedom
## Multiple R-squared: 0.9888, Adjusted R-squared: 0.9821
## F-statistic: 147.1 on 3 and 5 DF, p-value: 2.696e-05
# Uji Asumsi
## Uji Multikolinearitas
vif(M1)
## X1 X2 X3
## 1.403219 3.093549 2.607991
## Uji Normalitas Residual
shapiro.test(resid(M1))
##
## Shapiro-Wilk normality test
##
## data: resid(M1)
## W = 0.93208, p-value = 0.5014
## Uji non heteroskedastisitas
### Uji Breusch Pagan
bptest(M1, varformula = ~fitted.values(M1), studentize = FALSE)
##
## Breusch-Pagan test
##
## data: M1
## BP = 0.031878, df = 1, p-value = 0.8583
### Uji Glejser
resid(M1)
## 1 2 3 4 5 6 7
## -0.2980857 -0.2141744 0.4714083 -0.4745650 -0.9524106 0.4760829 0.9274363
## 8 9
## 0.7466056 -0.6822975
abs(resid(M1))
## 1 2 3 4 5 6 7 8
## 0.2980857 0.2141744 0.4714083 0.4745650 0.9524106 0.4760829 0.9274363 0.7466056
## 9
## 0.6822975
m1 = lm(abs(resid(M1)) ~ X1 + X2 + X3, data = data)
summary(m1)
##
## Call:
## lm(formula = abs(resid(M1)) ~ X1 + X2 + X3, data = data)
##
## Residuals:
## 1 2 3 4 5 6 7 8
## -0.24968 -0.37078 -0.06495 -0.01987 0.35744 -0.17650 0.37477 0.12608
## 9
## 0.02347
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.000238 1.548904 0.646 0.547
## X1 0.002391 0.011660 0.205 0.846
## X2 0.035130 0.179452 0.196 0.853
## X3 -0.024936 0.059127 -0.422 0.691
##
## Residual standard error: 0.3226 on 5 degrees of freedom
## Multiple R-squared: 0.04467, Adjusted R-squared: -0.5285
## F-statistic: 0.07793 on 3 and 5 DF, p-value: 0.9692
## Uji non autokorelasi
### Uji Durbin-Watson
dwtest(M1, alternative = 'two.sided')
##
## Durbin-Watson test
##
## data: M1
## DW = 1.6446, p-value = 0.233
## alternative hypothesis: true autocorrelation is not 0
### Uji Breusch-Godfrey
bgtest(M1)
##
## Breusch-Godfrey test for serial correlation of order up to 1
##
## data: M1
## LM test = 0.51249, df = 1, p-value = 0.4741