#install.packages("readxl")
library(readxl) #Memasukkan Data ke R (Excel)
Data <- read_excel("D:/STATISTIKA 2021/SEMESTER 5/DATA MINING/Pertumbuhan Ekonomi SS - 2.xlsx")
View(Data)
str(Data)
## tibble [32 × 8] (S3: tbl_df/tbl/data.frame)
## $ PertumbuhanEkonomi : num [1:32] 24407 25836 26565 27807 26831 ...
## $ Ekspor : num [1:32] 15444 18961 19065 19400 20312 ...
## $ Investasi : num [1:32] 6070 5997 6695 7165 4577 ...
## $ KonsumsiLSNirlaba : num [1:32] 123 122 134 135 134 ...
## $ KonsumsiRT : num [1:32] 11920 12058 12361 12394 12415 ...
## $ PengeluaranPemerintah: num [1:32] 1388 2083 2268 3244 1265 ...
## $ PerubahanInventori : num [1:32] 1617 -243 -342 418 755 ...
## $ ImporAHK : num [1:32] 12155 13142 13614 14948 12826 ...
dim(Data)
## [1] 32 8
# Korelasi Peubah Respons dengan Peubah Penjelas
cor.test (Data$Ekspor, Data$PertumbuhanEkonomi)
##
## Pearson's product-moment correlation
##
## data: Data$Ekspor and Data$PertumbuhanEkonomi
## t = 16.13, df = 30, p-value = 2.504e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.8930807 0.9739998
## sample estimates:
## cor
## 0.9468991
cor.test (Data$Investasi, Data$PertumbuhanEkonomi)
##
## Pearson's product-moment correlation
##
## data: Data$Investasi and Data$PertumbuhanEkonomi
## t = 3.2815, df = 30, p-value = 0.002622
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.2013304 0.7315395
## sample estimates:
## cor
## 0.5139441
cor.test (Data$KonsumsiRT, Data$PertumbuhanEkonomi)
##
## Pearson's product-moment correlation
##
## data: Data$KonsumsiRT and Data$PertumbuhanEkonomi
## t = 38.1, df = 30, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.9790429 0.9950731
## sample estimates:
## cor
## 0.9898244
cor.test (Data$PengeluaranPemerintah, Data$PertumbuhanEkonomi)
##
## Pearson's product-moment correlation
##
## data: Data$PengeluaranPemerintah and Data$PertumbuhanEkonomi
## t = 2.2883, df = 30, p-value = 0.02934
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.04251973 0.64719554
## sample estimates:
## cor
## 0.3854982
cor.test (Data$KonsumsiLSNirlaba, Data$PertumbuhanEkonomi)
##
## Pearson's product-moment correlation
##
## data: Data$KonsumsiLSNirlaba and Data$PertumbuhanEkonomi
## t = 18.759, df = 30, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.9187501 0.9804427
## sample estimates:
## cor
## 0.9599212
cor.test (Data$PerubahanInventori, Data$PertumbuhanEkonomi)
##
## Pearson's product-moment correlation
##
## data: Data$PerubahanInventori and Data$PertumbuhanEkonomi
## t = -0.41622, df = 30, p-value = 0.6802
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## -0.4135402 0.2803281
## sample estimates:
## cor
## -0.0757725
# Korelasi Antar Peubah Penjelas
cor(as.matrix(Data[,c("Ekspor","Investasi", "KonsumsiRT","PengeluaranPemerintah",
"KonsumsiLSNirlaba","PerubahanInventori")]))
## Ekspor Investasi KonsumsiRT PengeluaranPemerintah
## Ekspor 1.00000000 0.3243939 0.94503037 0.2415247
## Investasi 0.32439394 1.0000000 0.50452374 0.7759085
## KonsumsiRT 0.94503037 0.5045237 1.00000000 0.3446699
## PengeluaranPemerintah 0.24152468 0.7759085 0.34466994 1.0000000
## KonsumsiLSNirlaba 0.90275993 0.4975288 0.95734578 0.3573088
## PerubahanInventori -0.05969282 -0.5590342 -0.05352549 -0.5065535
## KonsumsiLSNirlaba PerubahanInventori
## Ekspor 0.90275993 -0.05969282
## Investasi 0.49752881 -0.55903416
## KonsumsiRT 0.95734578 -0.05352549
## PengeluaranPemerintah 0.35730882 -0.50655352
## KonsumsiLSNirlaba 1.00000000 -0.02929299
## PerubahanInventori -0.02929299 1.00000000
# Analisis Regresi Berganda
Model_ARLB <- lm (PertumbuhanEkonomi ~ Ekspor + Investasi + KonsumsiRT + PengeluaranPemerintah
+ KonsumsiLSNirlaba + PerubahanInventori, data=Data)
summary (Model_ARLB)
##
## Call:
## lm(formula = PertumbuhanEkonomi ~ Ekspor + Investasi + KonsumsiRT +
## PengeluaranPemerintah + KonsumsiLSNirlaba + PerubahanInventori,
## data = Data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1157.81 -271.66 44.58 357.95 581.70
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.255e+03 1.679e+03 -0.747 0.462
## Ekspor 1.812e-01 1.070e-01 1.694 0.103
## Investasi 4.387e-02 2.095e-01 0.209 0.836
## KonsumsiRT 1.777e+00 3.618e-01 4.910 4.7e-05 ***
## PengeluaranPemerintah 2.551e-01 1.598e-01 1.596 0.123
## KonsumsiLSNirlaba 1.724e+01 1.149e+01 1.501 0.146
## PerubahanInventori 6.201e-02 1.723e-01 0.360 0.722
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 490.4 on 25 degrees of freedom
## Multiple R-squared: 0.986, Adjusted R-squared: 0.9826
## F-statistic: 293 on 6 and 25 DF, p-value: < 2.2e-16
# Uji Asumsi Klasik
library(performance)
# Uji Normalitas
check_normality(Model_ARLB)
## OK: residuals appear as normally distributed (p = 0.074).
# Uji Heteroskedastisitas
check_heteroscedasticity(Model_ARLB)
## Warning: Heteroscedasticity (non-constant error variance) detected (p = 0.021).
# Uji Multikolinieritas
multicollinearity(Model_ARLB)
## # Check for Multicollinearity
##
## Low Correlation
##
## Term VIF VIF 95% CI Increased SE Tolerance
## PengeluaranPemerintah 2.69 [ 1.88, 4.21] 1.64 0.37
## PerubahanInventori 2.38 [ 1.70, 3.72] 1.54 0.42
## Tolerance 95% CI
## [0.24, 0.53]
## [0.27, 0.59]
##
## Moderate Correlation
##
## Term VIF VIF 95% CI Increased SE Tolerance Tolerance 95% CI
## Investasi 6.64 [ 4.28, 10.70] 2.58 0.15 [0.09, 0.23]
##
## High Correlation
##
## Term VIF VIF 95% CI Increased SE Tolerance Tolerance 95% CI
## Ekspor 19.66 [12.20, 32.09] 4.43 0.05 [0.03, 0.08]
## KonsumsiRT 33.62 [20.69, 55.04] 5.80 0.03 [0.02, 0.05]
## KonsumsiLSNirlaba 12.51 [ 7.85, 20.33] 3.54 0.08 [0.05, 0.13]
# Uji Autokorelasi
check_autocorrelation(Model_ARLB)
## Warning: Autocorrelated residuals detected (p < .001).
# Cek Performa/Kinerja Model
model_performance(Model_ARLB,metrics = "all")
## # Indices of model performance
##
## AIC | AICc | BIC | R2 | R2 (adj.) | RMSE | Sigma
## -------------------------------------------------------------------
## 495.407 | 501.668 | 507.133 | 0.986 | 0.983 | 433.456 | 490.400
# Hasil Prediksi Model (y_dugaARLB)
y_dugaARLB <- predict(Model_ARLB)
y_dugaARLB
## 1 2 3 4 5 6 7 8
## 25564.91 26482.29 27313.54 27779.46 27356.65 27708.64 28199.67 28615.90
## 9 10 11 12 13 14 15 16
## 28806.70 29350.76 29867.20 30269.61 30248.57 30650.83 31395.33 31758.38
## 17 18 19 20 21 22 23 24
## 31324.79 31832.85 32746.12 33323.52 32577.95 33591.71 34729.15 35011.14
## 25 26 27 28 29 30 31 32
## 34497.53 35587.89 36513.37 37261.05 36490.88 37456.81 37865.22 38467.39
# Korelasi Antara Pertumbuhan Ekonomi dan Y Duga
cor.test (Data$PertumbuhanEkonomi, y_dugaARLB)
##
## Pearson's product-moment correlation
##
## data: Data$PertumbuhanEkonomi and y_dugaARLB
## t = 45.927, df = 30, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.9854842 0.9965959
## sample estimates:
## cor
## 0.9929637
ANALISIS REGRESI TERPENALTI
# Analisis Regresi Ridge (Gulud)
x <- data.matrix(Data[, c('Ekspor', 'Investasi', 'KonsumsiRT','PengeluaranPemerintah'
, 'KonsumsiLSNirlaba', 'PerubahanInventori')])
head(x)
## Ekspor Investasi KonsumsiRT PengeluaranPemerintah KonsumsiLSNirlaba
## [1,] 15443.83 6070.14 11919.53 1388.04 123.15
## [2,] 18961.48 5996.57 12057.78 2083.34 121.72
## [3,] 19064.53 6694.59 12360.51 2267.53 133.51
## [4,] 19400.01 7164.88 12394.40 3243.64 135.14
## [5,] 20312.28 4576.75 12414.77 1265.14 133.58
## [6,] 20089.67 5706.60 12528.48 2137.20 132.44
## PerubahanInventori
## [1,] 1617.14
## [2,] -242.78
## [3,] -342.07
## [4,] 417.87
## [5,] 754.61
## [6,] -246.67
dim(x)
## [1] 32 6
y <- Data$PertumbuhanEkonomi
head(y)
## [1] 24407.10 25835.93 26564.60 27807.45 26831.47 28066.35
model_coba1 <- lm (y~x)
summary (model_coba1)
##
## Call:
## lm(formula = y ~ x)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1157.81 -271.66 44.58 357.95 581.70
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.255e+03 1.679e+03 -0.747 0.462
## xEkspor 1.812e-01 1.070e-01 1.694 0.103
## xInvestasi 4.387e-02 2.095e-01 0.209 0.836
## xKonsumsiRT 1.777e+00 3.618e-01 4.910 4.7e-05 ***
## xPengeluaranPemerintah 2.551e-01 1.598e-01 1.596 0.123
## xKonsumsiLSNirlaba 1.724e+01 1.149e+01 1.501 0.146
## xPerubahanInventori 6.201e-02 1.723e-01 0.360 0.722
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 490.4 on 25 degrees of freedom
## Multiple R-squared: 0.986, Adjusted R-squared: 0.9826
## F-statistic: 293 on 6 and 25 DF, p-value: < 2.2e-16
#install.packages("glmnet")
library(glmnet)
## Loading required package: Matrix
## Loaded glmnet 4.1-8
#Melakukan k-fold cross-validation untuk menemukan nilai lambda yang optimal
cv_model <- cv.glmnet(x, y, alpha = 0)
#temukan nilai lambda optimal yang meminimalkan tes MSE
best_lambda <- cv_model$lambda.min
best_lambda
## [1] 362.3103
log (best_lambda)
## [1] 5.892501
log(cv_model$lambda.1se)
## [1] 6.729805
#menghasilkan plot uji MSE dengan nilai lambda
plot(cv_model)

