require(Segmentor3IsBack);
N=2000
x=c(rnbinom(N,size=1.3,prob=0.7),rnbinom(N,size=1.3,prob=0.2),
rnbinom(N,size=1.3,prob=0.01));
res=Segmentor(data=x,model=3,Kmax=10, keep=TRUE);
# Finds the optimal segmentation in up to 10 segments with respect to
#the negative binomial model.
K<-3
Best<-BestSegmentation(res,K=3,t=3000)
matplot(Best$bestCost, type='l', lty=2)
points(apply(Best$bestCost, 2, which.min), apply(Best$bestCost, 2, min), pch=20, col=1:(K-1))
apply(Best$bestCost, 2, which.min)
getBreaks(res)[K,1:(K-1)]
#computes and plots cost of best segmentation in 3 segments with
#change-point t, and compares result with change-point estimates.
Best$bestSeg
#returns the optimal segmentation in 3 segments with 3000 as a
#change-point
Run the code above in your browser using DataLab