p_value_contrast: Hypothesis tests on contrasts

Description Usage Arguments Details Value Methods (by class) See Also Examples

View source: R/main.R

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

 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
)

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 sum(contrast*fixcoef(model)).

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)

See Also

Other Wald-related functions: df_for_wald(), fixcoef(), vcov_fixcoef()

Other Contrast functions: confint_contrast(), estimate_confint_contrast(), estimate_contrast()

Examples

 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))

glmglrt documentation built on Aug. 7, 2020, 9:10 a.m.