p_value_contrast {glmglrt} | R Documentation |
Hypothesis tests on contrasts
Description
This S3 generic function allows the computation of P-values associated to
hypothesis tests of contrasts (i.e. linear combinations) of fixed-effects in a model.
The default implementation computes Wald's P-values with any model as long as it consistently implements fixcoef
, vcov_fixcoef
and df_for_wald
.
It is also specialized for GLMs and negative binomial models (see MASS::glm.nb
) with Wald's, LRT and Rao's P-values and may be specialized with other models.
Usage
p_value_contrast(
model,
contrast,
alternative = c("two.sided", "less", "greater"),
H0 = 0,
method = NULL,
...
)
## S3 method for class 'glm'
p_value_contrast(
model,
contrast,
alternative = c("two.sided", "less", "greater"),
H0 = 0,
method = c("LRT", "Rao", "Chisq", "F", "Wald", "wald"),
...,
debuglevel = 1,
force = FALSE
)
## Default S3 method:
p_value_contrast(
model,
contrast,
alternative = c("two.sided", "less", "greater"),
H0 = 0,
method = "Wald",
...,
debuglevel = 0,
force = FALSE
)
Arguments
model |
a fitted statistical model such as a glm or a coxph. |
contrast |
numeric vector of the same length as the number of coefficients in the model; it describes the contrast |
alternative |
a character string specifying the alternative hypothesis, must be one of "two.sided" (default), "greater" or "less". You can specify just the initial letter. |
H0 |
numeric value; the value of the contrast under the null hypothesis. |
method |
character string value; specification of the algorithm used (implementation dependent). Suggested values are "Wald", "LRT", "Rao" and "exact" for, respectively, Wald's asymptotic normality and/or student test, the Generalized Likelihood Ratio Test, Rao's score test and non-asymptotic exact tests. Other values may be allowed. |
... |
Additional parameters that may be used by some implementations. |
debuglevel |
integer value; set to 0 (default) to disable warnings, 1 to enable warnings and 2 to enable warnings and notes. |
force |
logical; if TRUE, force computation of P-values in case of convergence problems. |
Details
Every implementation MUST support specification of the alternative hypothesis (alternative argument) and null hypothesis (H0 argument).
Value
A single numeric value (vector of length 1) equal to the one-sided (for alternative="less" or "greater") or two-sided P-value
Methods (by class)
-
glm
: It supports Wald (method="Wald"), Generalized Likelihood Ratio Tests (method="LRT") and Rao's score tests (method="Rao"). It works forstats::glm
models and negative binomial models (MASS::glm.nb
) with method="LRT" and method="Wald". -
default
: Supports Wald's test on a wide range of models, includinglm
,mlm
,stats::glm
,negbin
,MASS::polr
,MASS::rlm
(with normality assumptions, defeating the purpose of rlm),nlme::lme
,nlme::gls
,lme4::lmer
,lme4::glmer
,mgcv::gam
,gam::gam
,survival::coxph
,survival::survreg
,nnet::multinom
,stats::nls
.It can be easily extended by implementing three generic functions:
fixcoef
,vcov_fixcoef
anddf_for_wald
. If the implementations ofcoef
,vcov
anddf.residual
are consistent, you do not have to implementfixcoef
,vcov_fixcoef
anddf_for_wald
.
See Also
Other Wald-related functions:
df_for_wald()
,
fixcoef()
,
vcov_fixcoef()
Other Contrast functions:
confint_contrast()
,
estimate_confint_contrast()
,
estimate_contrast()
Examples
data(mtcars)
model1 = glm(family="gaussian", data=mtcars, hp ~ 0+factor(gear))
# do cars with 5 gears have more horse power (hp) than cars with 4 gears ?
p_value_contrast(model1, c(0,-1,1), alternative="greater")
# now, we fit an equivalent model (same distribution and same predictions)
model2 = glm(family=gaussian(log), data=mtcars, hp ~ 0+factor(gear))
# do cars with 5 gears have at least twice the horse power than cars with 4 gears ?
# the following two tests are equivalent
p_value_contrast(model1, c(0,-1,0.5), alternative="greater", method="LRT", H0=0)
p_value_contrast(model2, c(0,-1,1), alternative="greater", method="LRT", H0=log(2))
# the following two tests are close but not equivalent
p_value_contrast(model1, c(0,-1,0.5), alternative="greater", method="Wald", H0=0)
p_value_contrast(model2, c(0,-1,1), alternative="greater", method="Wald", H0=log(2))