Predicted Means of a Linear Model
Description
This function obtains predicted means, SE of means, SED of means, LSDs and plots of means
with Stder 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.
Usage
1 2 3 4 5  predictmeans(model, modelterm, pairwise=FALSE, atvar=NULL, adj="none",
Df=NULL, level=0.05, covariate=NULL, trans = NULL, responsen=NULL,
count=FALSE, plotord=NULL, plottitle=NULL, mplot=TRUE, barplot=FALSE,
pplot=TRUE, bkplot=TRUE, plot=TRUE, jitterv=0, basesz=12, prtnum=TRUE,
newwd=TRUE, permlist=NULL)

Arguments
model 
Model object returned by 
modelterm 
Name (in "quotes") for indicating which factor term's predicted mean to be calculated.
The 
pairwise 
An option for showing pairwise LSDs and pvalues, or not. The default is FALSE. 
atvar 
When 
adj 
Name (in "quote") for indicating a method for adjusting pvalues of pairwise comparisons. The choices are "none", "tukey", "holm", "hochberg", "hommel", "bonferroni", "BH", "BY" and "fdr". The default method is "none". 
Df 
A degree of freedom for calculating LSD. For the above models, Df is obtained from the function automatically. 
level 
A significant level for calculating LSD. The default value is 0.05. 
covariate 
A numerical vector to specify values of covariates for calculating predicted means. The default values are the means of the associated covariates. 
trans 
A function object for calculating the back transformed means, e.g. 
responsen 
Name (in "quotes") of the back transformed response variable in the 
count 
An option for indicating the back transformed mean values are counts or not. The default is FALSE. 
plotord 
A numeric vector specifying the order of plotting for two or three way interaction (e.g.

plottitle 
A character vector specifying the main title for plot(s). The default is NULL. 
mplot 
An option for drawing a means plot, or not. The default is TRUE. 
barplot 
An option for drawing a bar chart, or not. The default is FALSE. 
pplot 
An option for drawing a pvalues plot, or not when there are more than six pvalues. The default is TRUE. 
bkplot 
An option for drawing back transformed plot, or not. The default is TRUE. 
plot 
An option for drawing plots, or not. The default is TRUE. 
jitterv 
A degree of jitter in x and y direction in the back transformed means graph. The default is zero. 
basesz 
The base font size. The default is 12. 
prtnum 
An option for printing covariate information on the screen, or not. The default is TRUE. 
newwd 
A logical variable to indicate whether to print graph in a new window. The default is TRUE. 
permlist 
A model parameter list produced by the function 
Value
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. 
Back Transformed Means 
When 
Pairwise pvalue 
A matrix with tvalues above the diagonal and pvalues below the diagonal, or
matrix of pairwise comparison pvalues for each level of 
Note
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"
); the predictmeans
function will confuse the
colons with interactions; rename levels to avoid colons.
For predictmeans
function, it is assumed that methods coef
, vcov
, model.matrix
, model.frame
and terms
are available for model
.
Author(s)
Dongwen Luo, Siva Ganesh and John Koolaard
References
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., Gilm our, A., & Thompson, R. (2004), Prediction in linear mixed models, Australian and New Zealand Journal of Statistics, 46(3), 325347.
Examples
1 2 3 4 5 6 7 8  library(predictmeans)
ftable(xtabs(yield ~ Block+Variety+nitro, data=Oats))
Oats$nitro < factor(Oats$nitro)
fm < lme(yield ~ nitro*Variety, random=~1Block/Variety, data=Oats)
# library(lme4)
# fm < lmer(yield ~ nitro*Variety+(1Block/Variety), data=Oats)
predictmeans(fm, "nitro", adj="BH")
predictmeans(fm, "nitro:Variety", pair=TRUE, atvar="Variety", adj="BH")
