This function obtains predicted means, SE of means, SED of means, LSDs and plots of means
with SE bar or LSD bar for parametric models such as aov
, lm
,
glm
, gls
, lme
, and lmer
. The function also perfomrs pairwise comparisons
and permutation tests.
predictmeans(model, modelterm, data=NULL, pairwise=FALSE, atvar=NULL, adj="none", Df=NULL,
lsd_bar=TRUE, level=NULL, covariate=NULL, meandecr=NULL, letterCI=FALSE, trans = I,
transOff = 0, responsen=NULL, count=FALSE, plotord=NULL, plottitle=NULL, plotxlab=NULL,
plotylab=NULL, mplot=TRUE, barplot=FALSE, pplot=TRUE, bkplot=TRUE, plot=TRUE,
jitterv=0.2, basesz=12, prtnum=TRUE, prtplt=TRUE, newwd=TRUE, permlist=NULL, ncore=3,
ndecimal=4)
A table of predicted means.
A table of standard errors of predicted means.
Standard errors of differences between predicted means.
Least significant differences between predicted means.
A matrix with t-values above the diagonal and p-values below the diagonal, or
matrix of pairwise comparison p-values for each level of atvar
.
A summary of predicted means result including 'Predicted means', 'Standard error', 'Df'
and 'CIs'. When trans!=NULL
or trans!=I
, a table of back transformed means with CIs are also shown.
ggplot of predicted means.
ggplot of back transformed means.
gg bar plot of predicted means.
p_value matrix for pairwise comparison.
Model object returned by aov
, lm
, glm
, gls
, lme
, and lmer
.
Name (in "quotes") for indicating which factor term's predicted mean to be calculated.
The modelterm
must be factors and given exactly as it appears in the printed model, e.g. "A" or "A:B".
In some cases, you need to provide the data set used in model fitting, especially when you have applied some variable trnasformation in the model.
An option for showing pair-wise LSDs and p-values, or not. The default is FALSE.
When pairwise = TRUE
, a quoted name indicating within levels of which variable in
modelterm
the multiple comparison will be performed.
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" and "fdr". The default method is "none". Note that LSD can't be adjusted except for "bonferroni" method.
A degree of freedom for calculating LSD. For the above models, Df is obtained from the function automatically.
A logical variable to indicate to print an average LSD or SED bar on the means plot. The default is TRUE.
A significant level for calculating LSD, CI etc. The default value is 0.05.
A numerical vector to specify values of covariates for calculating predicted means. The default values are the means of the associated covariates.
A logical variable to indicate whether to print letters for multiple comparisons by decreasing order of means in the mean_table. The default is NULL which indicates the mean order follows the associated factor levels.
A logical variable to indicate printed letters for multiple comparisons by whether or not CI overlap in the mean_table. The default is FALSE.
A function object for calculating the back transformed means, e.g. trans=exp
.
When you use trans=exp(x+1)
, then transOff=1
, the default is 0.
Name (in "quotes") of the back transformed response variable in the model
.
An option for indicating the back transformed mean values are counts or not. The default is FALSE.
A numeric vector specifying the order of plotting for two or three way interaction (e.g.
plotord = c(2, 1, 3)
will put the second variable in modelterm
on the X
axis, the first variable as the grouping variable, and the third one as the panel variable).
The defaults are c(1, 2)
and c(1, 2, 3)
for two and three way interactions.
A character vector specifying the main title for plot(s). The default is NULL.
A character vector specifying the x label for plot(s). The default is NULL.
A character vector specifying the y label for plot(s). The default is NULL.
An option for drawing a means plot, or not. The default is TRUE.
An option for drawing a bar chart, or not. The default is FALSE.
An option for drawing a p-values plot, or not when there are more than six p-values. The default is TRUE.
An option for drawing back transformed plot, or not. The default is TRUE.
An option for drawing plots, or not. The default is TRUE.
A degree of jitter in x and y direction in the back transformed means graph. The default is zero.
The base font size. The default is 12.
An option for printing covariate information on the screen, or not. The default is TRUE.
An option for printing plots on the screen, or not. The default is TRUE.
A logical variable to indicate whether to print graph in a new window. The default is TRUE.
A model parameter list produced by the function permmodels
. When permlist != NULL
,
the option Df
will be non-functional. This is a key option for pairwise comparisons via
permutation tests.
Number of core for parallel computing when permlist != NULL
, the default value is 3.
An option for specifying number of decimal point to be print at predicted means table. The default is 4.
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.
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.
library(predictmeans)
ftable(xtabs(yield ~ Block+Variety+nitro, data=Oats))
Oats$nitro <- factor(Oats$nitro)
fm <- lme(yield ~ nitro*Variety, random=~1|Block/Variety, data=Oats)
# fm <- lmer(yield ~ nitro*Variety+(1|Block/Variety), data=Oats)
predictmeans(fm, "nitro", adj="BH")
predictmeans(fm, "nitro:Variety", atvar="Variety", adj="BH")
predictout <- predictmeans(fm, "nitro:Variety", atvar="Variety", adj="BH", barplot=TRUE)
names(predictout)
print(predictout$predictmeansPlot)
print(predictout$predictmeansBarPlot)
Run the code above in your browser using DataLab