removeShortSegments: Remove Short Segments from Data

View source: R/removeShortSegments.R

removeShortSegmentsR Documentation

Remove Short Segments from Data

Description

Remove the short segments from the data based on the estimated variance in changeTimes. If variance is small, segments specified may be retained.

Usage

removeShortSegments(shortduration, changes, variance, time)

Arguments

shortduration

integer vector, the elements that are determined to have short durations

changes

integer vector, the estimated change points

variance

numeric vector, the variance of the parameter estimate for the cpt object

time

numeric vector, the time vector

Value

list with elements:

  1. changes, the new change points,

  2. times, the new times at the start and end of each segment, and

  3. duration, the new durations of each segment

Examples

library(changepoint)
set.seed(45265)
tm0 <- 1001:1060
d0 <- round(c(cumsum(runif(n = 20) * 2), 
    20:1 + rnorm(n = 20), 
    runif(n = 20) * 10))  
## identify changes in variance
c0 <- cpt.var(d0, penalty = "SIC", pen.value = 1e-3, method = "PELT")
## times of changepoints
cp0 <- cpts(c0)
t0 <- c(tm0[1], tm0[sort(cp0)], tm0[60])
sdur0 <- which(diff(t0) < 10)
v0 <- param.est(c0)$variance
## Note that variance for early changepoints is low
## so they are not removed.
GENEAclassify:::removeShortSegments(shortduration = sdur0, 
    changes = cp0, 
    variance = v0, 
    time = tm0)

GENEAclassify documentation built on March 31, 2023, 9:01 p.m.