amce_bae: Bayesian AMCEs for conjoint analysis

Description Usage Arguments Details Value Examples

Description

Calculate Bayesian AMCEs for conjoint experiments

Usage

1
2
3
amce_bae(data, formula, id, prior, save_amce = TRUE,
  save_name = "baerms", iter = 2000, chains = 2, cores = 2,
  refresh = 10)

Arguments

data

A tidy conjoint dataset

formula

A standard formula of the form outcome ~ feature 1 + feature 2 ... + feature n

id

Respondent ID variable

prior

Priors for brms. Priors required for beta, intercept, sd and sigma. For clarification see examples below.

save_amce

Logical vector telling R whether or not to save the AMCE brmsfit as an object in your working directory. If you want both AMCE and MM estimates, set this to TRUE then load the brmsfit object into your environment and pass it through 'mm_bae()'. Alternatively, use 'cjbae()'. Defaults to TRUE.

save_name

The name you would like the AMCE brmsfit saved as. Defaults to 'baerms'.

iter

The number of iterations in the brms model. Essentially, the number of times it will sample from the posterior probability distribution. Defaults to 2000.

chains

The number of chains in the brms model. Defaults to 2.

cores

The number of cores used in the brms model. Defaults to 2.

refresh

The number of refreshes. Defaults to 10.

Details

amce_bae() is a Bayesian estimation function for a key quantity of interest in conjoint analysis (AMCEs), and is essentially a wrapper for [‘brms'](https://github.com/paul-buerkner/brms), and borrows extensively from ['cregg'](https://github.com/leeper/cregg), R’s foremost conjoint analysis package. The calculation in this function is computationally expensive, but exactly how long it takes is highly contingent on the size of the dataset.

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
#' #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 amce function with save specified, saves brmsfit to working directory - this will take a while
amce_bae(data = taxes, formula = f, id = ID, prior = prior, save_amce = TRUE)
# run mm function on the saved output
readRDS(baerms)
mm <- mm_bae(baerms, f, ID)
# plot MMs
cjbae_plot(mm, "ridge", "mm")

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