broom.mixed (version 0.2.3)

brms_tidiers: Tidying methods for a brms model

Description

These methods tidy the estimates from brmsfit-objects (fitted model objects from the brms package) into a summary.

Usage

# S3 method for brmsfit
tidy(x, parameters = NA, effects = c("fixed",
  "ran_pars"), robust = FALSE, conf.int = TRUE, conf.level = 0.95,
  conf.method = c("quantile", "HPDinterval"), fix.intercept = TRUE,
  ...)

# S3 method for brmsfit glance(x, looic = FALSE, ...)

# S3 method for brmsfit augment(x, data = stats::model.frame(x), newdata = NULL, se.fit = TRUE, ...)

Arguments

x

Fitted model object from the brms package. See brmsfit-class.

parameters

Names of parameters for which a summary should be returned, as given by a character vector or regular expressions. If NA (the default) summarized parameters are specified by the effects argument.

effects

A character vector including one or more of "fixed", "ran_vals", or "ran_pars". See the Value section for details.

robust

Whether to use median and median absolute deviation of the posterior distribution, rather than mean and standard deviation, to derive point estimates and uncertainty

conf.int

If TRUE columns for the lower (conf.low) and upper bounds (conf.high) of posterior uncertainty intervals are included.

conf.level

Defines the range of the posterior uncertainty conf.int, such that 100 * conf.level% of the parameter's posterior distributio lies within the corresponding interval. Only used if conf.int = TRUE.

conf.method

method for computing confidence intervals ("quantile" or "HPDinterval")

fix.intercept

rename "Intercept" parameter to "(Intercept)", to match behaviour of other model types?

...

Extra arguments, not used

looic

Should the LOO Information Criterion (and related info) be included? See loo.stanreg for details. Note: for models fit to very large datasets this can be a slow computation.

data

data frame

newdata

new data frame

se.fit

return standard errors of fit?

Value

All tidying methods return a data.frame without rownames. The structure depends on the method chosen.

When parameters = NA, the effects argument is used to determine which parameters to summarize.

Generally, tidy.brmsfit returns one row for each coefficient, with at least three columns:

term

The name of the model parameter.

estimate

A point estimate of the coefficient (mean or median).

std.error

A standard error for the point estimate (sd or mad).

When effects = "fixed", only population-level effects are returned.

When effects = "ran_vals", only group-level effects are returned. In this case, two additional columns are added:

group

The name of the grouping factor.

level

The name of the level of the grouping factor.

Specifying effects = "ran_pars" selects the standard deviations and correlations of the group-level parameters.

If conf.int = TRUE, columns for the lower and upper bounds of the posterior conf.int computed.

See Also

brms, brmsfit-class

Examples

Run this code
# NOT RUN {
 ## original model
 
# }
# NOT RUN {
    brms_crossedRE <- brm(mpg ~ wt + (1|cyl) + (1+wt|gear), data = mtcars,
           iter = 500, chains = 2)
 
# }
# NOT RUN {
 if (require("brms")) {
   ## load stored object
   load(system.file("extdata", "brms_example.rda", package="broom.mixed"))

   fit <- brms_crossedRE
   tidy(fit)
   tidy(fit, parameters = "^sd_", conf.int = FALSE)
   tidy(fit, effects = "fixed", conf.method="HPDinterval")
   tidy(fit, effects = "ran_vals")
   tidy(fit, effects = "ran_pars", robust = TRUE)
   # glance method
   glance(fit)
   ## this example will give a warning that it should be run with
   ## reloo=TRUE; however, doing this will fail
   ## because the \code{fit} object has been stripped down to save space
   suppressWarnings(glance(fit, looic = TRUE, cores = 1))
   head(augment(fit))
}

# }

Run the code above in your browser using DataCamp Workspace