Search code examples
rmachine-learningtime-seriessampling

How to correct efp() error "invalid type (list) for variable 'data'"?


I have a large(>100,000) single column floating point time-series data. I want to find structural changes within the data with respect to time( in my case index). In-order to do that, I am using R strucchange package. But I'm getting error. I expect to generate the following kind of plot with my dataset enter image description here

Here is the code which I'm using:

data = read.csv("tst1.csv", header = FALSE)
library(strucchange)

## fit, visualize and test OLS-based CUSUM test
## with a Cramer-von Mises functional
ocus <- efp(data ~ 1, type = "OLS-CUSUM")
sctest(ocus, functional = "meanL2")

## estimate breakpoints
bp <- breakpoints(data ~1)
summary(bp)

plot.ts(data)
lines(bp)
lines(fitted(bp, type = "mean"), col = 2)

I'm getting following error messages:

Loading required package: zoo

Attaching package: ‘zoo’

The following objects are masked from ‘package:base’:

as.Date, as.Date.numeric

Loading required package: sandwich
Error in model.frame.default(formula, data = data) : 
invalid type (list) for variable 'data'
Calls: efp -> model.frame -> model.frame.default
Execution halted

My data tst1.csv looks like:

0.6
0.78
0.54
0.96
0.43
1.43
1.03
0.83
0.68
3.23
3.09
2.87
...

Any help is much more appreciated.

Thanks


Solution

  • That is because data is a data frame. In order to put it in the formula correctly, try this:

    ocus <- efp(V1 ~ 1, data=data,type = "OLS-CUSUM")