Sie sind auf Seite 1von 2

Solution:

> malaysia <- read_excel("C:/Users/Khan/Desktop/Momina/7th/computing/R/malays


ia.xlsx")
> View(malaysia)
> tsdata=ts(malaysia, start = 1960)
> reg1 = lm(log(Yt) ~ Year, data = malaysia)
> View(reg1)
> summary(reg1)
> ytstar=reg1[["residuals"]]
> ygap = log(malaysia$Yt) – ytstar
> malaysia$OG<-ygap
> tsdata=ts(malaysia, start = 1960)
> reg2 = dynlm(formula = (diff(log(Pt))) ~ L(diff(log(Pt))) + OG, data = tsd
ata)
> View(reg2)
> summary(reg2)

[interpretation]
> #to check the significanse of the regression, we see the p-values in the re
gression where
H0=0 and
H1≠0
with the decision rule to reject H0 if p-value<0.05.
> #in this regression, we see that the p-value for L(diff(log(pt)))=0.0009<0.
005 hence it is a significant predictor of diff(log(pt)) while the p-value fo
r OG=0.472>0.05 hence we conclude that is is not a significant predictor for
diff(log(pt))
> stargazer(reg2,type = "text")
> res=residuals(reg2)
> acf(res)
> pacf(res)
> #H0: corr=0 (no correlation) if all black lines in pacf are in between the two blue
lines
> #can also conclude if black lines between blue, that this residual series is station
ary (no unit root issue)
> #we consider pacf more than acf to partial out impact of earlier lags while checking
correlation of later lags (e.g. take out impact of Rt-1 to check correlation between R
t and Rt-2)pacf=partial acf
> #hence, since in pacf, 2 blacklines at 5th and 7th lag are edging out of the blue li
nes we conclude that correlation does exist in these residuals and there is also issue
of non-stationarity among them
> (adf.test(res))
> #H0=non-stationary exists. H1=stationarity exists. decision rule=reject H0 if p-valu
e<0.05.
> #in this adf test, the p-value=0.037<0.05 hence we reject H0 and conclude that stati
onarity exists.
> #the problem we face in this is that pacf result showed nonstationarity in 5th and 7
th lags while adf-test p-value shows that the residuals are stationary. this contradic
tion could be possible as pacf shows nonstationarity in 5th and 7th lags while adf tes
t is conducted at 3 lags, where pacf also shows stationarity
> (Box.test(res,lag = 5))
> #H0= no autocorrelation, H1= autocorrelaion exists. decision rule=reject H0 if p-val
ue<0.05
> #the p-value here = 0.177>0.05 hence we DO NOT reject H0 and conclude that autocorre
lation does not exist in this model.
> (dwtest(reg2))
> #H0= no autocorrelation, H1= autocorrelation exists. decision rule=reject H0 if p-va
lue<0.05
> #for this DW test, p-value=0.2467>0.05 hence we DO NOT reject H0 means we conclude a
utocorrelation does not exist.

Das könnte Ihnen auch gefallen