bayesCountMargEffF {bayesMeanScale}R Documentation

Bayesian marginal effects on count probabilities.

Description

Computes Bayesian marginal effects on count probabilities. Models must have a family of "poisson"" or "neg_binomial_2" and be fit using the "rstanarm" package. Marginal effects can be averaged over the values of the covariates in the data (average marginal effects), or the covariates can be held at their means (marginal effects at the means). Also, "at" values can be specified to fix covariates at particular values. The marginal effects must be specified in terms of discrete changes. When investigating continuous variables this might be specified as the change between the mean and 1 standard deviation above the mean, for example.

Usage

bayesCountMargEffF(model,
                   counts,
                   marginal_effect,
                   start_value,
                   end_value,
                   n_draws         = 2000,
                   ci              = .95,
                   hdi_interval    = TRUE,
                   centrality      = 'mean',
                   digits          = 4,
                   at              = NULL,
                   at_means        = FALSE)

Arguments

model

A model object of class "stanreg."

counts

Vector of counts to get the predicted probabilities for.

marginal_effect

A character vector of terms that you want to estimate the marginal effect for.

start_value

The start value(s) for the marginal effect(s). Must be a list when specifying multiple values.

end_value

The end value(s) for the marginal effect(s). Must be a list when specifying multiple values.

n_draws

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

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

Optional list of covariate values to estimate the marginal effect at.

at_means

If FALSE, the default, the marginal effects are averaged across the rows of the data. If TRUE, the covariate values that are not specified in the "at" argument are held at their means.

Details

Marginal effects on count probabilities give you useful information to complement post estimation summaries on the mean scale.

Value

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

diffTable

summary table of the marginal effects

diffDraws

posterior draws of the marginal effects

Author(s)

David Dalenberg

References

Long, J. Scott and Jeremy Freese. 2001. "Predicted Probabilities for Count Models." Stata Journal 1(1): 51-57.

Examples




crabs <- read.table("https://users.stat.ufl.edu/~aa/cat/data/Crabs.dat", 
                    header = TRUE)

poissonModel  <- rstanarm::stan_glm(sat ~ weight + width, 
                                    data    = crabs, 
                                    family  = poisson, 
                                    refresh = 0,
                                    iter    = 500)

# marginal effect holding covariates at their means #

bayesCountMargEffF(poissonModel,
                   counts          = 1,
                   marginal_effect = 'width',
                   start_value     = 25,
                   end_value       = 20,
                   at_means        = TRUE,
                   n_draws         = 500)
                   



[Package bayesMeanScale version 0.1.1 Index]