rstanarm_tidiers | R Documentation |
These methods tidy the estimates from rstanarm
fits
(stan_glm
, stan_glmer
, etc.)
into a summary.
## S3 method for class 'stanreg'
tidy(
x,
effects = c("fixed", "ran_pars"),
conf.int = FALSE,
conf.level = 0.9,
conf.method = c("quantile", "HPDinterval"),
exponentiate = FALSE,
...
)
## S3 method for class 'stanreg'
glance(x, looic = FALSE, ...)
x |
Fitted model object from the rstanarm package. See
|
effects |
A character vector including one or more of |
conf.int |
If |
conf.level |
See |
conf.method |
method for computing confidence intervals ("quantile" or "HPDinterval") |
exponentiate |
whether to exponentiate the fixed-effect coefficient estimates and confidence intervals (common for logistic regression); if |
... |
For |
looic |
Should the LOO Information Criterion (and related info) be
included? See |
All tidying methods return a data.frame
without rownames.
The structure depends on the method chosen.
When effects="fixed"
(the default), tidy.stanreg
returns
one row for each coefficient, with three columns:
term |
The name of the corresponding term in the model. |
estimate |
A point estimate of the coefficient (posterior median). |
std.error |
A standard error for the point estimate based on
|
For models with group-specific parameters (e.g., models fit with
stan_glmer
), setting effects="ran_vals"
selects the group-level parameters instead of the non-varying regression
coefficients. Addtional columns are added indicating the level
and
group
. Specifying effects="ran_pars"
selects the
standard deviations and (for certain models) correlations of the group-level
parameters.
Setting effects="auxiliary"
will select parameters other than those
included by the other options. The particular parameters depend on which
rstanarm modeling function was used to fit the model. For example, for
models fit using stan_glm
the overdispersion
parameter is included if effects="aux"
, for
stan_lm
the auxiliary parameters include the residual
SD, R^2, and log(fit_ratio), etc.
glance
returns one row with the columns
algorithm |
The algorithm used to fit the model. |
pss |
The posterior sample size (except for models fit using optimization). |
nobs |
The number of observations used to fit the model. |
sigma |
The square root of the estimated residual variance, if
applicable. If not applicable (e.g., for binomial GLMs), |
If looic=TRUE
, then the following additional columns are also
included:
looic |
The LOO Information Criterion. |
elpd_loo |
The expected log predictive density ( |
p_loo |
The effective number of parameters. |
summary,stanfit-method
if (require("rstanarm")) {
## Not run:
#' ## original models
fit <- stan_glmer(mpg ~ wt + (1|cyl) + (1+wt|gear), data = mtcars,
iter = 500, chains = 2)
fit2 <- stan_glmer((mpg>20) ~ wt + (1 | cyl) + (1 + wt | gear),
data = mtcars,
family = binomial,
iter = 500, chains = 2
## End(Not run)
## load example data
load(system.file("extdata", "rstanarm_example.rda", package="broom.mixed"))
# non-varying ("population") parameters
tidy(fit, conf.int = TRUE, conf.level = 0.5)
tidy(fit, conf.int = TRUE, conf.method = "HPDinterval", conf.level = 0.5)
# exponentiating (in this case, from log-odds to odds ratios)
(tidy(fit2, conf.int = TRUE, conf.level = 0.5)
|> dplyr::filter(term != "(Intercept)")
)
(tidy(fit2, conf.int = TRUE, conf.level = 0.5, exponentiate = TRUE)
|> dplyr::filter(term != "(Intercept)")
)
# hierarchical sd & correlation parameters
tidy(fit, effects = "ran_pars")
# group-specific deviations from "population" parameters
tidy(fit, effects = "ran_vals")
# glance method
glance(fit)
## Not run:
glance(fit, looic = TRUE, cores = 1)
## End(Not run)
} ## if require("rstanarm")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.