0

I have the following data:

Class   Batch   Parity  EB
0   2   2   842.8302684
0   2   3   1435.313822
0   2   3   615.32252
1   3   2   428.0919074
1   3   3   629.6284765
1   3   2   428.0919074
.   .   .   .
.   .   .   .

I am running the multinomial regression using mlogit package but having problem back:

Error in relevel.default(attr(mf, "index")[["alt"]], reflevel) : 
  'relevel' only for factors

Could you please have a look to see where I am wrong. The model is:

model<-mlogit(Class~EB+DFS+Batch+Parity, data=dat, reflevel="1")

Class and Batch are categorical with Class ( 0 or 1) and Batch (1 to 6). Before running the model I applied this to transfer Class and Batch to factors:

dat$Class<-as.factor(dat$Class)
dat$Batch<-as.factor(dat$Batch)

Thank you very much!

hieu
  • 135
  • 3
  • 11
  • @eipi10: Class is currently coded as 0 or 1, and that is why I applied as.factor to make them to factor. Additionally, when I code Class and true/false the error is still the same – hieu May 04 '16 at 02:59
  • 1
    I looked into the mlogit function. It seems like it works best on data frames that are of class mlogit.data. Luckily, you can use mlogit.data() on your data.frame to make it of class mlogit.data. Have you looked into this? – AOGSTA May 04 '16 at 04:53
  • @Arman: I applied your suggestion and it worked. Thanks – hieu May 04 '16 at 06:13

1 Answers1

1

I had the same error and then realized I was using the actual dataset and not the dataset reshaped with "mlogit.data()".

Lucas
  • 11
  • 1