blus | R Documentation |
This function computes the Best Linear Unbiased Scalar-Covariance (BLUS) residuals from a linear model, as defined in \insertCiteTheil65;textualskedastic and explained further in \insertCiteTheil68;textualskedastic.
blus(
mainlm,
omit = c("first", "last", "random"),
keepNA = TRUE,
exhaust = NA,
seed = 1234
)
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
|
Under the ideal linear model conditions, the BLUS residuals have a
scalar covariance matrix \omega I
(meaning they have a constant
variance and are mutually uncorrelated), unlike the OLS residuals, which
have covariance matrix \omega M
where M
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 n
observations and an n\times p
design
matrix yields only n-p
BLUS residuals. The choice of which p
observations will not be represented in the BLUS residuals is specified
within the algorithm.
A double vector of length n
containing the BLUS residuals
(with NA_real_
) for omitted observations), or a double vector
of length n-p
containing the BLUS residuals only (if keepNA
is set to FALSE
)
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.
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.