dpseg_old {dpseg} | R Documentation |
inefficient dpseg
implementation
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
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 |
fit function, used in the scoring function
|
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
## 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