cjbart: Generate Conjoint Model Using BART

View source: R/cjbart.R

cjbartR Documentation

Generate Conjoint Model Using BART

Description

A wrapper for the BART::pbart() function used for estimating heterogeneity in conjoint models

Usage

cjbart(
  data,
  Y,
  type = NULL,
  id = NULL,
  round = NULL,
  use_round = TRUE,
  cores = 1,
  ...
)

Arguments

data

A data.frame, containing all attributes, controls, the outcome and id variables to analyze.

Y

Character string – the outcome variable

type

Type of conjoint experiment – either "choice" (for forced-choice outcomes) or "rating" (for interval ratings). If NULL (default), the function will attempt to automatically detect the outcome type.

id

Character string – variable identifying individual respondents (optional)

round

Character string – variable identifying rounds of the conjoint experiment

use_round

Boolean – whether to include the round indicator column when training the BART model (default = TRUE)

cores

Integer – number of CPU cores used in model training

...

Other arguments passed to BART::mc.pbart() if on a Unix-based system

Details

Please note, Windows users cannot use the parallelized BART::mc.pbart() function, and so setting an internal seed will not be used.

Value

A trained BART::pbart() model that can be passed to IMCE()

See Also

BART::pbart()

Examples

subjects <- 5
rounds <- 2
profiles <- 2
obs <- subjects*rounds*profiles

fake_data <- data.frame(A = sample(c("a1","a2"), obs, replace = TRUE),
                        B = sample(c("b1","b2"), obs, replace = TRUE),
                        id1 = rep(1:subjects, each=rounds),
                        stringsAsFactors = TRUE)

fake_data$Y <- sample(c(0,1), obs, replace = TRUE)

cj_model <- cjbart(data = fake_data,
                   Y = "Y",
                   id = "id1")

cjbart documentation built on Sept. 8, 2023, 5:57 p.m.