7

I have a set of results from a choice experiment that I am trying to analyse using the mlogit function in R. My data set is shown below, where each STR value represents the three choices in a single choice experiment, 'CHOICE' is a binary variable indicating which the participant selected, and columns C-G detail the attributes of each choice (D-G being binary variables - 1=yes, 0=no).

image of data set

I am trying to run the model as:

m <- mlogit(CHOICE ~ PRICE + GreenStatement + Certification +
            MediumBrand + HighBrand,
            SP1, choice = "CHOICE", shape = "long", alt.levels = "STR")

but get the error "contrasts can be applied only to factors with 2 or more levels". I have tried running 'as.factor' on all the variables, so they are different factors, and asking R to display a data summary tells me that they all have 2 or more levels. But I still get this error. Would anyone please be able to help me identify (and fix!) the source of this error?

Thanks.

Max Ghenis
  • 780
  • 1
  • 9
  • 17

1 Answers1

10

See Answer Here - https://stackoverflow.com/questions/18171246/error-in-contrasts-when-defining-a-linear-model-in-r

There are factors that you are using that either have only 1 distinct value or are NA

myloginid
  • 201
  • 2
  • 7