jhelvy / cbcTools

An R package with tools for designing choice based conjoint (cbc) survey experiments and conducting power analyses
https://jhelvy.github.io/cbcTools/
Other
5 stars 5 forks source link

`cbc_choices()` with an outside good (`no_choice = TRUE`) #31

Open jhelvy opened 9 months ago

jhelvy commented 9 months ago

When I use cbc_choices() with a design where no_choice = TRUE, the choices get simulated, but the model always has NA for the standard errors. There may need to be a special argument for handling the no_choice variable, similar to the prior_no_choice argument in cbc_design(). Here is an example:

# Load libraries
library(cbcTools)
library(logitr)

# Define profiles with attributes and levels
profiles <- cbc_profiles(
    price       = c(15, 20, 25), # Price ($1,000)
    fuelEconomy = c(20, 25, 30),   # Fuel economy (mpg)
    accelTime   = c(6, 7, 8),      # 0-60 mph acceleration time (s)
    powertrain  = c("Gasoline", "Electric")
)

# Make a full-factorial design of experiment
design <- cbc_design(
    profiles = profiles,
    n_resp   = 1000, # Number of respondents
    n_alts   = 3,    # Number of alternatives per question
    n_q      = 8,     # Number of questions per respondent
    no_choice = TRUE
)

# Simulate choices according to an assumed utility model
data <- cbc_choices(
    design = design,
    obsID = "obsID",
    priors = list(
        price       = -0.7,
        fuelEconomy = 0.1,
        accelTime   = -0.2,
        powertrain_Electric = -4.0,
        no_choice = -2
    )
)

# Estimate a model 
model <- logitr(
  data   = data,
  outcome = "choice",
  obsID  = "obsID",
  pars   = c(
      "price", "fuelEconomy", "accelTime", "powertrain_Electric", "no_choice"
  )
)

summary(model)