#menemukan koefisien model terbaik
Model_Ridge <- glmnet(x, y, alpha = 0, lambda = best_lambda)
coef(Model_Ridge)
## 7 x 1 sparse Matrix of class "dgCMatrix"
## s0
## (Intercept) 2743.1419682
## Ekspor 0.3110970
## Investasi 0.2678929
## KonsumsiRT 0.9834074
## PengeluaranPemerintah 0.1902167
## KonsumsiLSNirlaba 34.0211991
## PerubahanInventori 0.1576684
summary (Model_Ridge)
## Length Class Mode
## a0 1 -none- numeric
## beta 6 dgCMatrix S4
## df 1 -none- numeric
## dim 2 -none- numeric
## lambda 1 -none- numeric
## dev.ratio 1 -none- numeric
## nulldev 1 -none- numeric
## npasses 1 -none- numeric
## jerr 1 -none- numeric
## offset 1 -none- logical
## call 5 -none- call
## nobs 1 -none- numeric
# Hasil Prediksi Model (y_dugaARidge)
y_dugaRidge <- predict(Model_Ridge,newx=x[1:32,])
y_dugaRidge
## s0
## [1,] 25604.28
## [2,] 26605.22
## [3,] 27542.47
## [4,] 28167.10
## [5,] 27401.27
## [6,] 27715.74
## [7,] 28303.04
## [8,] 28966.02
## [9,] 29142.33
## [10,] 29744.82
## [11,] 29897.70
## [12,] 30337.26
## [13,] 30407.97
## [14,] 30861.43
## [15,] 31414.93
## [16,] 31802.25
## [17,] 31171.15
## [18,] 31622.48
## [19,] 32554.52
## [20,] 33227.16
## [21,] 32144.19
## [22,] 33280.30
## [23,] 34602.48
## [24,] 34876.59
## [25,] 34404.14
## [26,] 35214.04
## [27,] 36503.79
## [28,] 37415.38
## [29,] 36687.59
## [30,] 37424.67
## [31,] 37477.29
## [32,] 38126.23
# Menghitung R^2 adjusted dari nilai sebenarnya dan prediksi
SSE <- sum((y_dugaRidge - y)^2)
SST <- sum((y - mean(y))^2)
RSquared_Ridge <- 1 - (SSE / SST)*(31/26) #((n-1)/(n-p-1)
RSquared_Ridge
## [1] 0.9787964
# Root Mean Square Error (RMSE)
RMSE_Ridge <- sqrt(mean((y - y_dugaRidge)^2))
RMSE_Ridge
## [1] 488.1274
#Ukuran Kinerja/Performa untuk Model glmnet
Performance_Ridge <- assess.glmnet(Model_Ridge,newx=x[1:32,], newy=y)
RMSE_Ridge1 <- sqrt(Performance_Ridge$mse)
RMSE_Ridge1
## s0
## 488.1274
## attr(,"measure")
## [1] "Mean-Squared Error"
# Korelasi Antara Pertumbuhan Ekonomi dan Y Duga
cor.test (y, y_dugaRidge)
##
## Pearson's product-moment correlation
##
## data: y and y_dugaRidge
## t = 41.906, df = 30, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.9826144 0.9959183
## sample estimates:
## cor
## 0.9915663
Analisis Regresi LASSO
model_coba1 <- lm (y~x)
summary (model_coba1)
##
## Call:
## lm(formula = y ~ x)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1157.81 -271.66 44.58 357.95 581.70
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.255e+03 1.679e+03 -0.747 0.462
## xEkspor 1.812e-01 1.070e-01 1.694 0.103
## xInvestasi 4.387e-02 2.095e-01 0.209 0.836
## xKonsumsiRT 1.777e+00 3.618e-01 4.910 4.7e-05 ***
## xPengeluaranPemerintah 2.551e-01 1.598e-01 1.596 0.123
## xKonsumsiLSNirlaba 1.724e+01 1.149e+01 1.501 0.146
## xPerubahanInventori 6.201e-02 1.723e-01 0.360 0.722
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 490.4 on 25 degrees of freedom
## Multiple R-squared: 0.986, Adjusted R-squared: 0.9826
## F-statistic: 293 on 6 and 25 DF, p-value: < 2.2e-16
library(glmnet)
#Melakukan k-fold cross-validation untuk menemukan nilai lambda yang optimal
cv_model <- cv.glmnet(x, y, alpha = 1)
#temukan nilai lambda optimal yang meminimalkan tes MSE
best_lambda <- cv_model$lambda.min
best_lambda
## [1] 55.06795
log (best_lambda)
## [1] 4.008568
log(cv_model$lambda.1se)
## [1] 5.497108
#menghasilkan plot uji MSE dengan nilai lambda
plot(cv_model)

