Tugas Praktikum ADP

Nabil Izzany

2023-04-07

library(readxl)
library(tidyverse)
library(car)
library(plm)
library(tseries)
library(lmtest)
library(broom)
library(flextable)
library(lme4)
library(lmerTest)
library(pglm)
library(nlme)
library(kableExtra)
data <- read_xlsx("C:/Users/Nabil Izzany/Documents/Kuylah/Semester 6/Analisis Data Panel/Data (1).xlsx")

data$INFRA <- data$INFRA/100000
head(data)
## # A tibble: 6 × 7
##   PROVINSI TAHUN INFRA  PEKO  INFL  PGGR  KMIS
##   <chr>    <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Bali      2008  4.31  5.97  9.62  3.31  6.17
## 2 Bali      2009  4.84  5.33  4.37  3.13  5.13
## 3 Bali      2010  3.36  5.83  8.1   3.06  4.88
## 4 Bali      2011  2.99  6.49  3.75  2.95  4.2 
## 5 Bali      2012  3.49  6.65  4.71  2.1   3.95
## 6 Bali      2013  3.99  6.69  8.16  1.83  4.49

Multikol

model_08 <- lm(KMIS~INFRA+PEKO+INFL+PGGR,data%>%filter(TAHUN==2008))
model_09 <- lm(KMIS~INFRA+PEKO+INFL+PGGR,data%>%filter(TAHUN==2009))
model_10 <- lm(KMIS~INFRA+PEKO+INFL+PGGR,data%>%filter(TAHUN==2010))
model_11 <- lm(KMIS~INFRA+PEKO+INFL+PGGR,data%>%filter(TAHUN==2011))
model_12 <- lm(KMIS~INFRA+PEKO+INFL+PGGR,data%>%filter(TAHUN==2012))
model_13 <- lm(KMIS~INFRA+PEKO+INFL+PGGR,data%>%filter(TAHUN==2013))
model_14 <- lm(KMIS~INFRA+PEKO+INFL+PGGR,data%>%filter(TAHUN==2014))
model_15 <- lm(KMIS~INFRA+PEKO+INFL+PGGR,data%>%filter(TAHUN==2015))
model_16 <- lm(KMIS~INFRA+PEKO+INFL+PGGR,data%>%filter(TAHUN==2016))
model_17 <- lm(KMIS~INFRA+PEKO+INFL+PGGR,data%>%filter(TAHUN==2017))
model_18 <- lm(KMIS~INFRA+PEKO+INFL+PGGR,data%>%filter(TAHUN==2018))
model_19 <- lm(KMIS~INFRA+PEKO+INFL+PGGR,data%>%filter(TAHUN==2019))
model_20 <- lm(KMIS~INFRA+PEKO+INFL+PGGR,data%>%filter(TAHUN==2020))
model_full <- lm(KMIS~INFRA+PEKO+INFL+PGGR,data)

Multikol <- rbind(as.vector(vif(model_08)),as.vector(vif(model_09)),as.vector(vif(model_10)),
           as.vector(vif(model_11)),as.vector(vif(model_12)),as.vector(vif(model_13)),
           as.vector(vif(model_14)),as.vector(vif(model_15)),as.vector(vif(model_16)),
           as.vector(vif(model_17)),as.vector(vif(model_18)),as.vector(vif(model_19)),
           as.vector(vif(model_20)),as.vector(vif(model_full))
           )

rownames(Multikol) <- c("Tahun 2008","Tahun 2009","Tahun 2010",
                        "Tahun 2011","Tahun 2012","Tahun 2013","Tahun 2014",
                        "Tahun 2015","Tahun 2016","Tahun 2017","Tahun 2018",
                        "Tahun 2019","Tahun 2020","Tahun 2008-2020")

colnames(Multikol) <- c("INFRA","PEKO","INFL","PGGR")

Multikol
##                    INFRA     PEKO     INFL     PGGR
## Tahun 2008      1.018128 1.039962 1.008180 1.027142
## Tahun 2009      1.005583 1.098824 1.051225 1.093657
## Tahun 2010      1.026937 1.219132 1.216510 1.062607
## Tahun 2011      1.135149 1.261387 1.332625 1.157114
## Tahun 2012      1.073155 1.099455 1.059840 1.077085
## Tahun 2013      1.089168 1.340071 1.177480 1.363017
## Tahun 2014      1.003681 1.139900 1.013858 1.158505
## Tahun 2015      1.027002 1.116258 1.033706 1.118729
## Tahun 2016      1.018004 1.463559 1.165066 1.269270
## Tahun 2017      1.001229 1.029898 1.061055 1.062875
## Tahun 2018      1.005769 1.031605 1.029227 1.008431
## Tahun 2019      1.023695 1.177636 1.117407 1.037509
## Tahun 2020      1.059669 1.233411 1.161370 1.117794
## Tahun 2008-2020 1.124957 1.057116 1.157683 1.048047

