0

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

2
  • Where exactly do you get the error messages? I would assume in the call to efp(). What is the output of str(data)? Aug 26, 2014 at 8:04
  • @StephanKolassa, When I run the code on terminal using Rscript test.R , I got this error messages. I'm very new in R. I don't know how to get str(data). However, when I typed data on the R console, I get a data frame. Thanks
    – precision
    Aug 26, 2014 at 13:23

1 Answer 1

1

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")
2
  • @coulminer_I tried your code and I got the following error:Loading required package: zoo Attaching package: ‘zoo’ The following objects are masked from ‘package:base’: as.Date, as.Date.numeric Loading required package: sandwich OLS-based CUSUM test with mean L2 norm data: ocus S0 = 307.4023, p-value = 0.005 Error in model.frame.default(formula, data = data) : invalid type (list) for variable 'data' Calls: breakpoints ... breakpoints.formula -> model.frame -> model.frame.default Execution halted ----------------------
    – precision
    Aug 26, 2014 at 13:16
  • 1
    that is because you are again using the data frame called "data" in the formula where a variable is expected. solution is same as in previous case: substitute data with data$V1 also in the part where you estimate breakpoints, like this: bp <- breakpoints(data$V1 ~1)
    – coulminer
    Aug 26, 2014 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.