[R] struccchange on zoo time series
Naresh Gurbuxani
n@re@h_gurbux@n| @end|ng |rom hotm@||@com
Sun May 1 14:36:54 CEST 2022
I am trying to replicate empirical fluctuation process fit (efp) described in the book "Applied Econometrics with R". This fit works when data input is an object of class ts, but not when data input is object of class zoo. I prefer to use zoo because it provides better housekeeping with dates. Is it possible to achieve the fit with zoo?
library(AER)
library(strucchange)
data(UKDriverDeaths)
dd <- log(UKDriverDeaths)
dd.z <- zoo(dd, order.by = as.yearmon(time(dd)))
dd.z <- merge(dd = dd.z, dd.lag1 = lag(dd.z, k = -1),
dd.lag12 = lag(dd.z, k = -12))
# Does not work
dd.ocus <- efp(dd ~ dd.lag1 + dd.lag12, data = na.trim(dd.z),
type = "OLS-CUSUM")
# Error message
# Error in eval(attr(mt, "variables")[[2]], data, env) :
# numeric 'envir' arg not of length one
# Works
dd.ocus <- efp(dd ~ dd.lag1 + dd.lag12, data = ts(na.trim(dd.z)),
type = "OLS-CUSUM")
# But time stamps are lost
plot(dd.ocus)
# Time indexed from 0 to 180
Thanks,
Naresh
More information about the R-help
mailing list