Pemilihan Model Terbaik

Common Effect Model

cem <- plm(KMIS~INFRA+PEKO+INFL+PGGR, data=data, model = "pooling")
summary(cem)
## Pooling Model
## 
## Call:
## plm(formula = KMIS ~ INFRA + PEKO + INFL + PGGR, data = data, 
##     model = "pooling")
## 
## Balanced Panel: n = 32, T = 13, N = 416
## 
## Residuals:
##    Min. 1st Qu.  Median 3rd Qu.    Max. 
## -9.1611 -5.1292 -1.5170  4.5191 19.6026 
## 
## Coefficients:
##             Estimate Std. Error t-value  Pr(>|t|)    
## (Intercept) 6.670704   1.196074  5.5772 4.438e-08 ***
## INFRA       0.103474   0.029780  3.4746 0.0005661 ***
## PEKO        0.502862   0.082736  6.0779 2.781e-09 ***
## INFL        0.313383   0.103938  3.0151 0.0027284 ** 
## PGGR        0.048913   0.135313  0.3615 0.7179249    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    17772
## Residual Sum of Squares: 15525
## R-Squared:      0.12645
## Adj. R-Squared: 0.11794
## F-statistic: 14.873 on 4 and 411 DF, p-value: 2.3234e-11

Uji Asumsi CEM

res.cem <- residuals(cem)

normal <- jarque.bera.test(res.cem) # Normal
homos <- bptest(cem) # Homoskedastisitas
autokol <- pbgtest(cem) # Autokol

asumsi_cem <- data.frame(Asumsi=c("Normalitas","Homoskesdastisitas","Non-Autokorelasi"),
           PValue=c(normal$p.value,homos$p.value,autokol$p.value),
           Keputusan=c("Tolak H0", "Tolak H0", "Tolak H0"))
asumsi_cem
##               Asumsi       PValue Keputusan
## 1         Normalitas 9.355164e-10  Tolak H0
## 2 Homoskesdastisitas 1.934845e-03  Tolak H0
## 3   Non-Autokorelasi 2.991775e-64  Tolak H0

Fixed Effect Model

fem.twoway <- plm(KMIS~INFRA+PEKO+INFL+PGGR, data, model = "within", 
                 effect= "twoways", index = c("PROVINSI","TAHUN"))
summary(fem.twoway)
## Twoways effects Within Model
## 
## Call:
## plm(formula = KMIS ~ INFRA + PEKO + INFL + PGGR, data = data, 
##     effect = "twoways", model = "within", index = c("PROVINSI", 
##         "TAHUN"))
## 
## Balanced Panel: n = 32, T = 13, N = 416
## 
## Residuals:
##      Min.   1st Qu.    Median   3rd Qu.      Max. 
## -3.718143 -0.713539  0.050615  0.682921  4.957867 
## 
## Coefficients:
##        Estimate Std. Error t-value  Pr(>|t|)    
## INFRA -0.062411   0.015858 -3.9356 9.922e-05 ***
## PEKO   0.153983   0.024514  6.2813 9.478e-10 ***
## INFL   0.110982   0.047496  2.3367   0.01999 *  
## PGGR  -0.063412   0.078861 -0.8041   0.42186    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    695.57
## Residual Sum of Squares: 592.21
## R-Squared:      0.14859
## Adj. R-Squared: 0.039851
## F-statistic: 16.0562 on 4 and 368 DF, p-value: 3.9613e-12

Uji Asumsi FEM

res.fem.twoway <- residuals(fem.twoway)

normal.fem.2 <- jarque.bera.test(res.fem.twoway)
homos.fem.2 <- bptest(fem.twoway)
autokol.fem.2 <- pbgtest(fem.twoway)

asumsi.fem.2 <- data.frame(Asumsi=c("Normalitas","Homoskesdastisitas","Non-Autokorelasi"),
           PValue=c(normal.fem.2$p.value,homos.fem.2$p.value,autokol.fem.2$p.value),
           Keputusan=c("Tolak H0", "Tolak H0", "Tolak H0"))
asumsi.fem.2
##               Asumsi       PValue Keputusan
## 1         Normalitas 4.773959e-15  Tolak H0
## 2 Homoskesdastisitas 1.934845e-03  Tolak H0
## 3   Non-Autokorelasi 1.967413e-34  Tolak H0

Uji Chow

H0 : Pilih Common Effect H1 : Pilih Fixed Effect

pooltest(cem,fem.twoway)
## 
##  F statistic
## 
## data:  KMIS ~ INFRA + PEKO + INFL + PGGR
## F = 215.8, df1 = 43, df2 = 368, p-value < 2.2e-16
## alternative hypothesis: unstability

