| predictmeans | R Documentation |
Predicted means, their standard errors (SE), standard errors of differences (SED) and least significant
differences (LSD) for aov, lm, glm, gls, lme, lmer, glmer,
glmmTMB, gam and semireg fits, with pairwise comparisons and permutation tests. Plots are
drawn from the result with link{autoplot.predictmeans}; link{advice} reads the notes made for
this fit and data.
predictmeans(model, modelterm, data=NULL, pairwise=NULL, atvar=NULL, adj="none",
conf_level=0.95, covariate=NULL, meandecr=NULL, letter_ci=FALSE, trans = I,
permlist=NULL,
ncore=1, cov_reduce=mean, exclude=NULL, vcov_adjust=TRUE,
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=NULL,
equivalence=NULL, bias_adjust=FALSE, sigma=NULL, average=c("link", "response"),
mean_type=c("conditional", "overall"), ...)
model |
Model object returned by |
modelterm |
Name (in "quotes") for indicating which factor term's predicted mean to be calculated:
factors of the model joined by ":", e.g. "A" or "A:B". A combination of factors that is not a term of the
model can be asked for too (e.g. "A:B" for |
data |
The data used to fit the model; needed in some cases, e.g. when a variable is transformed in the model formula. |
pairwise |
What is printed: |
atvar |
Factor(s) of |
adj |
Name (in "quote") for indicating a method for adjusting p-values of pairwise comparisons.
The choices are "none", "tukey", "holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "sidak", "scheffe"
and "mvt". "sidak", "scheffe" (rank of the family: number of means - 1) and "mvt" (single-step multivariate t, the exact
counterpart of SAS |
conf_level |
The confidence level of the confidence limits; the tests, LSDs and letters are at the
significance level |
covariate |
The values of covariates at which the means are predicted: a named list or vector, e.g.
|
meandecr |
Logical: order the letters of |
letter_ci |
A logical variable to indicate printed letters for multiple comparisons by whether or not the
comparison intervals of the means overlap (the default is FALSE). The comparison intervals are mean
|
trans |
A function object for calculating the back transformed means, e.g. |
... |
Not used: arguments removed in 2.0 (e.g. |
permlist |
A list from |
ncore |
Number of cores for parallel computing when |
cov_reduce |
How covariates that are not varied are handled when building the predicted means: a function such as
|
exclude |
For |
vcov_adjust |
For models fitted by REML ( |
weights |
Passed to |
df_method |
Denominator degrees of freedom, by method or as one number (a fixed df, |
vcov |
Optional covariance of the coefficients to use instead of the model's. For |
equivalence |
Optional equivalence margins for equivalence tests (two one-sided t tests, TOST) of the
differences: a positive number |
bias_adjust |
Adjust the back-transformed means (non-identity link or |
sigma |
With |
average |
How means average over the other factors when they are back-transformed: |
mean_type |
Only for |
Predicted Means |
A table of predicted means. |
Standard Error of Means |
A table of standard errors of predicted means. |
Standard Error of Differences |
Standard errors of differences between predicted means. |
LSD |
Least significant differences between predicted means (maximum, minimum and average), with the
critical value that goes with |
Pairwise p-value |
Only when the pairs are displayed (see |
mean_table |
The means with SE, df and confidence limits (and letters when pairs are compared); for back-transformed means also the response-scale means and limits. |
p_valueMatrix |
Only when the pairs are displayed: the p-value matrix of the letters. |
means |
A data frame with one row per predicted mean and fixed column names: the factor (and covariate)
columns, |
pairs |
A data frame with one row per pairwise comparison ( |
settings |
A list with the options used: model term, significance level, adjustment method, |
The result has class c("predictmeans", "pdmlist"). Printing shows the legacy tables;
the means, pairs and settings elements are not printed. Plots come from
autoplot(); notes for this fit are in attr(, "advice"), read with advice.
A covariate that takes one value within each level of a factor (a site mean, a block-level measurement) is
aliased with that factor: in lm(ht ~ site + sitemean * seedlot) the coefficient of sitemean is
NA. A mean over sites is then estimable only if each site keeps its own value of the covariate; at a single
value, such as the overall mean, the "means" depend on the coding of the factors (which level is the
reference) and are not estimates. predictmeans finds such covariates and uses each level's own value, with a
message. predictmeans 1.x, and Genstat PREDICT after the covariate is dropped as aliased, used the
overall mean; SAS LSMEANS reports such means as non-estimable. For a seedlot measured at every site the
equal-weight mean is then its raw mean; for one with missing sites, weights = "equal" extrapolates its
regression line to the missing sites and weights = "cells" averages over the sites it was measured at.
See DataExam5.2.
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.
predictmeans(mean_type = "overall") gives the overall means and their ratios.
The predictmeans function becomes confused if a factor or covariate is changed to the other
in a model formula. Consequently, formulae that include calls as.factor, factor, or numeric
(e.g. as.factor(income)) will cause errors. Instead, create the modified variables outside of the model
formula (e.g., fincome <- as.factor(income)) and then use them in the model formula.
Factors cannot have colons in level names (e.g., "level:A") for the legacy tables; the predictmeans
function will confuse the colons with interactions; rename levels to avoid colons. The means and
pairs tables are not affected.
For predictmeans function, it is assumed that methods coef, vcov, model.matrix, model.frame and terms are available for model.
Dongwen Luo, Siva Ganesh and John Koolaard
Torsten Hothorn, Frank Bretz and Peter Westfall (2008), Simultaneous Inference in General Parametric Models. Biometrical, Journal 50(3), 346–363.
Gilmour, A. R., Thompson, R. and Cullis, B. R. (1995), Average information REML: an efficient algorithm for variance parameter estimation in linear mixed models, Biometrics, 51(4), 1440-1450.
Welham, S., Cullis, B., Gogel, B., Gilmour, A., & Thompson, R. (2004), Prediction in linear mixed models, Australian and New Zealand Journal of Statistics, 46(3), 325-347.
Vanessa, C. (05 October 2022), Confidence tricks: the 83.4% confidence interval for comparing means, https://vsni.co.uk/blogs/confidence_trick.
Maghsoodloo, S. and Huang, C.-Y. (2010), Comparing the overlapping of two independent confidence intervals with a single confidence interval for two normal population parameters, Journal of Statistical Planning and Inference, 140(11), 3295-3305.
Goldstein, H. and Healy, M. J. R. (1995), The graphical presentation of a collection of means, Journal of the Royal Statistical Society A, 158(1), 175-177.
Austin, P. C. and Hux, J. E. (2002), A brief note on overlapping confidence intervals, Journal of Vascular Surgery, 36(1), 194-195.
Afshartous, D. and Preston, R. A. (2010), Confidence intervals for dependent data: equating non-overlap with statistical significance, Computational Statistics and Data Analysis, 54(10), 2296-2305.
autoplot.predictmeans, tidy.predictmeans, advice,
pm_check, contrastmeans, pm_joint, covariatemeans
library(predictmeans)
Oats$nitro <- factor(Oats$nitro)
fm <- lmer(yield ~ nitro*Variety + (1|Block/Variety), data=Oats)
## The results as tables (columns described under Value)
pm <- predictmeans(fm, "nitro")
pm$means
pm$pairs
pm$settings
summary(pm)
## Means within each variety, Tukey-adjusted pairs; plots from the result
predictout <- predictmeans(fm, "nitro:Variety", atvar="Variety", adj="tukey")
names(predictout)
ggplot2::autoplot(predictout) # means, one LSD bar per variety
ggplot2::autoplot(predictout, type = "bar")
## lme fits work the same way
fl <- lme(yield ~ nitro*Variety, random=~1|Block/Variety, data=Oats)
predictmeans(fl, "nitro", adj="BH")$pairs
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.