library(readxl)
## Warning: package 'readxl' was built under R version 4.3.2
Data <- read_xlsx("D:/SIC/Analisis Regresi IPG.xlsx")
y<-Data$`IPG (Y)`
x1<-Data$`UHH(X1)`
x2<-Data$`Rata2 lama sekolah (X2)`
x3<-Data$`Harapan Lama Sekolah (X3)`
x4<-Data$`Pengeluaran (X4)`
x5<-Data$`UHH(X5)`
x6<-Data$`Rata2 lama sekolah (X6)`
x7<-Data$`Harapan Lama Sekolah (X7)`
x8<-Data$`Pengeluaran (X8)`
data<-data.frame(cbind(y,x1,x2,x3,x4,x5,x6,x7,x8))
data
## y x1 x2 x3 x4 x5 x6 x7 x8
## 1 90.23 76.19 8.54 12.78 8509 72.01 9.12 12.61 16512
## 2 90.20 73.96 8.03 12.64 8962 69.97 8.97 12.79 15974
## 3 88.30 73.88 7.08 12.21 7163 69.89 7.82 12.65 13917
## 4 85.17 72.81 6.75 11.93 5401 68.87 7.53 12.31 12257
## 5 94.03 76.20 8.93 13.11 9516 72.50 9.32 12.27 14682
## 6 83.37 74.12 7.49 12.10 4753 70.12 8.14 12.36 12306
## 7 87.01 72.21 7.83 12.63 5746 68.27 8.10 12.74 12748
## 8 87.25 74.63 7.89 14.29 6688 70.61 8.31 14.67 14958
## 9 87.31 76.22 7.63 12.25 7042 72.52 8.16 12.93 14794
## 10 84.28 74.83 7.21 12.75 5905 70.79 8.06 12.41 16736
## 11 87.06 73.08 7.20 12.23 6754 69.12 7.80 12.48 14978
## 12 95.41 75.35 8.48 13.67 10592 71.13 8.95 12.99 14749
## 13 88.81 74.52 6.36 12.47 7758 70.50 7.50 11.98 15603
## 14 91.29 75.43 7.12 12.13 9042 71.16 7.90 11.90 15779
## 15 87.08 73.78 7.69 12.27 8187 69.79 8.80 12.18 19087
## 16 91.07 74.97 7.48 12.19 9929 70.93 8.48 12.24 16706
## 17 89.53 76.23 9.17 13.22 8862 72.53 9.80 13.11 17956
## 18 80.37 75.23 7.86 11.91 4373 71.07 8.75 11.93 14242
## 19 90.04 74.22 7.77 12.28 7393 70.22 8.40 12.35 13293
## 20 91.11 76.37 10.24 13.54 10385 72.69 11.04 13.36 18739
## 21 92.35 75.25 10.09 13.53 10809 71.08 10.70 14.42 16399
## 22 94.71 76.93 10.71 14.49 17109 73.30 11.42 14.23 24304
## 23 95.55 75.20 10.12 13.45 12025 71.06 10.67 12.83 16432
## 24 93.52 77.45 11.66 14.12 15095 74.10 12.15 14.34 22892
## 25 93.44 77.11 11.28 14.08 14822 73.49 11.89 13.96 23370
## 26 92.00 76.70 10.98 13.84 10931 73.05 11.65 14.26 17551
## 27 92.13 74.99 9.31 13.80 8485 70.95 9.66 13.42 14570
## 28 87.85 73.84 8.52 13.19 7844 69.85 9.23 13.59 16864
plot(x4,y)
model.reg= lm(formula = y ~ ., data = data)
model.reg
##
## Call:
## lm(formula = y ~ ., data = data)
##
## Coefficients:
## (Intercept) x1 x2 x3 x4 x5
## 76.8098987 0.7132215 0.4206227 1.7747515 0.0017487 -0.6426053
## x6 x7 x8
## -0.6528355 -1.2601960 -0.0009061
plot(model.reg,1)
## 3 plot sisaan vs urutan sisaan saling bebas
plot(x = 1:dim(data)[1],
y = model.reg$residuals,
type = 'b',
ylab = "Residuals",
xlab = "Observation")
sisaan menyebar normal
plot(model.reg,2)
## 1 Nilai harapan sisaan sama dengan nol
t.test(model.reg$residuals,mu = 0,conf.level = 0.95)
##
## One Sample t-test
##
## data: model.reg$residuals
## t = -3.8572e-16, df = 27, p-value = 1
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
## -0.4217438 0.4217438
## sample estimates:
## mean of x
## -7.928228e-17
Karena p-value > 0,05 maka terima h0 yang artinya nilai harapan sisaan sama dengan 0
library(lmtest)
## Warning: package 'lmtest' was built under R version 4.3.2
## Loading required package: zoo
## Warning: package 'zoo' was built under R version 4.3.2
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
bptest(model.reg)
##
## studentized Breusch-Pagan test
##
## data: model.reg
## BP = 5.4855, df = 8, p-value = 0.7046
Berdasarkan hasil uji kehomogenan sisaan diatas, p-value > 0,05 artinya Sisaannya homogen.
library(randtests)
runs.test(model.reg$residuals)
##
## Runs Test
##
## data: model.reg$residuals
## statistic = 0, runs = 15, n1 = 14, n2 = 14, n = 28, p-value = 1
## alternative hypothesis: nonrandomness
Berdasarkan uji randtest diatas, p-value > 0,05 yang artinya Sisaan saling bebas
ks.test(model.reg$residuals, "pnorm", mean=mean(model.reg$residuals), sd=sd(model.reg$residuals))
##
## Exact one-sample Kolmogorov-Smirnov test
##
## data: model.reg$residuals
## D = 0.19068, p-value = 0.2294
## alternative hypothesis: two-sided
menyebar normal
library(car)
## Warning: package 'car' was built under R version 4.3.3
## Loading required package: carData
vif(model.reg)
## x1 x2 x3 x4 x5 x6 x7
## 80.880182 110.235709 7.865507 6.193067 89.365611 106.979047 5.170447
## x8
## 7.091782
tidak ada multikolinearitas
model_reg <- lm(y~x1+x2+x3+x4+x5+x6+x7+x8,
data = data)
summary(model_reg)
##
## Call:
## lm(formula = y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.8654 -0.3256 0.3575 0.6048 1.5569
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 76.8098987 24.2269187 3.170 0.005037 **
## x1 0.7132215 1.6764072 0.425 0.675291
## x2 0.4206227 1.7794520 0.236 0.815669
## x3 1.7747515 0.8822525 2.012 0.058662 .
## x4 0.0017487 0.0002020 8.658 5.08e-08 ***
## x5 -0.6426053 1.6076974 -0.400 0.693831
## x6 -0.6528355 1.8314214 -0.356 0.725421
## x7 -1.2601960 0.6799981 -1.853 0.079445 .
## x8 -0.0009061 0.0002164 -4.188 0.000499 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.297 on 19 degrees of freedom
## Multiple R-squared: 0.9161, Adjusted R-squared: 0.8807
## F-statistic: 25.92 on 8 and 19 DF, p-value: 1.191e-08
hasil uji F tolak H0, minimal ada satu Bj yang berpengaruh terhadap respon
Hasil uji parsial hanya x4 yang tolak H0 artinya peubah penjelas pengeluaran berpengaruh terhadap respon, setelah peubah penjelas lainnya ada dalam model.
library(olsrr)
## Warning: package 'olsrr' was built under R version 4.3.2
##
## Attaching package: 'olsrr'
## The following object is masked from 'package:datasets':
##
## rivers
ols_step_best_subset(model_reg)
## Best Subsets Regression
## --------------------------------------
## Model Index Predictors
## --------------------------------------
## 1 x4
## 2 x4 x8
## 3 x3 x4 x8
## 4 x3 x4 x7 x8
## 5 x3 x4 x6 x7 x8
## 6 x1 x3 x4 x6 x7 x8
## 7 x1 x3 x4 x5 x6 x7 x8
## 8 x1 x2 x3 x4 x5 x6 x7 x8
## --------------------------------------
##
## Subsets Regression Summary
## ---------------------------------------------------------------------------------------------------------------------------------
## Adj. Pred
## Model R-Square R-Square R-Square C(p) AIC SBIC SBC MSEP FPE HSP APC
## ---------------------------------------------------------------------------------------------------------------------------------
## 1 0.7026 0.6912 0.6225 43.3019 124.5600 42.0815 128.5566 121.8662 4.6623 0.1741 0.3431
## 2 0.8869 0.8779 0.8414 3.5981 99.4932 20.5780 104.8220 48.2828 1.9057 0.0717 0.1402
## 3 0.8908 0.8772 0.8406 4.7038 100.4975 22.0687 107.1585 48.6219 1.9775 0.0752 0.1455
## 4 0.9136 0.8986 0.8678 1.5481 95.9432 20.4324 103.9364 40.2232 1.6839 0.0649 0.1239
## 5 0.9151 0.8958 0.8375 3.2097 97.4543 23.0661 106.7798 41.4093 1.7824 0.0699 0.1312
## 6 0.9153 0.8911 0.8252 5.1720 99.3994 25.9612 110.0570 43.3945 1.9184 0.0767 0.1412
## 7 0.9158 0.8863 0.8059 7.0559 101.2292 28.8378 113.2190 45.4016 2.0593 0.0843 0.1516
## 8 0.9161 0.8807 0.802 9.0000 103.1470 31.7640 116.4690 47.7834 2.2214 0.0934 0.1635
## ---------------------------------------------------------------------------------------------------------------------------------
## AIC: Akaike Information Criteria
## SBIC: Sawa's Bayesian Information Criteria
## SBC: Schwarz Bayesian Criteria
## MSEP: Estimated error of prediction, assuming multivariate normality
## FPE: Final Prediction Error
## HSP: Hocking's Sp
## APC: Amemiya Prediction Criteria
model_reg2 <- lm(y~x4+x8,
data = data)
summary(model_reg2)
##
## Call:
## lm(formula = y ~ x4 + x8, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.8474 -0.4113 0.1095 0.8640 1.6004
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 89.3487809 1.5855006 56.354 < 2e-16 ***
## x4 0.0018847 0.0001580 11.930 8.14e-12 ***
## x8 -0.0010092 0.0001581 -6.382 1.11e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.312 on 25 degrees of freedom
## Multiple R-squared: 0.8869, Adjusted R-squared: 0.8779
## F-statistic: 98.02 on 2 and 25 DF, p-value: 1.474e-12