0

I'm working on a homework case using Conjoint analysis and running into an error that reads:

Error in X[k, j] <- x[i, j] : incorrect number of subscripts on matrix

I have tried looking up the error and cannot find anything that is conjoint analysis related. I have compared my data with other datasets (tea, ice) that are preloaded and don't cause the error, and it appears to be the same format, just different data.

library(conjoint)

     **load in data**
caModel(y=conjointrating[1,],x=profiles)

This line of code (caModel) works just fine

caUtilities(y=conjointrating[1,],x=profiles,z=levels) 

This is where I run in to the error. It seems to come from adding in z=levels. Other functions from the Conjoint package give the same exact error. The functions that do not require z (levels) as an input do not give an error.

"conjointrating" gives 40 observations of 16 variables, representing responses to 16 product profiles.

"profiles" gives 16 observations of 5 variables, representing 16 different product profiles.

"levels" is 15 observations of 1 variable, a section of which is below:

sm_suite
lg_rm
rm_off
internet
phone

I am receiving the following error:

Error in X[k, j] <- x[i, j] : incorrect number of subscripts on matrix

I expect to get partial utilities in a matrix format with columns representing the different levels.

jay.sf
  • 60,139
  • 8
  • 53
  • 110
Bailey
  • 23
  • 2
  • My guess is that the number of levels don't match with the number of levels in either the `profiles` or the `conjointrating` data frames. – Phil Nov 08 '19 at 06:20
  • I thought that might be the case, but I can't figure out why. I've got five variables: Room - 3 levels Bus.Amenities - 3 levels Leisure - 3 levels Extras - 4 levels Rest.Delivery - 2 levels Which adds up to 15 levels overall. In "profiles", they are coded as 1-3, 1-4, or 1-2 based on number of levels, as that is how the tea dataset has theirs. They are a list of levels in "levels", which has 15 observations. The conjointrating dataframe relates to the profiles dataframe, I'm not sure how levels would play into it. Does any of this pop out at you as the problem? – Bailey Nov 08 '19 at 14:14
  • I note that in their data examples, the levels data frames like `clevn` and `tlevn` consist of a data frame with a factor variable. What is the type of variable in your `levels` data frame? – Phil Nov 08 '19 at 15:16

1 Answers1

1

Had the same issue with my conjoint analysis. Like Phil I noticed the preloaded datasets are all data frames. So I just converted my data files to data.frame and it works now. In your case

profiles <- data.frame(profiles)
levels <- data.frame(levels)

should do it.

msc
  • 11
  • 1