#menemukan koefisien model terbaik
Model_Lasso <- glmnet(x, y, alpha = 1, lambda = best_lambda)
coef(Model_Lasso)
## 7 x 1 sparse Matrix of class "dgCMatrix"
## s0
## (Intercept) -988.0902760
## Ekspor 0.1433721
## Investasi .
## KonsumsiRT 1.8444796
## PengeluaranPemerintah 0.1997886
## KonsumsiLSNirlaba 17.8770354
## PerubahanInventori .
summary (Model_Lasso)
## Length Class Mode
## a0 1 -none- numeric
## beta 6 dgCMatrix S4
## df 1 -none- numeric
## dim 2 -none- numeric
## lambda 1 -none- numeric
## dev.ratio 1 -none- numeric
## nulldev 1 -none- numeric
## npasses 1 -none- numeric
## jerr 1 -none- numeric
## offset 1 -none- logical
## call 5 -none- call
## nobs 1 -none- numeric
# Hasil Prediksi Model (y_dugaARLasso)
y_dugaLasso <- predict(Model_Lasso,newx=x[1:32,])
y_dugaLasso
## s0
## [1,] 25690.33
## [2,] 26563.01
## [3,] 27383.73
## [4,] 27718.49
## [5,] 27463.69
## [6,] 27795.36
## [7,] 28227.59
## [8,] 28681.61
## [9,] 28857.97
## [10,] 29374.87
## [11,] 29893.72
## [12,] 30291.08
## [13,] 30288.95
## [14,] 30655.27
## [15,] 31397.27
## [16,] 31737.51
## [17,] 31390.58
## [18,] 31869.39
## [19,] 32752.89
## [20,] 33270.97
## [21,] 32668.18
## [22,] 33575.09
## [23,] 34666.16
## [24,] 34847.41
## [25,] 34520.59
## [26,] 35598.22
## [27,] 36398.45
## [28,] 37107.64
## [29,] 36485.24
## [30,] 37391.84
## [31,] 37811.44
## [32,] 38271.27
# Menghitung R^2 adjusted dari nilai sebenarnya dan prediksi
SSE <- sum((y_dugaLasso - y)^2)
SST <- sum((y - mean(y))^2)
RSquared_Lasso <- 1 - (SSE / SST)*(31/27) #((n-1)/(n-p-1)
RSquared_Lasso
## [1] 0.983385
# Root Mean Square Error (RMSE)
RMSE_Lasso <- sqrt(mean((y - y_dugaLasso)^2))
RMSE_Lasso
## [1] 440.3258
#Ukuran Kinerja/Performa untuk Model glmnet
Performance_Lasso <- assess.glmnet(Model_Lasso,newx=x[1:32,], newy=y)
RMSE_Lasso1 <- sqrt(Performance_Lasso$mse)
RMSE_Lasso1
## s0
## 440.3258
## attr(,"measure")
## [1] "Mean-Squared Error"
# Korelasi Antara Pertumbuhan Ekonomi dan Y Duga
cor.test (y, y_dugaLasso)
##
## Pearson's product-moment correlation
##
## data: y and y_dugaLasso
## t = 45.608, df = 30, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.9852832 0.9965484
## sample estimates:
## cor
## 0.9928659
Analisis Regresi Elastic Net
model_coba1 <- lm (y~x)
summary (model_coba1)
##
## Call:
## lm(formula = y ~ x)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1157.81 -271.66 44.58 357.95 581.70
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.255e+03 1.679e+03 -0.747 0.462
## xEkspor 1.812e-01 1.070e-01 1.694 0.103
## xInvestasi 4.387e-02 2.095e-01 0.209 0.836
## xKonsumsiRT 1.777e+00 3.618e-01 4.910 4.7e-05 ***
## xPengeluaranPemerintah 2.551e-01 1.598e-01 1.596 0.123
## xKonsumsiLSNirlaba 1.724e+01 1.149e+01 1.501 0.146
## xPerubahanInventori 6.201e-02 1.723e-01 0.360 0.722
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 490.4 on 25 degrees of freedom
## Multiple R-squared: 0.986, Adjusted R-squared: 0.9826
## F-statistic: 293 on 6 and 25 DF, p-value: < 2.2e-16
#install.packages("glmnet")
library(glmnet)
#Melakukan k-fold cross-validation untuk menemukan nilai lambda yang optimal
cv_model <- cv.glmnet(x, y, alpha = 0.75)
#temukan nilai lambda optimal yang meminimalkan tes MSE
best_lambda <- cv_model$lambda.min
best_lambda
## [1] 55.54251
log (best_lambda)
## [1] 4.017149
log(cv_model$lambda.1se)
## [1] 5.505689
#menghasilkan plot uji MSE dengan nilai lambda
plot(cv_model)

