Description Usage Arguments Details Value Examples

Calculate Bayesian AMCEs and marginal means for conjoint experiments

1 2 3 |

`data` |
A tidy conjoint dataset |

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

`id` |
Respondent ID variable |

`estimate` |
Either AMCE or MM. AMCE is always calculated within the function so if you want both write "mm". |

`prior` |
Priors for brms. Note these are always priors for the AMCE calculation, regardless of which estimate is specified here. 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 and set 'estimate = "mm"', then load the brmsfit object into your environment and pass it through 'cjbae_df()'. 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. |

`cjbae()`

is a generic Bayesian estimation function for the two key quantities of interest in conjoint experiments (AMCEs and marginal means), and is essentially a wrapper for [‘brms'](https://github.com/paul-buerkner/brms) and ['emmeans'](https://github.com/rvlenth/emmeans), and borrows extensively from ['cregg'](https://github.com/leeper/cregg), R’s foremost conjoint analysis package.

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | ```
#' #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)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.