Data

#import data
dataregresi <- read_xlsx("C:\\Users\\User\\Downloads\\Tugas Individu MPDW (1).xlsx", sheet = "Sheet3")
dataregresi
## # A tibble: 12 x 2
##        x     y
##    <dbl> <dbl>
##  1  2010  54.4
##  2  2011  55.0
##  3  2012  55.6
##  4  2013  56.2
##  5  2014  56.8
##  6  2015  57.2
##  7  2016  58.0
##  8  2017  59.0
##  9  2018  60.1
## 10  2019  60.8
## 11  2020  60.4
## 12  2021  60.6

Eksplorasi Data

x <- dataregresi$x
y <- dataregresi$y

#diagram pencar identifikasi model
plot(x,y,pch = 20, col = "blue", main = "Scatter Plot X vs Y",
     ylab = "Nilai Peubah Y", xlab = "Nilai Peubah X")

Secara eksplorasi, dapat dilihat bahwa plot antara peubah Y dengan peubah X tersebut menyebar normal.
#korelasi x dan y
cor(x,y)
## [1] 0.9849151
korelasi yang didapat sangat tinggi, dengan bertambahnya nilai X seiring dengan pertambahan nilai Y-nya

Regresi Deret Waktu

#model regresi
model <- lm(y~x, data = dataregresi)
summary(model)
## 
## Call:
## lm(formula = y ~ x, data = dataregresi)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.71154 -0.18750 -0.06643  0.10696  0.77084 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.214e+03  7.068e+01  -17.18 9.43e-09 ***
## x            6.312e-01  3.507e-02   18.00 6.00e-09 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4193 on 10 degrees of freedom
## Multiple R-squared:  0.9701, Adjusted R-squared:  0.9671 
## F-statistic:   324 on 1 and 10 DF,  p-value: 5.998e-09

Deteksi Autokorelasi

1. Residual Plot

#sisaan dan fitted value
resi1 <- residuals(model)
fit <- predict(model)

#Diagnostik dengan eksploratif
par(mfrow = c(2,2))

qqnorm(resi1)
qqline(resi1, col = "steelblue", lwd = 2)

plot(fit, resi1, col = "steelblue", pch = 20, xlab = "Sisaan", 
     ylab = "Fitted Values", main = "Sisaan vs Fitted Values")
abline(a = 0, b = 0, lwd = 2)

hist(resi1, col = "steelblue")

plot(seq(1,12,1), resi1, col = "steelblue", pch = 20, 
     xlab = "Sisaan", ylab = "Order", main = "Sisaan vs Order")
lines(seq(1,12,1), resi1, col = "red")
abline(a = 0, b = 0, lwd = 2)

2. ACF dan PACF Plot

#ACF dan PACF identifikasi autokorelasi
par(mfrow = c(2,1))
acf(resi1)
pacf(resi1)

Uji Statistik

1. Durbin Watson Test

H0 : tidak ada autokorelasi
H1 : ada autokorelasi

lmtest::dwtest(model, alternative = 'two.sided') #ada autokorelasi
## 
##  Durbin-Watson test
## 
## data:  model
## DW = 0.93809, p-value = 0.01136
## alternative hypothesis: true autocorrelation is not 0
Didapat p-value < 0.05 (Tolak H0), cukup bukti bahwa terdapat autokolerasi pada taraf nyata 5%

2. Breusch-Godfrey Test

H0: tidak ada autokorelasi
H1: ada autokorelasi

bgtest(y ~ x, data=dataregresi, order=1) #Perform Breusch-Godfrey test for first-order serial correlation
## 
##  Breusch-Godfrey test for serial correlation of order up to 1
## 
## data:  y ~ x
## LM test = 2.9638, df = 1, p-value = 0.08515
Didapat p-value > 0.05 (Tak Tolak H0), tidak cukup bukti bahwa terdapat autokolerasi pada taraf nyata 5%

Karena kedua test yang dilakukan sebelumnya menghasilkan kesimpulan yang berbeda, maka diperlukan uji lain untuk mengambil keputusan.

3. Run’s Test

runs.test(resid(model), alternative = 'two.sided')
## 
##  Runs Test - Two sided
## 
## data:  resid(model)
## Standardized Runs Statistic = -0.60553, p-value = 0.5448
Didapat p-value > 0.05 (Tolak H0), tidak cukup bukti bahwa terdapat autokolerasi pada taraf nyata 5%\

Tidak cukup bukti bahwa terdapat autokorelasi pada taraf nyata 5% pada data IPM Papua.