View source: R/modeling_phrases.R
compare_models.lm | R Documentation |
Tests whether a reduced (nested) model is sufficient for explaining the variability in the response compared to a more complex model.
## S3 method for class 'lm'
compare_models(
full.mean.model,
reduced.mean.model,
alternative = c("ne", "not equal", "!=", "lt", "less than", "<", "gt", "greater than",
">", "at least one differs"),
simulation.replications = 4999,
assume.constant.variance = TRUE,
assume.normality = FALSE,
construct = c("normal-2", "normal-1", "two-point mass"),
...
)
## S3 method for class 'glm'
compare_models(
full.mean.model,
reduced.mean.model,
alternative = c("ne", "not equal", "!=", "lt", "less than", "<", "gt", "greater than",
">", "at least one differs"),
simulation.replications = 4999,
method = c("classical", "parametric"),
...
)
compare_models(
full.mean.model,
reduced.mean.model,
alternative = c("ne", "not equal", "!=", "lt", "less than", "<", "gt", "greater than",
">", "at least one differs"),
simulation.replications = 4999,
...
)
full.mean.model |
|
reduced.mean.model |
model object of the same type as
|
alternative |
characterizes the form of the alternative hypothesis; one
of |
simulation.replications |
scalar indicating the number of samples to draw from the model for the null distribution (default = 4999). This will either be the number of bootstrap relications or the number of samples from the classical null distribution. |
assume.constant.variance |
boolean; if |
assume.normality |
boolean; if |
construct |
string defining the type of construct to use when generating
from the distribution for the wild bootstrap (see |
... |
additional arguments to be passed to other methods. |
method |
string defining the methodology to employ. If
|
This wrapper provides a single interface for commparing models under various
conditions imposed on the model. Similar to anova
.
Howevever, the p-value provided can be computed using classical methods or
bootstrapping.
For linear models, the following approaches are implemented:
classical: if both homoskedasticity and normality are assumed, the sampling distributions of a standardized statistic is modeled by an F-distribution.
parametric bootstrap: if normality can be assumed but homoskedasticity cannot, a parametric bootstrap can be peformed in which the variance for each observation is estimated by the square of the corresponding residual (similar to a White's correction).
residual bootstrap: if homoskedasticity can be assumed, but normality cannot, a residual bootstrap is used to compute the p-value.
wild bootstrap: if neither homoskedasticity nor normality is assumed, a wild bootstrap is used to compute the p-value.
All methods make additional requirements regarding independence of the error terms and that the model has been correctly specified.
For generalized linear models, the following approaches are implemented:
classical: if the distributional family is assumed correct, large sample theory is used to justify modeling the sampling distribution of a standardized statistic using a chi-squared distribution.
parametric bootstrap: the distributional family is assumed and a parametric bootstrap is performed to compute the p-value.
All methods require observations to be independent of one another.
data.frame containing an ANOVA table comparing the two models. The
data.frame has a single attribute "Null Distribution" which is a numeric
vector of length simulation.replications
which
contains a sample from the model of the null distribution of the test
statistic. This is useful for plotting the null distribution.
compare_models(lm)
: Computes p-value comparing nested linear models.
compare_models(glm)
: Computes p-value comparing nested generalized
linear models.
anova
fit1 <- lm(mpg ~ 1 + hp, data = mtcars)
fit0 <- lm(mpg ~ 1, data = mtcars)
# p-value computed via residual bootstrap
compare_models(fit1, fit0,
assume.constant.variance = TRUE,
assume.normality = FALSE)
# classical inference
compare_models(fit1, fit0,
assume.constant.variance = TRUE,
assume.normality = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.