library(ggplot2)
library(lmtest)
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
library(car)
## Loading required package: carData
library(zoo)
library(nortest)
# Input Data
data <- read.table("Dataset 1.csv", header = TRUE, sep = "\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
# Visualisasi Scatter Plot (ggplot2)
# Scatter Plot X1 dan Y
ggplot(data, aes(x = X1, y = Y)) +
geom_point(color = "orange", size = 3) +
geom_smooth(method = "lm", se = FALSE, color = "darkred", linetype = "twodash") +
labs(title = "Scatter Plot X1 dan Y", x = "X1", y = "Y") +
scale_x_continuous(breaks = seq(65, 105, 5)) +
scale_y_continuous(breaks = seq(52, 70, 2)) +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

# Scatter Plot X2 dan Y
ggplot(data, aes(x = X2, y = Y)) +
geom_point(color = "orange", size = 3) +
geom_smooth(method = "lm", se = FALSE, color = "darkred", linetype = "twodash") +
labs(title = "Scatter Plot X2 dan Y", x = "X2", y = "Y") +
scale_x_continuous(breaks = seq(2, 6, 0.5)) +
scale_y_continuous(breaks = seq(52, 70, 2)) +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

# Scatter Plot X3 dan Y
ggplot(data, aes(x = X3, y = Y)) +
geom_point(color = "orange", size = 3) +
geom_smooth(method = "lm", se = FALSE, color = "darkred", linetype = "twodash") +
labs(title = "Scatter Plot X3 dan Y", x = "X3", y = "Y") +
scale_x_continuous(breaks = seq(26, 37, 1)) +
scale_y_continuous(breaks = seq(52, 70, 2)) +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

# REGRESI LINIER BERGANDA (RLB)
# Estimasi Parameter & Uji Hipotesis RLB
Reg <- lm(Y ~ X1 + X2 + X3, data = data)
summary(Reg)
##
## 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
# Deteksi Multikolinearitas
vif(Reg)
## X1 X2 X3
## 1.403219 3.093549 2.607991
# Uji Asumsi Klasik RLB
# Uji Heteroskedastisitas
bptest(Reg)
##
## studentized Breusch-Pagan test
##
## data: Reg
## BP = 0.52402, df = 3, p-value = 0.9136
# Uji Autokorelasi
dwtest(Reg)
##
## Durbin-Watson test
##
## data: Reg
## DW = 1.6446, p-value = 0.1165
## alternative hypothesis: true autocorrelation is greater than 0
# Uji Autokorelasi
bgtest(Reg)
##
## Breusch-Godfrey test for serial correlation of order up to 1
##
## data: Reg
## LM test = 0.51249, df = 1, p-value = 0.4741
# Uji Normalitas Residual
shapiro.test(resid(Reg))
##
## Shapiro-Wilk normality test
##
## data: resid(Reg)
## W = 0.93208, p-value = 0.5014