contrast | R Documentation |
This is a function allows one to obtain standard inferences (i.e., point estimates, standard errors, confidence intervals, etc.) concerning one or more contrasts expressed in terms of (differences among) linear combinations of the parameters. It is similar to functions of the same name in the contrast and rms packages.
## S3 method for class 'lm'
contrast(model, a, b, u, v, df, tf, cnames, level = 0.95, fcov = vcov, delta = FALSE, adjust = FALSE, ...)
## S3 method for class 'glm'
contrast(model, a, b, u, v, df, tf, cnames, level = 0.95, fcov = vcov, delta = FALSE, adjust = FALSE, ...)
## S3 method for class 'lmerMod'
contrast(model, a, b, u, v, df, tf, cnames, level = 0.95, fcov = vcov, delta = FALSE, adjust = FALSE, ...)
## S3 method for class 'glmerMod'
contrast(model, a, b, u, v, df, tf, cnames, level = 0.95, fcov = vcov, delta = FALSE, adjust = FALSE, ...)
## S3 method for class 'gls'
contrast(model, a, b, u, v, df, tf, cnames, level = 0.95, fcov = vcov, delta = FALSE, adjust = FALSE, ...)
model |
Model object. |
... |
Not used. |
a |
List or data frame defining a linear combination. |
b |
List or data frame defining a linear combination. |
u |
List or data frame defining a linear combination. |
v |
List or data frame defining a linear combination. |
df |
Optional manual specification of the degrees of freedom. This defaults to the residual degrees of freedom for linear and generalized linear models, except when |
tf |
Optional transformation function to apply to the estimates. If |
cnames |
Labels for the contrasts. Default is none. |
level |
Confidence level in (0,1). Default is 95% |
fcov |
Function for estimating the variance-covariance matrix of the model parameters. Default is what is returned by the function |
delta |
Logical for if the delta method should be used with a transformation function (if provided). Default is |
adjust |
Option to adjust confidence intervals for a simultaneous confidence level and p-values for a family-wise Type I error rate using the multivariate t or normal distribution. Note that minor variation in these adjustments can happen due to Monte Carlo error in the algorithm used to compute the quantiles and probabilities. Default is |
Assuming a (generalized) linear (mixed) model of the for g[E(Y_i)] = \eta_i
where \eta_i = \beta_0 + \beta_1 x_{i1} + \beta_2 x_{i2} + \dots + \beta_p x_{ip}
, many contrasts or linear combinations of the parameters can be written in the form \eta_a - \eta_b - (\eta_u - \eta_v)
where the subscripts represent specified values of x_{i1}, x_{i2}, \dots, x_{ip}
. The arguments a, b, u, and v correspond to these specified values, where a value of zero is assumed by default if one or more of these are not specified. Note that for (generalized) linear mixed model, the expectation is computed conditional on setting all random effects equal to zero.
m <- lm(Gas ~ Temp * Insul, data = MASS::whiteside)
# estimate expected gas consumption at zero degrees
# before and after insulation was added
contrast(m, a = list(Temp = 0, Insul = c("Before","After")),
cnames = c("Before at 0","After at 0"))
# estimate slopes of regression of gas consultion on
# before and after insulation was added
contrast(m,
a = list(Temp = 1, Insul = c("Before","After")),
b = list(Temp = 0, Insul = c("Before","After")),
cnames = c("Slope Before","Slope After"))
# estimate difference in expected gas consumption between
# before and after insulation at different temperatures
contrast(m,
a = list(Temp = c(0,5,10), Insul = "Before"),
b = list(Temp = c(0,5,10), Insul = "After"),
cnames = c("at 5","at 5","at 10"))
m <- glm(cbind(deaths,total-deaths) ~ insecticide * log2(deposit),
family = binomial, data = insecticide)
# estimate odds ratios for the effect of doubling the
# deposit for each insecticide
types <- levels(insecticide$insecticide)
contrast(m,
a = list(insecticide = types, deposit = 2),
b = list(insecticide = types, deposit = 1),
cnames = types, tf = exp)
# odds ratios to compare insecticides at a deposit of 5
contrast(m,
a = list(insecticide = "both", deposit = 5),
b = list(insecticide = c("DDT","g-BHC"), deposit = 5),
cnames = c("both vs DDT","both vs g-BHC"), tf = exp)
# estimate response probabilities for each insecticide
# at a deposit level of 5
contrast(m, a = list(insecticide = types, deposit = 5),
cnames = types, tf = plogis)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.