Learn R Programming

bayesMeanScale (version 0.2.1)

bayesPredsF: Bayesian predictions on the mean scale.

Description

Computes Bayesian predictions on the mean scale for models fit using the package "rstanarm". Predictions can be averaged over the values of the covariates in the data (average marginal predictions), or the covariates can be held at their means (marginal predictions at the means). Also, "at" values must be specified to fix at least one covariate at particular values.

Usage

bayesPredsF(model,
            at,
            n_draws      = 2000,
            ci           = .95,
            hdi_interval = TRUE,
            centrality   = 'mean',
            digits       = 4,
            at_means     = FALSE,
            data_slice   = 'full')

Value

A list of class "bayesmeanscale_pred" with the following components:

predTable

summary table of the predictions

predDraws

posterior draws of the predictions

Arguments

model

A model object of class "stanreg."

at

List of covariate values to estimate the predictions at.

n_draws

The number of draws to take from the joint posterior distribution.

ci

The level for the credible intervals.

hdi_interval

If TRUE, the default, computes the highest density credible interval. If FALSE, computes the equal-tailed interval.

centrality

Centrality measure for the posterior distribution. Options are "mean" or "median".

digits

The number of digits to report in the summary table.

at_means

If FALSE, the default, the predictions are averaged across the rows of the model data for each unique combination of "at" values. If TRUE, the covariate values that are not specified in the "at" argument are held at their means.

data_slice

The number of rows of data to average over for the predictions. Defaults to all rows. This can be useful for very large data sets.

Author

David Dalenberg

Details

The following families of fixed-effect models fit using "rstanarm" are supported: 'beta', 'binomial', 'Gamma', 'gaussian', 'neg_binomial_2', and 'poisson.'

References

Agresti, Alan. 2013. Categorical Data Analysis. Third Edition. New York: Wiley

Long, J. Scott and Sarah A. Mustillo. 2018. "Using Predictions and Marginal Effects to Compare Groups in Regression Models for Binary Outcomes." Sociological Methods & Research 50(3): 1284-1320.

Mize, Trenton D. 2019. "Best Practices for Estimating, Interpreting, and Presenting Non-linear Interaction Effects." Sociological Science 6: 81-117.

Examples

Run this code

# \donttest{

## Logit model ##

if(require(rstanarm)){

m1 <- stan_glm(switch ~ dist + educ + arsenic + assoc, 
               data    = rstanarm::wells, 
               family  = binomial, 
               refresh = 0, 
               iter    = 500)

# marginal predictions holding covariates at means #

bayesPredsF(m1, 
            at       = list(arsenic = c(.82, 1.3)), 
            at_means = TRUE,
            n_draws  = 500)
         
}
            
# }

Run the code above in your browser using DataLab