R/sjPlotGLME.R
sjp.lmer.Rd
By default, this function plots estimates (coefficients) with confidence
intervalls of either fixed effects or random effects of linear mixed
effects models (that have been fitted with the lmer
-function
of the lme4-package). Furhermore, this function also plot
predicted values or diagnostic plots.
sjp.lmer(fit, type = "re", vars = NULL, ri.nr = NULL, group.estimates = NULL, remove.estimates = NULL, emph.grp = NULL, sample.n = NULL, poly.term = NULL, sort.est = NULL, title = NULL, legend.title = NULL, axis.labels = NULL, axis.title = NULL, geom.size = NULL, geom.colors = "Set1", show.values = TRUE, show.p = TRUE, show.ci = FALSE, show.legend = FALSE, show.loess = FALSE, show.loess.ci = FALSE, show.intercept = FALSE, string.interc = "(Intercept)", p.kr = TRUE, 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 |
poly.term | name of a polynomial term in |
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. |
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.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. |
geom.colors | user defined color for geoms. See 'Details' in |
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.loess | logical, if |
show.loess.ci | logical, if |
show.intercept | Logical, if |
string.interc | String, axis label of intercept estimate. Only applies,
if |
p.kr | logical, if |
show.scatter | Logical, if |
point.alpha | Alpha value of point-geoms in the scatter plots. Only applies,
if |
point.color | Color of of point-geoms 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 y-axis, 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
the ggplot-object (plot
), if type = "fe"
or if type = "re"
and facet.grid = TRUE
). Multiple plots (type = "re"
and if facet.grid = FALSE
) are returned in the object plot.list
.
a list of ggplot-objects (plot.list
). see plot
for details.
a data frame data
with the data used to build the ggplot-object(s).
type = "re"
plots the conditional modes of the random
effects, inclduing predicion intervals. It basically does the same
as dotplot(ranef(fit, condVar = TRUE)[[i]])
, where i
denotes the random effect index.
type = "fe.slope"
plots the linear relationship between
each fixed effect and the response. The regression lines are not
based on the fitted model's fixed effects estimates (though they may
be similar). This plot type just computes a simple linear model for
each fixed effect and response. Hence, it's intended for checking
model assumptions, i.e. if predictor and respone are in a linear relationship.
You may use the show.loess
argument to see whether the linear
line differs from the best fitting line.
type = "fe.resid"
Similar to type = "fe.slope"
,
this this type is intended for checking model assumptions. However,
fitted values are plotted against the residuals instead of response.
type = "eff"
plots the adjusted (marginal) effects
for each fixed effect, with all co-variates 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 = "eff.ri"
plots the adjusted (marginal) effects
for each fixed effect, with all co-variates set to the mean, varying
by the random intercepts. This plot type basically does the same
as type = "ri.slope"
, except that the co-variates are not
set to zero, but adjusted for. This plot type differs from type = "ri.slope"
only in the adjusted y-axis-scale
type = "rs.ri"
plots regression lines for the random
effects of the model, i.e. all random slopes for each random intercept.
As the random intercepts describe the deviation from the global intercept,
the regression lines are computed as global intercept + random intercept +
random slope. In case of overplotting,
use the sample.n
argument to randomly sample a limited amount
of groups.
type = "ri.slope"
plots regression lines for each fixed
effect (slopes) within each random intercept. Lines 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 b0 + b0[r1-rn] + bi * xi)
(where xi
is the estimate of fixed effects, b0
is the intercept of
the fixed effects and b0[r1-rn]
are all random intercepts).
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 for response, conditional on fixed effects only or 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 x-axis 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 p-values (if necessary and if p.kr = TRUE
) are based
on conditional F-tests with Kenward-Roger approximation for the df, using
the pbkrtest-package. If pbkrtest is not available or
p.kr = FALSE
, computation of p-values is based
on normal-distribution assumption, treating the t-statistics as Wald
z-statistics. See 'Details' in p_value
.