Description Usage Arguments Details Value Methods (by generic) Author(s) Examples
Fits a moving quadratic (or simple linear) regression model over a series using a 2-sided window.
1 2 3 4 5 6 |
y |
A numeric vector |
x1 |
The predictor of the regression model, whose length must be odd, and it must be monotonic (increasing or decreasing). Typically this would be an evenly spaced, increasing vector. |
min.window |
The minimum number of non-missing data points in a window that are required to fit the regression model. |
start |
The index of the center of the first window |
skip |
The number of indexes to advance the center of the moving window each time the model is fit. |
linear.only |
|
object |
An object of class |
stats |
A character vector of summary statistics that are valid for
|
... |
Additional (unused) arguments required for consistency of S3 methods |
This function dynamically accounts for the incomplete windows
which are caused by missing values and which occur at the beginning and end
of the series.
A quadratic regression model is used if linear.only = FALSE
:
y = a + b*x1 + c*x1^2 + e
and a simple linear regression model is used if linear.only = TRUE
:
y = a + b*x1 + e
where a
, b
, and c
are regression coefficients, and e
represents the residual error. The regression model is fit repeatedly over a two-sided
moving window across the values of y
. The middle element of x1
is aligned with
an element of y
and then the regression model coefficients are calculated for that element
of y
.
Consequently, the size of the moving window is determined by
the the number of elements in x1
. For example, if x1 = -3:3
, the size
of the moving window is 7.
For the quadratic model, fitQ
rapidly calculates the least squares estimates by centering the
predictors so that they are orthogonal (or nearly orthogonal, if data in
the window are missing). Then the orthogonal coefficients are
'backtransformed' to the original, non-orthogonal parameterization.
Centering and orthogonality are not required to quickly fit the simple
linear regression model.
The handling of the moving windows and missing values in this function is
very similar to Smisc::smartFilter
.
Instead of a numeric vector, the x1
argument can be a
valid_fitQ_args
object (returned by check_fitQ_args
), in which
case all the subsequent arguments to fitQ
are ignored
(because the valid_fitQ_args
object contains all those arguments). This is useful
because fitQ
is called repeatedly by getFeatures
over the same set of
argument values.
An object of class fitQ
, which is list with
the 4 vectors that contain the results of the
quadratic model fits:
a |
The estimated intercepts |
b |
The estimated linear coefficients |
c |
The estimated quadratic coefficients. These are |
d |
The root mean squared error (RMSE) |
The first element of the vectors a
, b
, c
, and d
contains the model
coefficients corresponding to the first data point in y
. The second element in
the vectors a
, b
, c
, and d
contains the model
coefficients corresponding to the second data point in y
, etc.
summary
: Calculates summary statistics for a fitQ
object, returning a
named vector with summary statistics. The names take the form [coefficient].[stat],
where the coefficient is one of "a", "b", "c", or "d", and the stat is the statistic
required in the stats
argument of the summary
method.
Landon Sego
1 2 3 4 5 6 7 |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.