#menemukan koefisien model terbaik
Model_ENet <- glmnet(x, y, alpha = 0.75, lambda = best_lambda)
coef(Model_ENet)
## 7 x 1 sparse Matrix of class "dgCMatrix"
## s0
## (Intercept) -4.496944e+02
## Ekspor 1.690125e-01
## Investasi 9.676272e-03
## KonsumsiRT 1.721687e+00
## PengeluaranPemerintah 2.131709e-01
## KonsumsiLSNirlaba 2.095169e+01
## PerubahanInventori .
summary (Model_ENet)
## Length Class Mode
## a0 1 -none- numeric
## beta 6 dgCMatrix S4
## df 1 -none- numeric
## dim 2 -none- numeric
## lambda 1 -none- numeric
## dev.ratio 1 -none- numeric
## nulldev 1 -none- numeric
## npasses 1 -none- numeric
## jerr 1 -none- numeric
## offset 1 -none- logical
## call 5 -none- call
## nobs 1 -none- numeric
# Hasil Prediksi Model (y_dugaENet)
y_dugaENet <- predict(Model_ENet,newx=x[1:32,])
y_dugaENet
## s0
## [1,] 25617.03
## [2,] 26567.13
## [3,] 27398.79
## [4,] 27760.62
## [5,] 27470.39
## [6,] 27801.48
## [7,] 28174.22
## [8,] 28688.94
## [9,] 28880.76
## [10,] 29420.98
## [11,] 29869.18
## [12,] 30304.77
## [13,] 30321.96
## [14,] 30682.90
## [15,] 31384.36
## [16,] 31752.26
## [17,] 31358.54
## [18,] 31830.51
## [19,] 32704.99
## [20,] 33274.87
## [21,] 32595.09
## [22,] 33526.57
## [23,] 34668.21
## [24,] 34850.15
## [25,] 34504.73
## [26,] 35566.67
## [27,] 36424.42
## [28,] 37216.43
## [29,] 36529.94
## [30,] 37421.36
## [31,] 37807.78
## [32,] 38269.77
# Menghitung R^2 adjusted dari nilai sebenarnya dan prediksi
SSE <- sum((y_dugaENet - y)^2)
SST <- sum((y - mean(y))^2)
RSquared_ENet <- 1 - (SSE / SST)*(31/27) #((n-1)/(n-p-1)
RSquared_ENet
## [1] 0.9834757
# Root Mean Square Error (RMSE)
RMSE_ENet <- sqrt(mean((y - y_dugaENet)^2))
RMSE_ENet
## [1] 439.1226
#Ukuran Kinerja/Performa untuk Model glmnet
Performance_ENet <- assess.glmnet(Model_ENet,newx=x[1:32,], newy=y)
RMSE_ENet1 <- sqrt(Performance_ENet$mse)
RMSE_ENet1
## s0
## 439.1226
## attr(,"measure")
## [1] "Mean-Squared Error"
# Korelasi Antara Pertumbuhan Ekonomi dan Y Duga
cor.test (y, y_dugaENet)
##
## Pearson's product-moment correlation
##
## data: y and y_dugaENet
## t = 45.643, df = 30, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.9853057 0.9965537
## sample estimates:
## cor
## 0.9928768