blus {skedastic} | R Documentation |
Compute Best Linear Unbiased Scalar-Covariance (BLUS) residuals from a linear model
Description
This function computes the Best Linear Unbiased Scalar-Covariance (BLUS) residuals from a linear model, as defined in Theil (1965) and explained further in Theil (1968).
Usage
blus(
mainlm,
omit = c("first", "last", "random"),
keepNA = TRUE,
exhaust = NA,
seed = 1234
)
Arguments
mainlm |
Either an object of |
omit |
A numeric vector of length |
keepNA |
A logical. Should BLUS residuals for omitted observations be
returned as |
exhaust |
An integer. If singular matrices are encountered
using the passed value of |
seed |
An integer specifying a seed to pass to
|
Details
Under the ideal linear model conditions, the BLUS residuals have a
scalar covariance matrix (meaning they have a constant
variance and are mutually uncorrelated), unlike the OLS residuals, which
have covariance matrix
where
is a function of
the design matrix. Use of BLUS residuals could improve the performance of
tests for heteroskedasticity and/or autocorrelation in the linear model.
A linear model with
observations and an
design
matrix yields only
BLUS residuals. The choice of which
observations will not be represented in the BLUS residuals is specified
within the algorithm.
Value
A double vector of length containing the BLUS residuals
(with
NA_real_
) for omitted observations), or a double vector
of length containing the BLUS residuals only (if
keepNA
is set to FALSE
)
References
Theil H (1965).
“The Analysis of Disturbances in Regression Analysis.”
Journal of the American Statistical Association, 60(312), 1067–1079.
Theil H (1968).
“A Simplification of the BLUS Procedure for Analyzing Regression Disturbances.”
Journal of the American Statistical Association, 63(321), 242–251.
See Also
H. D. Vinod's online article, Theil's BLUS Residuals and R Tools for Testing and Removing Autocorrelation and Heteroscedasticity, for an alternative function for computing BLUS residuals.
Examples
mtcars_lm <- lm(mpg ~ wt + qsec + am, data = mtcars)
blus(mtcars_lm)
plot(mtcars_lm$residuals, blus(mtcars_lm))
# Same as first example
mtcars_list <- list("y" = mtcars$mpg, "X" = cbind(1, mtcars$wt, mtcars$qsec, mtcars$am))
blus(mtcars_list)
# Again same as first example
mtcars_list2 <- list("e" = mtcars_lm$residuals, "X" = cbind(1, mtcars$wt, mtcars$qsec, mtcars$am))
blus(mtcars_list2)
# BLUS residuals cannot be computed with `omit = "last"` in this example, so
# omitted indices are randomised:
blus(mtcars_lm, omit = "last")