# Example of multiple changes in mean and variance at 50,100,150 in simulated Gamma data
set.seed(1)
x=c(rgamma(50,shape=1,rate=1),rgamma(50,shape=1,rate=3),rgamma(50,shape=1,rate=1),rgamma(50,shape=1,rate=10))
segneigh.meanvar.gamma(x,shape=1, Q=5, pen=2*log(200)) # returns optimal number as 3 and the locations as c(47,102,150)
segneigh.meanvar.gamma(x,shape=1, Q=3, pen=2*log(200)) # returns optimal number as 2 as this is the maximum number of changepoints it can find. If you get the maximum number, you need to increase Q until this is not the case.
# Example no change in mean or variance
set.seed(1)
x=rgamma(200,shape=1,rate=1)
segneigh.meanvar.gamma(x,shape=1,pen=2*log(200)) # returns optimal number as 0
Run the code above in your browser using DataLab