在mclogit中编码随机效应

4
我正在尝试使用R包mclogit中的条件Logistic模型和每个受试者的随机效应来分析离散选择实验。每个受试者(ID)评估了4个选择集,每个选择集包含4个备选项。
当我将代码写成以下形式时,

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

我遇到了以下错误:

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

我希望得到正确编码的帮助。
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个回答

1
错误来自于使用fm2而不是直接输入公式,如下所示:
out2 <- mclogit(cbind(RES, STR) ~ ASC1 + Price1 + ASC2 + Price2 + ASC3 + Price3, random = ~1|ID, data = ds.pork)

现在出现了另一个错误,但现在纯粹是关于模型规范的问题。

@user1375871,那有帮助吗? - Julius Vainora

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接