dpseg_old: inefficient 'dpseg' implementation

Description Usage Arguments Details Value Examples

View source: R/old.R

Description

See dpseg for a current version of this algorithm. Note: this was a first test implementation of the linear piecewise segmentation by a dynamic programming approach. This implementation is very slow. A much more efficient version, dpseg, calculates the variance of residuals of a linear regression incrementally while looping through the recursion, and is implemented in Rcpp. See there for details on the algorithm. This version is kept alive, since it is a more general implementation, allowing to test different regression and scoring functions by command-line arguments.

Usage

1
2
3
dpseg_old(x, y, minl, maxl = length(x), P = 0, EPS,
  store.matrix = FALSE, fitscoref = fitscore, fitf = linregf,
  scoref = varscore, verb = 0)

Arguments

x

x-values

y

y-values

minl

minimal segment length

maxl

maximal segment length

P

jump penalty, increase to get fewer segments # @inheritParams score

EPS

a pre-calculated fitscore matrix, will be generated if missing

store.matrix

store the fitscore matrix

fitscoref

the heavy-load loop that fills the fitscore matrix using fitf and scoref

fitf

fit function, used in the scoring function scoref; (TODO: currently expecting a fit object that provides intercept and slope as coef(obj)[1:2] only for the result table)

scoref

function to calculate a score from the passed fit function

verb

print progress messages

Details

The recursion calculates S_j = max ( S_i + fitscore(i+1,j)) - P, where the fitscore is the variance of the residuals of a linear regression (lm(y~x)) between x_{i+1} to x_j, P is a jump penality that implicitly regulates the number of segments, minl and maxl are minimal and maximal lengths of segments. Uses RcppEigen:fastLm for linear regression.

Value

Returns a list of result structures very similar to the list of class "dpseg" returned by function dpseg, except for the name of the scoring function matrix, here: EPS. See ?dpseg for detailed information on these structures.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
## NOTE: not run because it's too slow for R CMD check --as-cran
## calculate linear segments in semi-log bacterial growth data
## NOTE: library loads bacterial growth curve data as data.frame oddata
Sj <- dpseg_old(x=oddata$Time, y=log(oddata$A3), minl=5, P=0.0001, verb=1)

## inspect resulting segments
print(Sj)

## plot results
plot(Sj, delog=TRUE, log="y")

## NOTE: predict method & movie function do not work for dpseg_old

dpseg documentation built on Aug. 17, 2020, 5:06 p.m.