mclogit中的编码随机效应

时间:2018-12-25 21:09:46

标签: r logistic-regression mixed-models choice

我正在尝试使用条件逻辑模型分析离散选择实验,并使用来自R软件包mclogit的mclogit函数对每个受试者产生随机影响。每个科目(ID)对4个选择集进行评分,其中包括4个选择。

我收到错误

  

attributes(.Data)中的错误<-c(attributes(.Data),attrib):无法   在符号上设置属性

当我将其编码为

  

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

我希望获得正确编码的帮助。

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 个答案:

答案 0 :(得分:0)

错误来自使用fm2而不是直接输入公式,如

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

现在还有另一个错误,但现在纯粹是关于模型规范。