[R] struccchange on zoo time series

Achim Zeileis Ach|m@Ze||e|@ @end|ng |rom u|bk@@c@@t
Sun May 1 16:53:33 CEST 2022


On Sun, 1 May 2022, Naresh Gurbuxani wrote:

> 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?

The efp() function has been written before zoo was available and is hence 
confined to ts objects. The gefp() function _g_enenralizes the efp idea 
and also works with zoo series out of the box - and also with models other 
than lm()..

Internally gefp always computes a score-based CUSUM process, based on 
which various structural change tests can be computed that encompass the 
OLS-based CUSUM test. Typically, I would recommend to compute the supLM 
test, though, which is more powerful against many structural change 
alternatives. See ?gefp and the references therein for more details. A 
worked example is included below.

> 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))

Then you can continue with the following for the full score-based CUSUM 
process and corresponding supLM test with 10% trimming:

dd.scus <- gefp(dd ~ dd.lag1 + dd.lag12, fit = lm, data = dd.z)
plot(dd.scus, functional = supLM(0.1))
sctest(dd.scus, functional = supLM(0.1))
## 	M-fluctuation test
## 
## data:  dd.scus
## f(efp) = 17.128, p-value = 0.01711

The OLS-based CUSUM test is also a special case but then you need to test 
just the first score without decorrelation:

dd.ocus <- gefp(dd ~ dd.lag1 + dd.lag12, fit = lm, data = dd.z,
   parm = 1, decorrelate = FALSE)
plot(dd.ocus)
sctest(dd.ocus)
## 	M-fluctuation test
## 
## data:  dd.ocus
## f(efp) = 1.4991, p-value = 0.02234

Compared to the book the results differ slightly due to different degrees 
of freedom adjustments that are used by default.

Best,
Achim

> # 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
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


More information about the R-help mailing list