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(ggplot2)
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
# MEMANGGIL DATA
data <- read.table(file.choose(), header = TRUE, sep = "\t")
data
## Y X1 X2
## 1 34.4 100 140
## 2 38.7 110 180
## 3 34.2 120 150
## 4 41.7 130 200
## 5 39.0 140 170
## 6 41.5 150 220
## 7 40.9 160 190
## 8 44.0 170 240
## 9 43.9 180 200
## 10 47.6 190 230
## 11 49.7 200 260
## 12 48.7 210 220
# SCATTER PLOT Y (Hasil panen padi) DAN X1 (Dosis pupuk)
ggplot(data, aes(x = X1, y = Y)) +
geom_point(color = "pink", size = 2) +
geom_smooth(method = "lm", se = FALSE,
color = "skyblue", linewidth = 1.2) +
ggtitle("Scatter Plot Antara Dosis Pupuk dan Hasil Panen Padi") +
ylab("Hasil Panen Padi (kuintal/ha)") +
xlab("Dosis Pupuk (kg/ha)") +
theme(plot.title = element_text(hjust = 0.5))
## `geom_smooth()` using formula = 'y ~ x'

# SCATTER PLOT Y (Hasil panen padi) DAN X2 (Curah hujan)
ggplot(data, aes(x = X2, y = Y)) +
geom_point(color = "hotpink", size = 2) +
geom_smooth(method = "lm", se = FALSE,
color = "springgreen4", linewidth = 1.2) +
ggtitle("Scatter Plot Antara Curah Hujan dan Hasil Panen Padi") +
ylab("Hasil Panen Padi (kuintal/ha)") +
xlab("Curah Hujan (mm/bulan)") +
theme(plot.title = element_text(hjust = 0.5))
## `geom_smooth()` using formula = 'y ~ x'

# REGRESI LINIER BERGANDA
model <- lm(Y ~ X1 + X2, data = data)
summary(model)
##
## Call:
## lm(formula = Y ~ X1 + X2, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.8540 -1.0105 0.1800 0.9349 1.6401
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 16.96176 2.30605 7.355 4.3e-05 ***
## X1 0.07860 0.01965 4.000 0.00311 **
## X2 0.06440 0.01958 3.289 0.00940 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.361 on 9 degrees of freedom
## Multiple R-squared: 0.9412, Adjusted R-squared: 0.9281
## F-statistic: 71.99 on 2 and 9 DF, p-value: 2.905e-06
# PENDETEKSIAN MULTIKOLINIERITAS (Nilai VIF < 10)
vif(model)
## X1 X2
## 2.983051 2.983051
# PENGUJIAN ASUMSI KLASIK
# 1. Uji Heteroskedastisitas (Breusch-Pagan)
bptest(model, varformula = ~fitted.values(model), studentize = FALSE)
##
## Breusch-Pagan test
##
## data: model
## BP = 0.2226, df = 1, p-value = 0.6371
# 2. Uji Autokorelasi (Durbin-Watson)
dwtest(model, alternative = 'two.sided')
##
## Durbin-Watson test
##
## data: model
## DW = 2.0988, p-value = 0.9478
## alternative hypothesis: true autocorrelation is not 0
# 3. Uji Normalitas Residual (Shapiro-Wilk)
shapiro.test(resid(model))
##
## Shapiro-Wilk normality test
##
## data: resid(model)
## W = 0.92837, p-value = 0.3631