Random Effect Model

rem.twoway <- plm(KMIS~INFRA+PEKO+INFL+PGGR, data, model = "random", 
                 effect= "twoways", index = c("PROVINSI","TAHUN"))
summary(rem.twoway)
## Twoways effects Random Effect Model 
##    (Swamy-Arora's transformation)
## 
## Call:
## plm(formula = KMIS ~ INFRA + PEKO + INFL + PGGR, data = data, 
##     effect = "twoways", model = "random", index = c("PROVINSI", 
##         "TAHUN"))
## 
## Balanced Panel: n = 32, T = 13, N = 416
## 
## Effects:
##                   var std.dev share
## idiosyncratic  1.6093  1.2686 0.047
## individual    32.6514  5.7141 0.947
## time           0.2158  0.4646 0.006
## theta: 0.9385 (id) 0.5653 (time) 0.5648 (total)
## 
## Residuals:
##     Min.  1st Qu.   Median  3rd Qu.     Max. 
## -3.48112 -0.80340 -0.21541  0.46391  6.46679 
## 
## Coefficients:
##              Estimate Std. Error z-value  Pr(>|z|)    
## (Intercept) 10.882843   1.246213  8.7327 < 2.2e-16 ***
## INFRA       -0.078316   0.014391 -5.4421 5.266e-08 ***
## PEKO         0.169723   0.024964  6.7988 1.055e-11 ***
## INFL         0.172517   0.038357  4.4977 6.871e-06 ***
## PGGR         0.162553   0.077831  2.0886   0.03675 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Total Sum of Squares:    1018
## Residual Sum of Squares: 773.87
## R-Squared:      0.23978
## Adj. R-Squared: 0.23238
## Chisq: 129.63 on 4 DF, p-value: < 2.22e-16
res.rem.twoway <- residuals(rem.twoway)

normal.rem.2 <- jarque.bera.test(res.rem.twoway)
homos.rem.2 <- bptest(rem.twoway)
autokol.rem.2 <- pbgtest(rem.twoway)


asumsi.rem <- data.frame(Asumsi=c("Normalitas","Homoskesdastisitas","Non-Autokorelasi"),
           PValue=c(normal.rem.2$p.value,homos.rem.2$p.value,autokol.rem.2$p.value),
           Keputusan=c("Tolak H0", "Tolak H0", "Tolak H0"))
asumsi.rem
##               Asumsi       PValue Keputusan
## 1         Normalitas 0.000000e+00  Tolak H0
## 2 Homoskesdastisitas 1.934845e-03  Tolak H0
## 3   Non-Autokorelasi 3.324685e-35  Tolak H0

Uji Haussman

H0 : Pilih Random Effect H1 : Pilih Fixed Effect

phtest(fem.twoway, rem.twoway)
## 
##  Hausman Test
## 
## data:  KMIS ~ INFRA + PEKO + INFL + PGGR
## chisq = 40.108, df = 4, p-value = 4.111e-08
## alternative hypothesis: one model is inconsistent

Fixed Effect Model

# efek individu dan waktu
plmtest(fem.twoway,type = "bp", effect="twoways")
## 
##  Lagrange Multiplier Test - two-ways effects (Breusch-Pagan)
## 
## data:  KMIS ~ INFRA + PEKO + INFL + PGGR
## chisq = 1746.8, df = 2, p-value < 2.2e-16
## alternative hypothesis: significant effects
# efek individu
plmtest(fem.twoway,type = "bp", effect="individual")
## 
##  Lagrange Multiplier Test - (Breusch-Pagan)
## 
## data:  KMIS ~ INFRA + PEKO + INFL + PGGR
## chisq = 1726.2, df = 1, p-value < 2.2e-16
## alternative hypothesis: significant effects
# efek waktu
plmtest(fem.twoway,type = "bp", effect="time")
## 
##  Lagrange Multiplier Test - time effects (Breusch-Pagan)
## 
## data:  KMIS ~ INFRA + PEKO + INFL + PGGR
## chisq = 20.619, df = 1, p-value = 5.605e-06
## alternative hypothesis: significant effects

Fixed Effect dengan LSDV

