Change point detection

I'm trying to find change points of multiple data using for loop.
In the for loop, each data needs to be typed their own ncpts value(which is 3 in the codes below).
So, I want to know how to get the vector or list of possible ncpts given in the error message which I can use in the for loop.
The codes below are just for checking.

library(changepoint)
set.seed(1)
x=c(rnorm(50,0,1),rnorm(50,5,3),rnorm(50,10,2))
out=cpt.meanvar(x, pen.value=c(2*log(length(x)),100*log(length(x))),penalty="CROPS",method="PELT")
cpts.full(out) #range of segmentations
pen.value.full(out)
plot(out,diagnostic =TRUE)
plot(out, ylab='Data', ncpts=3)
Error in .local(x, ...) : 
  Your input object doesn't have a segmentation with the requested number of changepoints.
 Possible ncpts are: 15,11,9,7,5,2,1,0

Created on 2020-09-25 by the reprex package (v0.3.0)

1 Like

Can you provide a reproducible example? It will make it easier to work out what you are doing. FAQ: What's a reproducible example (`reprex`) and how do I do one?

I've been trying to use reprex but it says 'Sorry, new users can only put one embedded media item in a post.'

Your reprex is fine. I can't work out how to get the list of ncpts though. Hopefully someone else can.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.