test_highest {lmhelprs} | R Documentation |
Test the Highest Order Term by ANOVA
Description
Identify the highest order terms in a model fitted by 'lm()', and compare this model to a model with this term removed using ANOVA.
Usage
test_highest(lm_out)
highest_order(lm_out)
Arguments
lm_out |
The output of
|
Details
The function test_highest()
first check if a model fitted by
stats::lm()
has a unique highest
order term (e.g., the term x1:x2
,
in the model y ~ x1 + x2 + x1:x2
).
If yes, it will fit a model with this
term removed, and then call
hierarchical_lm()
to compare the
original model with this reduced
model.
If the model does not have a unique highest order term, an error will be raised.
Value
A hierarchical_lm
-class
object, which is the output of
hierarchical_lm()
. Two models
are compared, the original model and
the model with the unique highest
order term removed.
Functions
-
test_highest()
: Test the highest order term. -
highest_order()
: Find the highest order term.
Limitation
It relies on terms created by
stats::lm()
to determine the order
of each term. If a higher order term
is created manually (e.g.,
I(x1 * x2)
), then it cannot know
that this term is a second order
term.
Author(s)
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448
See Also
Examples
dat <- data_test1
lm1 <- lm(y ~ x1 + x2 + cat1*x3, dat)
lm2 <- lm(y ~ x1 + x2*x3 + x4, dat)
test_highest(lm1)
test_highest(lm2)
highest_order(lm1)
highest_order(lm2)
# The followings will yield an error
lm3 <- lm(y ~ x1 + x2 + x3, dat)
summary(lm3)
tryCatch(test_highest(lm3), error = function(e) e)
tryCatch(highest_order(lm3), error = function(e) e)
lm4 <- lm(y ~ x1 + x2*x3 + x4*x5, dat)
summary(lm4)
tryCatch(test_highest(lm4), error = function(e) e)
tryCatch(highest_order(lm4), error = function(e) e)