R Code
R Code
setwd("~/Sinha")
# Library locations #
library("MTS", lib.loc="~/R/win-library/3.3")
library("MSBVAR", lib.loc="~/R/win-library/3.3")
library("bvarsv", lib.loc="~/R/win-library/3.3")
library("urca", lib.loc="~/R/win-library/3.3")
library("uroot", lib.loc="~/R/win-library/3.3")
library("vars", lib.loc="~/R/win-library/3.3")
library("tsDyn", lib.loc="~/R/win-library/3.3")
library("TSA", lib.loc="~/R/win-library/3.3")
gdp = Gendata1[,2]
cpi = Gendata1[,3]
Xt
win.graph(width=7.5, height=4.5,pointsize=12)
par(mfrow=c(1,1))
plot(Yt, ylab="GDP of India", xlab= "Time ", type = "l",
main = "Fig. 4.1 Time plot of quarterly GDP 2010-2017")
plot(Xt, ylab="Consumer's Price Index (CPI)", xlab= "Time", type = "l",
main = "Fig. 4.2 : Time plot of Quarterly Consumers Price Index, 2010-2017")
acf(Xt, lag.max = 56, plot = TRUE, main = "ACF plot of India Consumer Price Index")
pacf(Xt, lag.max = 56, plot = TRUE, main = "PACF plot of India Consumer rice
Index")
### Cointegraion
lg.reg <-lm(Yt~Xt)
error<- lg.reg$residuals
RES = ur.df(error, type = "drift", selectlags = "AIC")
summary(RES)
co.data = cbind(gdp,cpi)
VARselect(co.data, type = "const")$selection
cointest = ca.jo(co.data, 10, type = "trace", ecdet = "const",
spec = "transitory")
cointest
cointest@cval
cointest@teststat[2]
cointest@teststat[1]
gdp = gdp
cpi = cpi
d.gdp = diff(gdp)
d.cpi = diff(cpi)
adf.test(gdp); adf.test(cpi)
modelvar$varresult
summary(modelvar)
data("mts-examples",package="MTS")
z=log(co.data[,1:2])
zt=diffM(z)*100
C=0.1*diag(rep(1,3))
V0=diag(rep(1,2))
model = BVAR(zt,p=1,C,V0)
summary(model)
model$residuals
model$residuals
forecast(model, nsteps = 29)
# Fit model
m1 <- msbvar(Y.sample1, p=1, h=2, lambda0=0.8, lambda1=0.2,
lambda3=1, lambda4=0.2, lambda5=0, mu5=0, mu6=0,
qm=12, prior=0)
# Gibbs sampling
# Summarize forecasts
apply(msforc$forecasts, c(2,3), mean)