| covariatemeans | R Documentation |
Predicted means along a covariate for each level of a factor term (curves) with their confidence limits, or
the difference between two of the curves with its band. The result holds the tables in the layout of
predictmeans and the plot, which autoplot() returns.
covariatemeans(model, modelterm=NULL, covariate, as_is=FALSE, at=NULL, data=NULL,
conf_level=0.95, trans=NULL, cov_reduce=mean, exclude=NULL,
weights=c("equal", "proportional", "outer", "cells", "flat"),
df_method=c("auto", "Kenward-Roger", "Satterthwaite", "containment",
"between-within", "KR-expected", "KR-average", "inner-outer", "residual"),
vcov_adjust=TRUE, contr=NULL, contr_scale=c("model", "response"),
band=c("pointwise", "simultaneous"), bias_adjust=FALSE, sigma=NULL,
mean_type=c("conditional", "overall"), vcov=NULL,
plot=getOption("predictmeans.plot", FALSE), plot_args=list(), ...)
model |
A fitted model, as for |
modelterm |
Name (in "quotes") of the factor term whose lines are predicted, e.g. "A" or "A:B", given exactly as it appears in the printed model. |
covariate |
Name (in "quotes") of a covariate of |
as_is |
|
at |
The values of |
data |
The data used to fit the model; needed in some cases, e.g. when a variable is transformed in the model formula. |
conf_level |
The confidence level of the limits, the default is 0.95 ( |
trans |
A function object for calculating the back transformed means, e.g. |
plot_args |
Superseded by the arguments of |
... |
Not used: arguments removed in 2.0 ( |
cov_reduce |
How covariates that are not varied are handled when building the predicted means: a function such as
|
exclude |
For |
weights |
Passed to |
df_method, vcov_adjust |
As in |
vcov |
Optional covariance of the coefficients to use instead of the model's, as in |
contr |
Two levels of |
contr_scale |
With |
band |
With |
mean_type |
Only for |
plot |
Draw the plot now? The default is |
bias_adjust, sigma |
For back-transformed lines (a link, a transformed response or |
An object of class c("covariatemeans", "pm_curves"), a list. Its tables have the layout of
predictmeans (columns estimate, std.error, df, conf.low,
conf.high, ..., the covariate under its own name; see tidy.pm_curves); tidy() and
as.data.frame() return them, autoplot() the plot, and print() shows a summary.
means |
The curves: one row per level of |
pairs |
With |
settings |
The options that produced them (df method, level, band, back-transformation, ...). |
plt |
|
pred_df |
( |
test, significant |
With |
Whether the bands of two lines overlap does not say whether the lines differ: the lines are estimated from the same model and are correlated. The band of their difference does, and it is computed from the contrast of the two lines, not from their limits.
The scale of the test. The difference is tested on the scale of the model (the link, or the
transformed response): there the model is additive, the estimates are closest to normal and the standard
error does not depend on the mean. d = (K_a - K_b)\hat\beta, SE^2 = (K_a - K_b) V (K_a - K_b)',
limits d \pm c\,SE (columns diff, ses, Df, LL, UL). With a log
the difference back-transforms exactly to a ratio and with a logit to an odds ratio (columns ratio
or odds.ratio with their limits): the limits leave out 1 exactly when those of diff leave out
0, so nothing is approximated. For other transformations (square root, probit, a power) the
back-transformed difference has no meaning and the model scale is shown.
Why back-transform. Only to read the size of the difference in the units of the response; it is not
needed to decide whether the lines differ. The response-scale difference h(\eta_a) - h(\eta_b) is
another quantity: its standard error is an approximation (the delta method, gradient
h'(\eta_a) K_a - h'(\eta_b) K_b; columns response.diff, response.ses,
response.LL, response.UL), it depends on the values of the other variables of the model, and
lines that are parallel on the model scale are not parallel on the response scale. Its band can disagree
with the test near the boundary, so with contr_scale = "response" the covariate values where the
lines differ are still those of the model scale (marked along the axis). For a generalized linear mixed
model it is the difference for a typical cluster (random effects at zero), as the lines are.
Significance at a level. Three questions have three answers:
At one covariate value chosen beforehand: the pointwise band (band = "pointwise"); the lines
differ at the level 1 - conf_level when it leaves out zero (one for a ratio).
Over which range of the covariate: looking at many values needs wider limits. band =
"simultaneous" uses Scheffe's critical value c = \sqrt{r F_{1-\alpha;\,r,\,df}}, r the rank
of the contrasts along the covariate (2 for straight lines: the Working-Hotelling band). It holds for
every covariate value at once and is slightly conservative over a limited range.
Whether the lines differ anywhere: the joint F test that all the differences along the covariate
are zero (test in the result).
Each set of limits in pred_df has a column that says whether it includes the value of no difference:
includes0 for diff, ratio.includes1 or odds.ratio.includes1 (always equal to
includes0) and response.includes0 for the response-scale difference (which can differ from
includes0 near the boundary). Column significant (!includes0) and significant in
the result (the ranges of the covariate) follow the band asked for, on the model scale.
For a glmmTMB fit with zero inflation (ziformula) the means are those of the conditional (count)
part, \mu, as emmeans and predict(type = "conditional") give, not the overall mean
(1 - \pi)\mu (\pi the probability of an extra zero); ratios are of these means, and equal the
ratios of overall means only when \pi is the same. A message says so and settings$component is
"conditional". The two can order treatments differently when \pi differs between them.
mean_type = "overall" (predictmeans(), covariatemeans(), semipred()) gives the overall
means and their ratios.
For brmsfit and stanreg fits (see pm_draws) each point of a curve, and with
contr each difference, is summarised from the posterior draws: posterior median, posterior SD and
equal-tailed pointwise interval (with band = "simultaneous" the Besag et al. (1995) band over the covariate
values), and the probability of direction of the differences; the back-transformation is applied to each draw.
There is no test of equal curves (no F test), and df_method, vcov_adjust and mean_type do not
apply; the draws are in attr(, "draws").
Dongwen Luo, Siva Ganesh and John Koolaard
autoplot.pm_curves, tidy.pm_curves, advice, pm_slopes, predictmeans
library(predictmeans)
data(Oats, package="nlme")
fm <- lme(yield ~ nitro*Variety, random=~1|Block/Variety, data=Oats)
cm <- covariatemeans(fm, "Variety", covariate="nitro")
ggplot2::autoplot(cm)
ggplot2::autoplot(cm, panel = character(0), data = FALSE) # one panel, no data
covariatemeans(fm, "Variety", covariate="nitro", at=seq(0, 0.6, 0.3))
# the difference between two varieties along nitro, with a simultaneous band
# (the two levels by name, or by number: contr=c(1, 3))
cd <- covariatemeans(fm, "Variety", covariate="nitro", contr=c("Golden Rain", "Victory"),
band="simultaneous")
cd$settings$test
head(as.data.frame(cd))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.