alberto alberto - 4 years ago 139
R Question

Changepoint method returning last point of segment

The documentation of the changepoint package says that a changepoint is denoted as the first observation of the new segment / regime. However, when I try to detect the changepoints in this very simple example, it gives me the last observation of the segment:

library(changepoint)
x <- c(1,1,1,1,1,10,10,10,10,10)
res <- cpt.meanvar(x, class=TRUE, method="PELT")

bp <- cpts(res)
# bp contains the point 5
colors <- rep("black", length(x))
colors[bp] <- 'red'
plot(x, col=colors, pch=19, cex=1)


enter image description here

Shouldn't it return the 6th instead of the 5th?

Answer Source

As Roland highlighted this is a documentation bug. This has been reported here: https://github.com/rkillick/changepoint/issues/13 and is fixed in the github version. It will be pushed to CRAN with the next release.

This has been an open issue on StackOverflow for a long time, if alberto had reported this to the maintainer as Roland suggested i'm sure it would have been fixed sooner. A lesson to us all.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download