number of valid columns for ChoiceModelR

25 Views Asked by At

I'm conducting tests to see how the ChoiceModelR package works for conjoint and MaxDiff analysis. I have created a test conjoint table as shown below:

#Define the brands and their corresponding prices
brands <- c("ACROS", "ACROS", "GRS", "GRS", "GRS", "MABE", "MABE", "MABE", "WHIRLPOOL")
prices <- c(2299, 1599, 2299, 2069.1, 1169.1, 2299, 1499, 2799, 2899)

#Create sample data for stoves
UnitID <- rep(1:27, each = 9)
Set <- rep(1:9, times = 27)
Alt <- rep(1:9, each = 9)
Brand <- rep(brands, each = 3)
Price <- rep(prices, each = 3)

#Create the final dataframe
stoves_data <- data.frame(UnitID = UnitID, Set = Set, Alt = Alt, Brand = Brand, Price = Price)

#Show the first rows of the data table
head(stoves_data)
stoves_data

When I apply the code from the package, which is as follows:

Define the encoding codes for categorical variables
xcoding <- rep(0, 3) # There are 3 categorical variables: UnitID, Set, Alt

Create an empty list of demographic data, as we are not using it in this example
demos <- matrix(NA, nrow = nrow(estufas_data), ncol = 0)

Define the parameters for the Markov Chain Monte Carlo (MCMC)
mcmc_params <- list(R = 4000, use = 2000)

Define options for model estimation
options <- list(none = FALSE, save = TRUE, keep = 1)

Call the choicemodelr function
out <- choicemodelr(data = estufas_data, xcoding = xcoding, demos = demos, mcmc = mcmc_params, options = options)  

It gives me the following error:

Error: length of xcoding is not equal to number of attributes

0

There are 0 best solutions below