Simulate choices for a given survey
data frame, either randomly or
according to a utility model defined by user-provided parameters.
simulateChoices(survey, obsID = "obsID", pars = NULL, numDraws = 100)
survey | A survey data frame exported from the |
---|---|
obsID | The name of the column that identifies each choice observation.
Defaults to |
pars | A list of one or more parameters separated by commas that define
the "true" utility model used to simulate choices for the |
numDraws | The number of Halton draws to use for simulated choices
based on mixed logit models. Defaults to |
Returns the survey
data frame with an additional choice
column
identifying the simulated choices.
library(conjointTools) # Define the attributes and levels levels <- list( price = seq(1, 4, 0.5), # $ per pound type = c('Fuji', 'Gala', 'Honeycrisp', 'Pink Lady', 'Red Delicious'), freshness = c('Excellent', 'Average', 'Poor') ) # Make a full-factorial design of experiment doe <- makeDoe(levels) # Re-code levels doe <- recodeDoe(doe, levels) # Make the conjoint survey by randomly sampling from the doe survey <- makeSurvey( doe = doe, # Design of experiment nResp = 2000, # Total number of respondents (upper bound) nAltsPerQ = 3, # Number of alternatives per question nQPerResp = 6 # Number of questions per respondent ) # Simulate random choices for the survey data_random <- simulateChoices( survey = survey, obsID = "obsID" ) # Simulate choices based on a utility model with the following parameters: # - 1 continuous "price" parameter # - 4 discrete parameters for "type" # - 2 discrete parameters for "freshness" data_mnl <- simulateChoices( survey = survey, obsID = "obsID", pars = list( price = 0.1, type = c(0.1, 0.2, 0.3, 0.4), freshness = c(0.1, -0.1)) ) # Simulate choices based on a utility model with the following parameters: # - 1 continuous "price" parameter # - 4 discrete parameters for "type" # - 2 random normal discrete parameters for "freshness" # - 2 interaction parameters between "price" and "freshness" data_mxl <- simulateChoices( survey = survey, obsID = "obsID", pars = list( price = 0.1, type = c(0.1, 0.2, 0.3, 0.4), freshness = randN(mu = c(0.1, -0.1), sigma = c(1, 2)), `price*freshness` = c(1, 2)) )