R/sjPlotGLME.R
sjp.glmer.Rd
By default, this function plots estimates (odds, risk or incidents
ratios, i.e. exponentiated coefficients, depending on family and
link function)
with confidence intervals of either fixed effects or random effects of
generalized linear mixed effects models (that have been fitted with the
glmer
function of the lme4package).
Furthermore, this function also plots predicted probabilities /
incidents or diagnostic plots.
sjp.glmer(fit, type = "re", vars = NULL, ri.nr = NULL, group.estimates = NULL, remove.estimates = NULL, emph.grp = NULL, sample.n = NULL, sort.est = NULL, title = NULL, legend.title = NULL, axis.labels = NULL, axis.title = NULL, geom.colors = "Set1", geom.size = NULL, show.values = TRUE, show.p = TRUE, show.ci = FALSE, show.legend = FALSE, show.intercept = FALSE, string.interc = "(Intercept)", show.scatter = TRUE, point.alpha = 0.2, point.color = NULL, jitter.ci = FALSE, fade.ns = FALSE, axis.lim = NULL, digits = 2, vline.type = 2, vline.color = "grey70", facet.grid = TRUE, free.scale = FALSE, y.offset = 0.1, prnt.plot = TRUE, ...)
fit  A fitted model as returned by the 

type  Type of plot. Use one of following:

vars  Numeric vector with column indices of selected variables or a character vector with
variable names of selected variables from the fitted model, which should be used to plot
 depending on 
ri.nr  Numeric vector. If 
group.estimates  Numeric or character vector, indicating a group identifier for each estimate. Dots and confidence intervals of estimates are coloured according to their group association. See 'Examples'. 
remove.estimates  Character vector with coefficient names that indicate
which estimates should be removed from the plot.

emph.grp  Numeric vector with index numbers of grouping levels (from random effect).
If 
sample.n  Numeric vector. only applies, if 
sort.est  Determines in which way estimates are sorted in the plot:
See 'Examples'. 
title  Character vector with one or more labels that are used as plot title. 
legend.title  Character vector, used as title for the plot legend. Note that
only some plot types have legends (e.g. 
axis.labels  Character vector with labels for the model terms, used as axis labels.
For mixed models, should either be vector of fixed effects variable labels
(if 
axis.title  Character vector of length one or two (depending on
the plot function and type), used as title(s) for the x and y axis.
If not specified, a default labelling is chosen. To set multiple
axis titles (e.g. with 
geom.colors  User defined color palette for geoms. If 
geom.size  size resp. width of the geoms (bar width, line thickness or point size, depending on plot type and function). Note that bar and bin widths mostly need smaller values than dot sizes. 
show.values  Logical, whether values should be plotted or not. 
show.p  Logical, adds significance levels to values, or value and variable labels. 
show.ci  Logical, if 
show.legend  logical, if 
show.intercept  Logical, if 
string.interc  String, axis label of intercept estimate. Only applies,
if 
show.scatter  Logical, if 
point.alpha  Alpha value of pointgeoms in the scatter plots. Only applies,
if 
point.color  Color of of pointgeoms in the scatter plots. Only applies,
if 
jitter.ci  Logical, if 
fade.ns  Logical, if 
axis.lim  Numeric vector of length 2, defining the range of the plot axis.
Depending on plot type, may effect either x or yaxis, or both.
For multiple plot outputs (e.g., from 
digits  Numeric, amount of digits after decimal point when rounding estimates and values. 
vline.type  Linetype of the vertical "zero point" line. Default is 
vline.color  Color of the vertical "zero point" line. Default value is 
facet.grid 

free.scale  Logical, if 
y.offset  numeric, offset for text labels when their alignment is adjusted
to the top/bottom of the geom (see 
prnt.plot  logical, if 
...  Other arguments passed down to further functions. Currently, following arguments are supported:

(Insisibily) returns, depending on the plot type
The ggplotobject (plot
). For multiple plots and if facet.grid = FALSE
) a plot.list
is returned.
A data frame data
with the data used to build the ggplotobject(s), or a list of data frames (data.list
).
type = "re"
plots the conditional modes of the random
effects, inclduing predicion intervals. It basically does the same
as dotplot(exp(ranef(fit, condVar = TRUE)[[i]])
, where i
denotes the random effect index.
type = "fe.slope"
the predicted values
are based on the fixed effects intercept's estimate and each specific
fixed term's estimate. All other fixed effects are set to zero (i.e. ignored),
which corresponds to family(fit)$linkinv(eta = b0 + bi * xi)
(where xi
is the estimate of fixed effects and b0
is the intercept of
the fixed effects; the inverse linkfunction is used). This plot type
may give similar results as type = "pred"
, however, type = "fe.slope"
does not adjust for other predictors.
type = "eff"
plots the marginal effects of model predictors.
Unlike type = "fe.slope"
, the predicted values computed by
type = "eff"
are adjusted for all covariates, which are
set to the mean, as returned by the allEffects
function.
You can pass further arguments down to allEffects
for flexible
function call via the ...
argument.
type = "ri.slope"
the predicted values
are based on the fixed effects intercept, plus each random intercept and
each specific fixed term's estimate. All other fixed effects are set to zero (i.e. ignored),
which corresponds to family(fit)$linkinv(eta = b0 + b0[r1rn] + bi * xi)
(where xi
is the estimate of fixed effects, b0
is the intercept of
the fixed effects and b0[r1rn]
are all random intercepts).
type = "rs.ri"
the predicted values are based
on the fixed effects intercept, plus each random intercept and
random slope. This plot type is intended to plot the random part, i.e.
the predicted probabilities or incident rates of each random slope
for each random intercept.
Since the random intercept specifies the deviance from the gloabl
intercept, the global intercept is always included. In case of overplotting,
use the sample.n
argument to randomly sample a limited amount
of groups.
type = "coef"
forest plot of joint fixed and random
effect coefficients, as retrieved by coef.merMod
,
it's simply ranef + fixef
.
type = "pred"
or type = "pred.fe"
predicted
values against response, only fixed effects or
conditional on random intercept. It's calling
predict(fit, type = "response", re.form = NA)
resp.
predict(fit, type = "response", re.form = NULL)
to
compute the values.
This plot type requires the vars
argument to select specific terms
that should be used for the xaxis and  optional  as grouping factor.
Hence, vars
must be a character vector with the names of
one or two model predictors. See 'Examples'.
Computation of pvalues (if necessary) is based on normal distribution assumption, treating the tstatistics as Wald zstatistics.
Plot types use the inverse linkfunction to calculate predicted probabilites or incidents rates. Thus, this function should work with different model families and link functions; however, the plot or axis title may not use the exact terminology regarding model family or link function.
Thanks go to Robert Reijntjes from Leiden University Medical Center for sharing R code that is used to compute fixed effects correlation matrices and qqplots of random effects.