Description Usage Arguments Details Value Methods (by class) See Also Examples
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.
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 | 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
)
|
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. |
Every implementation MUST support specification of the alternative hypothesis (alternative argument) and null hypothesis (H0 argument).
A single numeric value (vector of length 1) equal to the one-sided (for alternative="less" or "greater") or two-sided P-value
glm
: It supports Wald (method="Wald"),
Generalized Likelihood Ratio Tests (method="LRT") and Rao's score tests (method="Rao").
It works for stats::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, including lm
, 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
and df_for_wald
.
If the implementations of coef
, vcov
and df.residual
are consistent,
you do not have to implement fixcoef
, vcov_fixcoef
and df_for_wald
.
Other Wald-related functions:
df_for_wald()
,
fixcoef()
,
vcov_fixcoef()
Other Contrast functions:
confint_contrast()
,
estimate_confint_contrast()
,
estimate_contrast()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.