I've run a conjoint study and now trying to use R package ChoiceModelR to estimate utilities. I've read the package documentation and looked through similar answers/questions on StackOverflow (here and here), but getting the error message below.
My data file (the .csv that you can download from here has the required format (UnitID Set Alt X_1 ... X_natts y) were y is discrete. In each choice set, I have 2 alternatives and "none" choice. I have excluded the rows with the "none" option from the data file. For the "none" choice set, the choice number is set as "number of alternatives +1", that is, 3.
As far as I can see, that data is in the required format. However, I can’t estimate the utilities and get the following error:
Error: invalid values of y present in data - values must be 1 to 3
My input looks like this:
id set_number card_number att1 att2 att3 att4 dv
1 932 1 1 1 1 1 3 2
2 932 1 2 2 2 4 4 0
4 932 2 1 3 3 3 1 2
5 932 2 2 4 2 2 4 0
7 932 3 1 5 4 1 3 2
8 932 3 2 6 3 3 2 0
...
My code looks like this
library(ChoiceModelR)
c_data <- read.csv("c_data.csv")
# Set parameter for calculation
# R is the total number of iterations of the Markov Chain Monte Carlo to be performed
# use is the number of iterations to be used in parameter estimation
mcmc = list(R = 4000, use = 2000)
# Set parameter of datainput
# xcoding specifies the way in which each attribute will be coded (0 = categorical, 1 = nominal)
# none = TRUE to estimate a none parameter, and the data does not include a row for “none” (i.e., no choice)
# keep is the thinning parameter that defines the number of random draws to save
xcoding = c(0, 0, 0, 0)
options = list(none = TRUE, keep = 5)
# Putting it together to get betas
choicemodelr(data = c_data, xcoding = xcoding, mcmc = mcmc, options = options)
Running this code results in this error:
Error: invalid values of y present in data - values must be 1 to 3
20 top rows with dput:
structure(list(id = c(932L, 932L, 932L, 932L, 932L, 932L, 932L,
932L, 932L, 932L, 932L, 932L, 932L, 932L, 932L, 932L, 933L, 933L,
933L, 933L), set_number = c(1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 5L,
5L, 6L, 6L, 7L, 7L, 8L, 8L, 1L, 1L, 2L, 2L), card_number = c(1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L), att1 = c(1L, 2L, 3L, 4L, 5L, 6L, 3L, 4L, 5L, 2L,
3L, 4L, 2L, 6L, 6L, 4L, 3L, 5L, 6L, 2L), att2 = c(1L, 2L, 3L,
2L, 4L, 3L, 1L, 3L, 1L, 2L, 1L, 4L, 4L, 3L, 4L, 3L, 3L, 1L, 2L,
4L), att3 = c(1L, 4L, 3L, 2L, 1L, 3L, 2L, 4L, 1L, 2L, 3L, 4L,
1L, 4L, 2L, 3L, 1L, 4L, 3L, 4L), att4 = c(3L, 4L, 1L, 4L, 3L,
2L, 2L, 1L, 3L, 4L, 2L, 4L, 2L, 3L, 2L, 3L, 4L, 2L, 3L, 1L),
dv = c(2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 1, 0, 1, 0, 2, 0, 1,
0, 1, 0)), row.names = c(NA, -20L), class = "data.frame")
I would really appreciate any advice here.