cjbae_df: Tidy Bayesian AMCE dataframe

Description Usage Arguments Details Value Examples

Description

Generate a tidy dataframe of Bayesian AMCEs from brmsfit

Usage

1
cjbae_df(data, formula, brmsfit, iter = 2000)

Arguments

data

A tidy conjoint dataframe - the original dataset you used in the AMCE model.

formula

A standard formula of the form outcome ~ feature 1 + feature 2 ... + feature n - the same as the one plugged into the AMCE model.

brmsfit

The brmsfit object to convert.

iter

The number of iterations in the brms model. Defaults to 2000, the same as the default in amce_bae and cjbae.

Details

cjbae_df() takes an AMCE brmsfit object and creates a dataframe of AMCE parameter estimates. The other arguments are needed in addition to the brmsfit argument in order to create the feature variable in the output. Also used as a utility function in other functions.

Value

A dataframe of AMCEs. These take the form of samples from the posterior probability distribution and can be plotted as distributions, rather than point estimates.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#' #' #load example dataset from {cregg} (Leeper 2019)
library(cregg)
data(taxes)
# formula
f <- chose_plan ~ taxrate1 + taxrate2 + taxrate3 + taxrate4 + taxrate5 + taxrate6 + taxrev
# prior - minimally informative
prior <- c(set_prior("normal(0, .2)", class = "Intercept"),
set_prior("normal(0, .2)", class = "b"),
set_prior("exponential(10)", class = "sd"),
set_prior("exponential(10)", class = "sigma"))
# run generic function with MM and save specified, gives MMs as output and saves brmsfit to
# working directory - this will take a while
bae <- cjbae(data = taxes, formula = f, id = ID, estimate = "mm", prior = prior, save_amce = TRUE)
# AMCE brmsfit object can be loaded from working directory using readRDS()
# then converted into proper cjbae output
cjbae_df(taxes, f, baerms)
# if the iter argument in cjbae() is altered from the default, the same is required in cjbae_df()
bae <- cjbae(data = taxes, formula = f, id = ID, estimate = "mm", prior = prior, save_amce = TRUE, iter = 1e3)
cjbae_df(taxes, f, baerms, iter = 1e3)

mbarnfield/cjbae documentation built on June 23, 2019, 3:32 a.m.