This function is used to compute the cost of the best segmentation in K segments given the position of a change-point, and to return the optimal segmenation having a change-point at location t.
Usage
BestSegmentation(x,K,t=numeric(),compress=TRUE)
Arguments
x
An object of class Segmentor returned by function Segmentor
K
The number of segments of the segmentation for which the cost or best segmentation is wanted
t
The position for which the best segmentation with t as change-point is wanted
compress
A boolean stating whether data should be compressed prior to segmentation
Value
bestCost
A matrix of size n*K: the cost of the optimal segmentation with jth change-point i
bestSeg
If a t has been specified, a vector of size K+1 containing values of indicating the optimal segmentation with t as a change-point
Author(s)
Alice Cleynen, Michel Koskas and Guillem Rigaill
Maintainer: Who to complain to <alice.cleynen@agroparistech.fr>
References
PDPA: Rigaill, G. Pruned dynamic programming for optimal multiple change-point detection: Submittedhttp://arxiv.org/abs/1004.0887
PDPA: Cleynen, A. and Koskas, M. and Lebarbier, E. and Rigaill, G. and Robin, S. Segmentor3IsBack: an R package for the fast and exact
segmentation of Seq-data: Submittedhttp://arxiv.org/abs/1204.5564
Examples
require(Segmentor3IsBack);
N=2000
x=rnbinom(3*N,size=1.3,prob=rep(c(0.7,0.2,0.01),each=N));
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,compress=FALSE)
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
Best<-BestSegmentation(res,K=3,t=3000,compress=TRUE)
Best$bestSeg
# this segmentation usually does not make sense because of the
# compress option. t has to be adapted consequently
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(Segmentor3IsBack)
Segmentor3IsBack v1.8 Loaded
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/Segmentor3IsBack/BestSegmentation.Rd_%03d_medium.png", width=480, height=480)
> ### Name: BestSegmentation
> ### Title: BestSegmentation
> ### Aliases: BestSegmentation
> ### Keywords: R-package PDPA Segmentation
>
> ### ** Examples
>
> require(Segmentor3IsBack);
> N=2000
> x=rnbinom(3*N,size=1.3,prob=rep(c(0.7,0.2,0.01),each=N));
> 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,compress=FALSE)
Warning message:
In BestSegmentation(res, K = 3, t = 3000, compress = FALSE) :
Warning: Segmentor was applied with compression = TRUE, will apply new Segmentor with compression = FALSE
> 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)
[1] 2000 4000
> getBreaks(res)[K,1:(K-1)]
1th break 2th break
2000 4000
> #computes and plots cost of best segmentation in 3 segments with
> #change-point t, and compares result with change-point estimates.
> Best$bestSeg
[1] 1 3000 4000 6000
> #returns the optimal segmentation in 3 segments with 3000 as a
> #change-point
> Best<-BestSegmentation(res,K=3,t=3000,compress=TRUE)
> Best$bestSeg
[1] 1 2908 3000 4901
> # this segmentation usually does not make sense because of the
> # compress option. t has to be adapted consequently
>
>
>
>
>
> dev.off()
null device
1
>