rolling_slope(): Computes rolling linear regression slopes within a
local window along a numeric vector.
slope(): Calculates the linear regression slope of a numeric vector.
Arguments
- x
A numeric vector of the response variable.
- t
An optional numeric vector of the predictor variable; time or sample number. Defaults to indices of
t = seq_along(x).- width
An integer defining the local window in number of samples around
idxin which to perform the operation., between[idx - floor(width/2), idx + floor(width/2)].- span
A numeric value defining the local window timespan around
idxin which to perform the operation. In units oftime_channelort, between[t - span/2, t + span/2].- align
Window alignment as "centre"/"center" (the default), "left", or "right". Where "left" is forward looking, and "right" is backward looking from the current sample.
- partial
A logical specifying whether to perform the operation over a subset of available data within the local rolling window (
TRUE), or requiring a complete window of valid samples (FALSE, by default). See Details.- verbose
A logical to display (the default) or silence (
FALSE) warnings and information messages used for troubleshooting.- ...
Additional arguments.
Value
rolling_slope() returns a numeric vector of rolling local slopes
in units of x/t the same length as x.
slope() returns a numeric slope in units of x/t.
Details
See details in peak_slope().
Additional args (...) accepts:
bypass_checksLogical; Speeds operation by bypassing validation checks. These checks should be performed upstream.
min_obsInteger; The minimum number of observations required to calculate
slope(). Defined by eitherwidthorspan, or equal to2whenpartial = TRUEinterceptLogical; When
TRUE,slope()will also return a numeric intercept value retrievable withattr(slope, "intercept").window_idxLogical; When
TRUE,rolling_slope()will also return a list of numeric window indices retrievable withattr(rolling_slope, "window_idx").