as.data.frame.ggeffects | R Documentation |
After fitting a model, it is useful generate model-based estimates (expected values, or adjusted predictions) of the response variable for different combinations of predictor values. Such estimates can be used to make inferences about relationships between variables.
The ggeffects package computes marginal means and adjusted predicted
values for the response, at the margin of specific values or levels from
certain model terms. The package is built around three core functions:
predict_response()
(understanding results), test_predictions()
(testing
results for statistically significant differences) and plot()
(communicate
results).
By default, adjusted predictions or marginal means are by returned on the
response scale, which is the easiest and most intuitive scale to interpret
the results. There are other options for specific models as well, e.g. with
zero-inflation component (see documentation of the type
-argument). The
result is returned as consistent data frame, which is nicely printed by
default. plot()
can be used to easily create figures.
The main function to calculate marginal means and adjusted predictions is
predict_response()
. In previous versions of ggeffects, the functions
ggpredict()
, ggemmeans()
, ggeffect()
and ggaverage()
were used to
calculate marginal means and adjusted predictions. These functions are still
available, but predict_response()
as a "wrapper" around these functions is
the preferred way to do this now.
## S3 method for class 'ggeffects'
as.data.frame(
x,
row.names = NULL,
optional = FALSE,
...,
stringsAsFactors = FALSE,
terms_to_colnames = FALSE
)
ggaverage(
model,
terms,
ci_level = 0.95,
type = "fixed",
typical = "mean",
condition = NULL,
back_transform = TRUE,
vcov_fun = NULL,
vcov_type = NULL,
vcov_args = NULL,
weights = NULL,
verbose = TRUE,
...
)
ggeffect(model, terms, ci_level = 0.95, verbose = TRUE, ci.lvl = ci_level, ...)
ggemmeans(
model,
terms,
ci_level = 0.95,
type = "fixed",
typical = "mean",
condition = NULL,
back_transform = TRUE,
vcov_fun = NULL,
vcov_type = NULL,
vcov_args = NULL,
interval = "confidence",
verbose = TRUE,
ci.lvl = ci_level,
back.transform = back_transform,
...
)
ggpredict(
model,
terms,
ci_level = 0.95,
type = "fixed",
typical = "mean",
condition = NULL,
back_transform = TRUE,
ppd = FALSE,
vcov_fun = NULL,
vcov_type = NULL,
vcov_args = NULL,
interval,
verbose = TRUE,
ci.lvl = ci_level,
back.transform = back_transform,
vcov.fun = vcov_fun,
vcov.type = vcov_type,
vcov.args = vcov_args,
...
)
x |
An object of class |
row.names |
|
optional |
logical. If |
... |
Arguments are passed down to |
stringsAsFactors |
logical: should the character vector be converted to a factor? |
terms_to_colnames |
Logical, if |
model |
A model object, or a list of model objects. |
terms |
Names of those terms from
|
ci_level |
Numeric, the level of the confidence intervals. Use
|
type |
Character, indicating whether predictions should be conditioned
on specific model components or not. Consequently, most options only apply
for survival models, mixed effects models and/or models with zero-inflation
(and their Bayesian counter-parts); only exception is Note 1: For Note 2: If
When |
typical |
Character vector, naming the function to be applied to the
covariates (non-focal terms) over which the effect is "averaged". The
default is |
condition |
Named character vector, which indicates covariates that
should be held constant at specific values. Unlike |
back_transform |
Logical, if |
vcov_fun |
Variance-covariance matrix used to compute uncertainty estimates (e.g., for confidence intervals based on robust standard errors). This argument accepts a covariance matrix, a function which returns a covariance matrix, or a string which identifies the function to be used to compute the covariance matrix.
If See details in this vignette. |
vcov_type |
Character vector, specifying the estimation type for the
robust covariance matrix estimation (see |
vcov_args |
List of named vectors, used as additional arguments that
are passed down to |
weights |
This argument is used in two different ways, depending on the
|
verbose |
Toggle messages or warnings. |
ci.lvl , vcov.fun , vcov.type , vcov.args , back.transform |
Deprecated arguments.
Please use |
interval |
Type of interval calculation, can either be |
ppd |
Logical, if |
Please see ?predict_response
for details and examples.
A data frame (with ggeffects
class attribute) with consistent data columns:
"x"
: the values of the first term in terms
, used as x-position in plots.
"predicted"
: the predicted values of the response, used as y-position in plots.
"std.error"
: the standard error of the predictions. Note that the standard
errors are always on the link-scale, and not back-transformed for non-Gaussian
models!
"conf.low"
: the lower bound of the confidence interval for the predicted values.
"conf.high"
: the upper bound of the confidence interval for the predicted values.
"group"
: the grouping level from the second term in terms
, used as
grouping-aesthetics in plots.
"facet"
: the grouping level from the third term in terms
, used to indicate
facets in plots.
The estimated marginal means (or predicted values) are always on the response scale!
For proportional odds logistic regression (see ?MASS::polr
)
resp. cumulative link models (e.g., see ?ordinal::clm
),
an additional column "response.level"
is returned, which indicates
the grouping of predictions based on the level of the model's response.
Note that for convenience reasons, the columns for the intervals
are always named "conf.low"
and "conf.high"
, even though
for Bayesian models credible or highest posterior density intervals
are returned.
There is an as.data.frame()
method for objects of class ggeffects
,
which has an terms_to_colnames
argument, to use the term names as column
names instead of the standardized names "x"
etc.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.