Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MJacobs1985/2269b53190d27d1c11ee04b5a7540d99 to your computer and use it in GitHub Desktop.
Save MJacobs1985/2269b53190d27d1c11ee04b5a7540d99 to your computer and use it in GitHub Desktop.
mymts<-dataset%>%dplyr::select(VO2i_methode1,DO2i_methode1,RQ_methode1)%>%ts(.)
mymts
plot(mymts)
theme_set(theme_bw())
autoplot(mymts) +
ggtitle("Time Series Plot of the `mymts' Time-Series") +
theme(plot.title = element_text(hjust = 0.5)) #for centering the text
class(mymts)
apply(mymts, 2, adf.test)
plot.ts(mymts)
autoplot(ts(mymts))
VARselect(mymts,
type = "none", #type of deterministic regressors to include. We use none becasue the time series was made stationary using differencing above.
lag.max = 10)
var.a <- vars::VAR(mymts,
lag.max = 10, #highest lag order for lag length selection according to the choosen ic
ic = "AIC", #information criterion
type = "none") #type of deterministic regressors to include
summary(var.a)
serial.test(var.a)
plot(var.a)
causality(var.a, #VAR model
cause = c("VO2i_methode1"))
fcast = predict(var.a, n.ahead = 500) # we forecast over a short horizon because beyond short horizon prediction becomes unreliable or uniform
par(mar = c(2.5,2.5,2.5,2.5))
plot(fcast)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment