rolling_slope(): Compute rolling linear regression slopes within a local
window along a numeric vector.
slope(): Calculate the linear regression slope of a numeric vector via
the least-squares formula.
Usage
rolling_slope(
x,
t = seq_along(x),
width = NULL,
span = NULL,
align = c("centre", "left", "right"),
partial = FALSE,
na.rm = FALSE,
verbose = TRUE,
...,
env = rlang::caller_env()
)
slope(x, t = seq_along(x), na.rm = FALSE, ..., env = rlang::caller_env())Arguments
- x
A numeric vector of the response variable.
- t
An optional numeric vector of the predictor variable (e.g. time). Default is
seq_along(x).- width
An integer defining the local window in number of samples around
idxin which to perform the operation, according toalign.- span
A numeric value defining the local window time span around
idxin which to perform the operation, according toalign. In units oftime_channelort.- 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
Logical; default is
FALSE, only returns values where a full window of valid (non-NA) samples are available. IfTRUE, ignoresNAand processes available valid samples (see Details).- na.rm
Logical; default is
FALSE, propagates anyNAs to the returned vector. IfTRUE, ignoresNAs and processes available valid samples within the local window. May return errors or warnings. (see Details).- verbose
Logical.
TRUE(default) will display, andFALSEwill silence warnings and information messages helpful for troubleshooting. Global default can be set viaoptions(mnirs.verbose = FALSE).- ...
Additional arguments.
- env
The calling environment or a defused call, used to report errors and warnings as coming from the user-facing function rather than the validator.
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 value in units of x / t, or
NA_real_ when insufficient valid observations are present.
Details
See peak_slope() for details on window specification (width, span,
align), partial windows, and direction detection.
Additional arguments (...) accepted:
bypass_checksLogical; if
TRUE, skips input validation. Intended for internal use when checks have already been performed upstream.min_obsInteger; minimum number of valid observations required per window to return a slope. Derived from
widthorspan, or2Lwhenpartial = TRUE.interceptLogical; if
TRUE,slope()also attaches the y-intercept asattr(slope_val, "intercept").window_idxLogical; if
TRUE, the window bounds fromcompute_window_bounds()are attached asattr(slopes, "bounds").