0% found this document useful (0 votes)
24 views11 pages

CPI VT

ss

Uploaded by

Thục Đoan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views11 pages

CPI VT

ss

Uploaded by

Thục Đoan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

library(readxl)

CPI_U <- read_excel("C:/Users/DELL/Desktop/CPI.U.xlsx")

r<-CPI_U$r
library(carData)
library(zoo)

##
## Attaching package: 'zoo'

## The following objects are masked from 'package:base':


##
## as.Date, as.Date.numeric

library(foreign)
library(dynlm)
library(sandwich)
library(car)
library(ggplot2)
library(forecast)

## Registered S3 method overwritten by 'quantmod':


## method from
## as.zoo.data.frame zoo

library(tseries)
library(urca)

r=ts(r, start=c(1995,8), end=c(2023,12),frequency = 12 )

summary(r)

## Min. 1st Qu. Median Mean 3rd Qu. Max.


## -0.344160 -0.055253 -0.002271 0.003145 0.050269 0.280229

plot(r)
r.ts=decompose(r, type = c("additive"), filter = NULL)
autoplot(r.ts)
r.ts1=decompose(r, type = c("multiplicative"), filter = NULL)
autoplot(r.ts1)

Box.test(r)

##
## Box-Pierce test
##
## data: r
## X-squared = 1.3714, df = 1, p-value = 0.2416

adf.test(r)

## Warning in adf.test(r): p-value smaller than printed p-value

##
## Augmented Dickey-Fuller Test
##
## data: r
## Dickey-Fuller = -11.482, Lag order = 6, p-value = 0.01
## alternative hypothesis: stationary

acf(r)
pacf(r)

summary(ur.df(r, type = "trend",lags=12))


##
## ###############################################
## # Augmented Dickey-Fuller Test Unit Root Test #
## ###############################################
##
## Test regression trend
##
##
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + tt + z.diff.lag)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.265628 -0.037502 -0.000972 0.039352 0.211840
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 6.265e-03 7.374e-03 0.850 0.396224
## z.lag.1 -2.024e+00 3.986e-01 -5.077 6.59e-07 ***
## tt -4.280e-06 3.637e-05 -0.118 0.906401
## z.diff.lag1 7.504e-01 3.838e-01 1.955 0.051489 .
## z.diff.lag2 5.959e-01 3.558e-01 1.675 0.094968 .
## z.diff.lag3 5.091e-01 3.243e-01 1.570 0.117496
## z.diff.lag4 2.281e-01 2.939e-01 0.776 0.438227
## z.diff.lag5 1.686e-01 2.613e-01 0.645 0.519096
## z.diff.lag6 -5.974e-02 2.295e-01 -0.260 0.794752
## z.diff.lag7 -1.975e-01 1.973e-01 -1.001 0.317807
## z.diff.lag8 -3.658e-01 1.679e-01 -2.179 0.030083 *
## z.diff.lag9 -4.530e-01 1.364e-01 -3.322 0.000999 ***
## z.diff.lag10 -6.373e-01 1.098e-01 -5.801 1.61e-08 ***
## z.diff.lag11 -6.222e-01 8.297e-02 -7.499 6.69e-13 ***
## z.diff.lag12 -1.265e-01 5.522e-02 -2.290 0.022673 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.06234 on 313 degrees of freedom
## Multiple R-squared: 0.7701, Adjusted R-squared: 0.7598
## F-statistic: 74.89 on 14 and 313 DF, p-value: < 2.2e-16
##
##
## Value of test-statistic is: -5.0773 8.5954 12.8896
##
## Critical values for test statistics:
## 1pct 5pct 10pct
## tau3 -3.98 -3.42 -3.13
## phi2 6.15 4.71 4.05
## phi3 8.34 6.30 5.36

acf(diff(r,12),lag.max = 25, plot=TRUE,na.action = na.contiguous)


pacf(diff(r,12),lag.max = 25, plot=TRUE,na.action = na.contiguous)
reg1=arima((window(r, end= c(2023,12))),order=c(1,1,1), seasonal=
list(order = c(1,1,1), period = 12),method=c("CSS-ML", "ML", "CSS"),
optim.control = list(maxit= 1000))
summary(reg1)

