1

I am experimenting with the cpt and bcp packages in R. I import the following data from a CSV file:

Data plot

Here is the CSV file link: http://www.filedropper.com/cpttest

Running bcp:

p.bcp=bcp(p$Rate);
plot(p.bcp)

Point 28 is a change point according to bcp.

When running cpt, I get no indication that a change point exists:

p.cpt=cpt.mean(p$Rate,method="AMOC")
p.cpt

Wondering if anyone could advise why cpt does not detect a change point?

Gregory
  • 11
  • 5
  • 1
    Please consider [making your example reproducible](http://stackoverflow.com/q/5963269/1655567) by providing the required data or using other publicly available data set. – Konrad Mar 02 '16 at 15:40
  • Added a link to the CSV. Thank you. – Gregory Mar 02 '16 at 16:07

2 Answers2

1

See if the changepoint package satisfies your purpose. Replace the word method with PELT, BinSeg, or SegNeigh.

library(changepoint)

p.cpt <- changepoint::cpt.mean(p$Rate,method="method")
cpts(p.cpt)
bbiasi
  • 1,549
  • 2
  • 15
  • 31
1

There are many change point packages in R and you could try others. I've compiled a list here. Disclosure: I am the developer of the mcp package.

To use mcp for your problem, do:

model = list(
  Rate ~ 1,  # Intercept
  ~ 1  # Another intercept
)

library(mcp)
fit = mcp(model, p)
plot(fit)

enter image description here

See the estimate of the change point (cp_1) as well as the other parameters of the model. You could also see it as a narrow blue distribution in the plot above.

summary(fit)

Family: gaussian(link = 'identity')
Iterations: 9000 from 3 chains.
Segments:
  1: Rate ~ 1
  2: Rate ~ 1 ~ 1

Population-level parameters:
    name    mean   lower   upper Rhat n.eff
    cp_1 30.5009 3.0e+01 3.1e+01    1  6250
   int_1  0.0132 1.3e-02 1.3e-02    1  5501
   int_2  0.0071 6.8e-03 7.3e-03    1  5514
 sigma_1  0.0008 6.8e-04 9.4e-04    1  5056
Jonas Lindeløv
  • 5,442
  • 6
  • 31
  • 54
  • great answer! apparently this package has been removed from cran :( – stats_noob Sep 06 '21 at 06:18
  • @stats555 Yeah, a dependency had incompatible changes and I still haven't fixed it. I'm working on a new version but until then, you can do `remotes::install_github("lindeloev/mcp")` and install an older version of `tidybayes`. – Jonas Lindeløv Sep 06 '21 at 10:47