# 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))
multiple.meanvar.gamma(x,shape=1,mul.method="BinSeg",penalty="Manual",value="2*log(n)",Q=5,class=FALSE) # returns optimal number of changepoints is 3, locations are 47,104,150.
# Example multiple datasets where the first row has multiple changes in mean and variance and the second row has no change in mean or variance
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))
y=rgamma(200,shape=1,rate=1)
z=rbind(x,y)
multiple.meanvar.gamma(z,shape=1,mul.method="SegNeigh",penalty="SIC",Q=5,class=FALSE) # returns list that has two elements, the first has 4 changes in mean and variance at 47,102,151,172 and the second has no changes in mean or variance
ans=multiple.meanvar.gamma(z,shape=1,mul.method="PELT",penalty="SIC")
cpts(ans[[1]]) # same results as for the SegNeigh method.
cpts(ans[[2]]) # same results as for the SegNeigh method.
Run the code above in your browser using DataLab