hierarchical | R Documentation |
Check a list of 'lm' objects to see whether they are be ordered in a way for doing hierarchical regression analysis.
hierarchical(...)
... |
The outputs of |
Two models can be compared by hierarchical regression analysis if one model can be formed by adding one or more terms to the other model.
This function checks whether a list
of lm
outputs can be ordered from
the simplest model to the most
complex model, with a more complex
model formed by adding one or more
terms to a simpler model.
It extracts the terms in each model
by stats::terms()
and then extracts
the labels of the terms by
labels()
. The labels are then used
to determine the hierarchical order.
Therefore, in principle, this
function can be used for the outputs
of other model fitting functions as
long as their outputs support the
stats::terms()
and the labels can
be used to determine hierarchical
order of two models.
If the models can be ordered in a
hierarchical way, the output is a
list of the original lm
outputs, sorted from the model with
the smallest number of terms to the
model with the largest number of
terms. If the models cannot be
ordered this way, NA
is returned.
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448
stats::lm()
dat <- data_test1
lm1 <- lm(y ~ x1 + x2, dat)
lm2 <- lm(y ~ x1 + x2 + x3 + x4, dat)
lm3 <- lm(y ~ x1 + cat1 + cat2 + x2 + x3 + x4, dat)
lm4 <- lm(y ~ x1 + x2*x3 + x4, dat)
# The order of entry does not matter
hierarchical(lm1, lm4, lm2)
# The following three models yield NA
hierarchical(lm3, lm4, lm2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.