r - ggplot2 plot result of ecp change point detection -
i try started change point detection in r. found interesting package called ecp
in cran. figure 6 from: http://cran.r-project.org/web/packages/ecp/vignettes/ecp.pdf depicts results of performing change point detection on several time series follows:
understand change point detection better tried build simple example on own. use samples dataset http://kdd.ics.uci.edu/databases/synthetic_control/synthetic_control.html like:
library(cluster) library(dtw) library(zoo) library(ggplot2) library(reshape2) library(ecp) synthetic_control.data <- read.table("~/pathtofile/synthetic_control.data.txt", quote="\"", comment.char="") n <- 2 s <- sample(1:100, n) idx <- c(s, 100+s, 200+s, 300+s, 400+s, 500+s) sample2 <- synthetic_control.data[idx,] observedlabels <- c(rep(1,n), rep(2,n), rep(3,n), rep(4,n), rep(5,n), rep(6,n)) df = as.data.frame(t(as.matrix(sample2)))
this part of code performs change point detection , clustering
output1 <- e.divisive(as.matrix(df), k=null, r = 400, alpha = 2, min.size = 2) head(output1) df$id = 1:nrow(df) dfmelt <- reshape2::melt(df, id.vars = "id") p = ggplot(dfmelt,aes(x=id,y=value))+geom_line(color = "steelblue") +facet_wrap(~ variable, scales = 'free_y', ncol = 1)
output of change point detection
this means 10 change-points found:
$k.hat [1] 10 $order.found [1] 1 61 37 30 40 48 8 14 20 54 24 $estimates [1] 1 8 14 20 24 30 37 40 48 54 61 $considered.last [1] 42 $p.values [1] 0.002493766 0.002493766 0.004987531 0.019950125 0.007481297 0.002493766 0.004987531 0.004987531 [9] 0.009975062 0.059850374 $permutations [1] 400 400 400 400 400 400 400 400 400 400
however did not succeed plot them shown in picture
p + geom_abline(output1$estimates)
results in diagonal lines
p + geom_vline(aes(yintercept = output1$estimates))
results in error.
question:
what wrong plot? how can plot own change points nicely example?
Comments
Post a Comment