0

I'm using the strucchange package to identify breakpoints in my data, essentially trying to fit a step function. In some cases, it's very good, but in others it completely misses the steps, or doesn't identify enough of them. Is there any way to essentially tell the package, that it should be looking for the breakpoints at smaller granularity?

I followed this example to find the breakpoints: Model comparison for breakpoint time series model in R strucchange

The code I used is here:

        ts_prep <- data.frame(newdata$Num_Cycles)
        newdata_ts <- ts(data=ts_prep, start = c(1,1), frequency=num)
        plot(newdata_ts,main=num)
        break_points <- breakpoints(newdata_ts ~ 1)
        break_factor <- breakfactor(break_points)
        break_model <- lm(newdata_ts ~ break_factor - 1)
        lines(fitted(break_points), col = 4)
        simple_lm <- lm(newdata_ts ~ time(newdata_ts))
        abline(simple_lm,col='red')

Here is an example of a good fit (blue line to black): Here is an example of a good fit

And here is an example of a bad fit (blue line to black again): And this is an example of a bad fit

kkm
  • 33
  • 1
  • 7

1 Answers1

0

This can be done by passing the "h" argument, where h is the minimal segment size (as a fraction of the data). In my case 0.05 works well.

kkm
  • 33
  • 1
  • 7