addLm: Adds linear regression data to 'dpseg' results or a table of...

Description Usage Arguments Value Examples

View source: R/dpseg.R

Description

addLm takes a segment table (with start/end columns) or a result object from code dpseg, calls base R function lm for each segment, and adds slope, intercept, r2 and variance of residuals to the segment table. This data is required for plot and predict method, eg. when dpseg was called with a pre-calculated scoring matrix, or alternative scoring functions or recursion.

Usage

1
addLm(dpseg, x, y)

Arguments

dpseg

result object (class "dpseg") returned by function dpseg or simply a segment table with "start" and "end" indices

x

original x-data used

y

original y-data used

Value

Returns the input dpseg object or segment table, but with original xy data and fit results from a linear regression with base R (lm(y~x)) added to the results and linear regression coefficient and goodness of fit meaurs in the main segments table.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## 1: run dpseg with store.matrix=TRUE to allow re-rung
segs <- dpseg(x=oddata$Time, y=log(oddata$A3), store.matrix=TRUE)

## 2: run dpseg with score function matrix input
segr <- dpseg(y=segs$SCR,  P=0.0001, verb=1)

## NOTE: only data indices i and j are provided in results
print(segr)

## 3: add original data and linear regression for segments
## NOTE: now also plot and predict methods work
segr <- addLm(segr, x=oddata$Time, y=log(oddata$A3))
print(segr)

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