##
## Call:
## arima(x = (window(r, end = c(2023, 12))), order = c(1, 1, 1),
seasonal = list(order = c(1,
## 1, 1), period = 12), method = c("CSS-ML", "ML", "CSS"),
optim.control = list(maxit = 1000))
##
## Coefficients:
## ar1 ma1 sar1 sma1
## -0.2962 -1.0000 0.2027 -0.9216
## s.e. 0.0530 0.0121 0.0657 0.0456
##
## sigma^2 estimated as 0.003386: log likelihood = 453.4, aic = -
896.8
##
## Training set error measures:
## ME RMSE MAE MPE MAPE
MASE
## Training set -0.001008867 0.05707262 0.04176693 9.931916 184.0122
0.4199934
## ACF1
## Training set -0.07742582

reg2=arima((window(r, end= c(2023,12))),order=c(1,1,2), seasonal=


list(order = c(1,1,1), period = 12),method=c("CSS-ML", "ML", "CSS"),
optim.control = list(maxit= 1000))
summary(reg2)

##
## Call:
## arima(x = (window(r, end = c(2023, 12))), order = c(1, 1, 2),
seasonal = list(order = c(1,
## 1, 1), period = 12), method = c("CSS-ML", "ML", "CSS"),
optim.control = list(maxit = 1000))
##
## Coefficients:
## ar1 ma1 ma2 sar1 sma1
## 0.2136 -1.6121 0.6121 0.2111 -0.9504
## s.e. 0.1101 0.0895 0.0885 0.0650 0.0588
##
## sigma^2 estimated as 0.003133: log likelihood = 463.33, aic = -
914.66
##
## Training set error measures:
## ME RMSE MAE MPE MAPE
MASE
## Training set -0.0005491916 0.05489814 0.04009895 8.325093 181.8746
0.4032208
## ACF1
## Training set 0.002681089

reg3=arima((window(r, end= c(2023,12))),order=c(2,1,2), seasonal=


list(order = c(1,1,1), period = 12),method=c("CSS-ML", "ML", "CSS"),
optim.control = list(maxit= 1000))
summary(reg3)

##
## Call:
## arima(x = (window(r, end = c(2023, 12))), order = c(2, 1, 2),
seasonal = list(order = c(1,
## 1, 1), period = 12), method = c("CSS-ML", "ML", "CSS"),
optim.control = list(maxit = 1000))
##
## Coefficients:
## ar1 ar2 ma1 ma2 sar1 sma1
## 0.0760 -0.0952 -1.4672 0.4672 0.2055 -0.9553
## s.e. 0.2668 0.1196 0.2684 0.2680 0.0660 0.0638
##
## sigma^2 estimated as 0.003115: log likelihood = 463.76, aic = -
913.53
##
## Training set error measures:
## ME RMSE MAE MPE MAPE
MASE
## Training set -0.0006654801 0.05474198 0.0398714 8.575361 180.2003
0.4009326
## ACF1
## Training set 0.002218171

reg4=arima((window(r, end= c(2023,12))),order=c(2,1,1), seasonal=


list(order = c(1,1,1), period = 12),method=c("CSS-ML", "ML", "CSS"),
optim.control = list(maxit= 1000))
summary(reg4)

##
## Call:
## arima(x = (window(r, end = c(2023, 12))), order = c(2, 1, 1),
seasonal = list(order = c(1,
## 1, 1), period = 12), method = c("CSS-ML", "ML", "CSS"),
optim.control = list(maxit = 1000))
##
## Coefficients:
## ar1 ar2 ma1 sar1 sma1
## -0.3713 -0.2506 -1.0000 0.1851 -0.9413
## s.e. 0.0540 0.0539 0.0139 0.0649 0.0521
##
## sigma^2 estimated as 0.003138: log likelihood = 463.84, aic = -
915.68
##
## Training set error measures:
## ME RMSE MAE MPE MAPE
MASE
## Training set -0.0008899748 0.05493885 0.03989064 12.3036 179.5279
0.4011261
## ACF1
## Training set 0.0003392887

acf(reg1$residuals)

pacf(reg1$residuals)
adf.test(reg1$residuals)

## Warning in adf.test(reg1$residuals): p-value smaller than printed


p-value

##
## Augmented Dickey-Fuller Test
##
## data: reg1$residuals
## Dickey-Fuller = -8.5031, Lag order = 6, p-value = 0.01
## alternative hypothesis: stationary

Box.test(reg1$residuals)

##
## Box-Pierce test
##
## data: reg1$residuals
## X-squared = 2.0442, df = 1, p-value = 0.1528

autoplot(reg1)
plot(forecast(reg1,h=60))
lines(r)

You might also like