Single change
Detecting change point is a two step process:
Is there a change point?
When did the change happen?
Is there a change
mcppv
uses randomization to calculate the p-value of observing the particular sequence. It uses shuffle!
to re-arrange the centered time series. For repeatable results, set the random number seed first.
using ChangePointMean
using Random
ts = [1, 2, 1, 2, 1, 2, 10, 11, 10, 11, 10]
for _ in 1:10
Random.seed!(888)
println(mcppv(ts))
end
0.005988023952095809 0.005988023952095809 0.005988023952095809 0.005988023952095809 0.005988023952095809 0.005988023952095809 0.005988023952095809 0.005988023952095809 0.005988023952095809 0.005988023952095809
If the random number seed is not set, the results will not be repeatable:
ts = [1, 2, 1, 2, 1, 2, 10, 11, 10, 11, 10]
Random.seed!(888)
for _ in 1:10
println(mcppv(ts))
end
0.005988023952095809 0.005988023952095809 0.005988023952095809 0.001996007984031936 0.005988023952095809 0.003992015968063872 0.001996007984031936 0.003992015968063872 0.005988023952095809 0.003992015968063872
When is the change
mcptime
estimates the location of the change point by finding the location of minimum sum of squares when the time series is split into two halves.
mcptime(ts)
7
A single change point
mcpoint
uses mcppv
and mcptime
together to return the location of a change point, the start of a new shifted sub-series:
mcpoint(ts)
7
If there is no change point, mcpoint
returns 0:
mcpoint([1, 1, 1, 1, 1, 1, 1, 1, 1])
0
You can use minlen
to control the length of segments:
mcptime([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10, 10, 10])
12
mcptime([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10, 10, 10]; minlen = 4)
11