Description Usage Arguments Details Value Author(s) Examples
View source: R/orthogonalize.R
Provides functionality to create residual scores for a single outcome or a set
of outcomes via ordinary least squares (OLS) regression more quickly
and conveniently than lm
. The 'response' vector produced by this
function is "orthogonal" to the variables the predictor set.
1 2 |
formula |
a |
data |
a |
intercept |
a |
group |
an optional |
simplify |
a |
This function is based on symbolic model
representation via a formula object, just like lm
. The
formula accepts a single 'response' separated by a "~"
from a set of 'terms', which are
themselves separated by a +
. The formula is evaluated and the
relevant data are provided to an OLS estimator where the 'response'
is regressed on the 'terms'. The residuals of the 'response' are
retained and returned by the function.
If group
is provided, the OLS estimator computes the 'response'
as a set of within-group residuals.
When "formula"
is specified as a "list"
, the user
can either supply a single value to the arguments "intercept"
and "group"
or a vector of the same length as the "list"
for a more modular approach to computing residuals.
a numeric matrix of the same number of rows as the provided
data
and the same number of columns as the provided.
If "simplify"
is set to TRUE, a numeric vector will
be returned.
Pavel Panko
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | ## Load the data:
data(iris)
## Orthogonalize "Petal.Width" and add the intercept:
Petal.Width.Prime <- orthogonalize(
formula = Petal.Width ~ Petal.Length + Sepal.Length,
data = iris,
intercept = TRUE
)
## Orthgonalize "Petal.Width" within "Species:
Petal.Width.Prime <- orthogonalize(
formula = Petal.Width ~ .,
data = iris,
group = "Species"
)
## Orthgonalize the "Width" variables, one within-group, one not:
Width.Prime <- orthogonalize(
formula = list(
Petal.Width ~ .,
Sepal.Width ~ .
),
data = iris,
group = c("Species", "")
)
## Orthgonalize the "Width" variables, adding the intercept to one
## but not the other:
Width.Prime <- orthogonalize(
formula = list(
Petal.Width ~ .,
Sepal.Width ~ .
),
data = iris,
intercept = c(TRUE, FALSE)
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.