Coding random effect in mclogit

Viewed 1462

I am trying analyze a discrete choice experiment using a conditional logistic model with a random effect for each subject using the mclogit function from the R package mclogit. Each subject (ID) rated 4 choice sets consisting of 4 alternatives.

I get the error

Error in attributes(.Data) <- c(attributes(.Data), attrib) : cannot set attribute on a symbol

when I code it as

out2 <- mclogit(fm2, random=~1|ID, data=ds.pork)

I was hoping to get help coding this properly.

library(support.CEs)
library(survival)
library(mclogit)

d.pork <- Lma.design(
  attribute.names = list(
    Price = c("100", "130", "160", "190")),
  nalternatives = 3,
  nblocks = 4,
  row.renames = FALSE,
  seed = 987)

data(pork)

dm.pork <- make.design.matrix(
  choice.experiment.design = d.pork,
  optout = TRUE,
  continuous.attributes = c("Price"),
  unlabeled = FALSE)

ds.pork <- make.dataset(
  respondent.dataset = pork,
  choice.indicators =
    c("q1", "q2", "q3", "q4"),
  design.matrix = dm.pork)

ds.pork$ID<-factor(ds.pork$ID)

fm1 <- RES ~ ASC1 + Price1 + ASC2 + Price2 + ASC3 + Price3 + strata(STR)
fm2<-cbind(RES, STR) ~ ASC1 + Price1 + ASC2 + Price2 + ASC3 + Price3

out1 <- clogit(fm1, data = ds.pork)
out2 <- mclogit(fm2, random=~1|ID, data=ds.pork)
1 Answers

The error comes from using fm2 rather than directly entering the formula, as in

out2 <- mclogit(cbind(RES, STR) ~ ASC1 + Price1 + ASC2 + Price2 + ASC3 + Price3, random = ~1|ID, data = ds.pork)

Now there is another error but now it's purely about model specification.

Related