fem.lsdv <- lm(KMIS~INFRA+PEKO+INFL+PGGR+factor(TAHUN)+factor(PROVINSI) , data)
summary(fem.lsdv)
## 
## Call:
## lm(formula = KMIS ~ INFRA + PEKO + INFL + PGGR + factor(TAHUN) + 
##     factor(PROVINSI), data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.7181 -0.7135  0.0506  0.6829  4.9579 
## 
## Coefficients:
##                              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                  21.74660    1.05705  20.573  < 2e-16 ***
## INFRA                        -0.06241    0.01586  -3.936 9.92e-05 ***
## PEKO                          0.15398    0.02451   6.281 9.48e-10 ***
## INFL                          0.11098    0.04750   2.337   0.0200 *  
## PGGR                         -0.06341    0.07886  -0.804   0.4219    
## factor(TAHUN)2009            -0.08688    0.49873  -0.174   0.8618    
## factor(TAHUN)2010            -1.66799    0.38303  -4.355 1.73e-05 ***
## factor(TAHUN)2011            -2.40129    0.48322  -4.969 1.03e-06 ***
## factor(TAHUN)2012            -3.48541    0.49066  -7.103 6.34e-12 ***
## factor(TAHUN)2013            -3.81264    0.39315  -9.698  < 2e-16 ***
## factor(TAHUN)2014            -4.15197    0.39123 -10.613  < 2e-16 ***
## factor(TAHUN)2015            -3.44188    0.50533  -6.811 3.96e-11 ***
## factor(TAHUN)2016            -2.70009    0.64641  -4.177 3.69e-05 ***
## factor(TAHUN)2017            -3.76441    0.57400  -6.558 1.85e-10 ***
## factor(TAHUN)2018            -4.05674    0.59247  -6.847 3.17e-11 ***
## factor(TAHUN)2019            -4.22990    0.62942  -6.720 6.92e-11 ***
## factor(TAHUN)2020            -3.01961    0.63732  -4.738 3.09e-06 ***
## factor(PROVINSI)BABEL       -14.01452    0.61293 -22.865  < 2e-16 ***
## factor(PROVINSI)Bali        -15.17667    0.69683 -21.779  < 2e-16 ***
## factor(PROVINSI)Banten      -13.08043    0.57988 -22.557  < 2e-16 ***
## factor(PROVINSI)Bengkulu     -2.50468    0.62056  -4.036 6.61e-05 ***
## factor(PROVINSI)DIY          -5.14729    0.63307  -8.131 6.60e-15 ***
## factor(PROVINSI)Gorontalo    -1.02812    0.60819  -1.690   0.0918 .  
## factor(PROVINSI)JABAR        -8.55617    0.52753 -16.219  < 2e-16 ***
## factor(PROVINSI)Jambi       -11.46537    0.60469 -18.961  < 2e-16 ***
## factor(PROVINSI)JATENG       -3.94729    0.55750  -7.080 7.33e-12 ***
## factor(PROVINSI)JATIM        -4.97799    0.60736  -8.196 4.17e-15 ***
## factor(PROVINSI)KALBAR      -10.65580    0.57747 -18.453  < 2e-16 ***
## factor(PROVINSI)KALSEL      -14.38507    0.57534 -25.003  < 2e-16 ***
## factor(PROVINSI)KALTENG     -13.39698    0.60990 -21.966  < 2e-16 ***
## factor(PROVINSI)KALTIM      -12.23047    0.53264 -22.962  < 2e-16 ***
## factor(PROVINSI)Kepri       -12.65170    0.54723 -23.120  < 2e-16 ***
## factor(PROVINSI)Lampung      -3.72484    0.55652  -6.693 8.17e-11 ***
## factor(PROVINSI)Maluku        2.25632    0.52338   4.311 2.09e-05 ***
## factor(PROVINSI)MALUT       -11.62297    0.56959 -20.406  < 2e-16 ***
## factor(PROVINSI)NTB          -1.40023    0.57304  -2.444   0.0150 *  
## factor(PROVINSI)NTT           2.95019    0.62686   4.706 3.58e-06 ***
## factor(PROVINSI)PAPUA         8.80069    0.67437  13.050  < 2e-16 ***
## factor(PROVINSI)PapuaBarat    7.54665    0.55741  13.539  < 2e-16 ***
## factor(PROVINSI)RIAU        -10.73024    0.53321 -20.124  < 2e-16 ***
## factor(PROVINSI)SULBAR       -7.26047    0.66362 -10.941  < 2e-16 ***
## factor(PROVINSI)SULSEL       -8.47371    0.53991 -15.695  < 2e-16 ***
## factor(PROVINSI)SULTENG      -4.47203    0.60591  -7.381 1.06e-12 ***
## factor(PROVINSI)SulTenggara  -5.43362    0.59686  -9.104  < 2e-16 ***
## factor(PROVINSI)SULUT       -10.64917    0.51513 -20.673  < 2e-16 ***
## factor(PROVINSI)SUMBAR      -11.25656    0.52261 -21.539  < 2e-16 ***
## factor(PROVINSI)SUMSEL       -4.92304    0.54462  -9.039  < 2e-16 ***
## factor(PROVINSI)SUMUT        -8.07732    0.52420 -15.409  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.269 on 368 degrees of freedom
## Multiple R-squared:  0.9667, Adjusted R-squared:  0.9624 
## F-statistic: 227.1 on 47 and 368 DF,  p-value: < 2.2e-16