首页 > 解决方案 > mlogit:具有截距的多项概率模型返回错误

问题描述

我在使用mlogit包拟合多项式概率时遇到问题。

我对具有通用系数的单个替代特定协变量的模型感兴趣(此处有关符号的更多详细信息)。简而言之,2001 年的受访者面临 6 个选择。每个受访者都拥有与每个选项相关的效用分数。选择的分布来自真实数据,但出于本练习的目的,效用分数(0 到 100 分)是随机生成的,以避免多重共线性。由于选择场景是真实的,因此估计了具有截距的模型。

完整数据可在此处获得,将数据转换为长格式的代码可在此处获得。下面我提供了原始数据的头部,我随后将其转换为长格式。

#准备样本数据

    library(mlogit)
    data_head<-head(original_data) ##from https://pastebin.com/28XpX7A4
    DT_head_long <- mlogit.data(data_head, shape="wide", varying=1:6, choice="choice_with_6_alternative")  

   DT_head_long<-structure(list(choice_with_6_alternative = c(FALSE, FALSE, FALSE, 
    TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, 
    FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, 
    TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, 
    FALSE, FALSE, FALSE, TRUE, FALSE, FALSE), alt = c(1, 2, 3, 4, 
    5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 
    2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6), random_utility = c(18, 25, 
    12, 13, 2, 37, 3, 21, 38, 3, 6, 51, 8, 33, 32, 9, 6, 29, 43, 
    6, 5, 25, 15, 17, 24, 11, 12, 29, 33, 13, 16, 22, 12, 5, 21, 
    3), chid = c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 
    3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 
    5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L)), reshapeLong = list(varying = structure(list(
    random_utility = c("random_utility.1", "random_utility.2", 
    "random_utility.3", "random_utility.4", "random_utility.5", 
    "random_utility.6")), v.names = "random_utility", times = c(1, 
    2, 3, 4, 5, 6)), v.names = "random_utility", idvar = "chid", 
    timevar = "alt"), row.names = c("1.1", "1.2", "1.3", "1.4", 
    "1.5", "1.6", "2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "3.1", 
    "3.2", "3.3", "3.4", "3.5", "3.6", "4.1", "4.2", "4.3", "4.4", 
    "4.5", "4.6", "5.1", "5.2", "5.3", "5.4", "5.5", "5.6", "6.1", 
    "6.2", "6.3", "6.4", "6.5", "6.6"), class = c("mlogit.data", 
    "data.frame"), index = structure(list(chid = structure(c(1L, 
    1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 
    3L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 
    6L, 6L, 6L), .Label = c("1", "2", "3", "4", "5", "6"), class = "factor"), 
    alt = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 
    5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 
    2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L), .Label = c("1", 
    "2", "3", "4", "5", "6"), class = "factor")), class = "data.frame", row.names = c("1.1", 
    "1.2", "1.3", "1.4", "1.5", "1.6", "2.1", "2.2", "2.3", "2.4", 
    "2.5", "2.6", "3.1", "3.2", "3.3", "3.4", "3.5", "3.6", "4.1", 
    "4.2", "4.3", "4.4", "4.5", "4.6", "5.1", "5.2", "5.3", "5.4", 
    "5.5", "5.6", "6.1", "6.2", "6.3", "6.4", "6.5", "6.6")), choice = "choice_with_6_alternative")

#用probit=TRUE拟合模型

probit <- mlogit(choice_with_6_alternative ~ random_utility, 
  data=DT_head_long, 
  probit=TRUE)

//The model returns the error: 

Error in if (is.null(initial.value) || lnl <= initial.value) break : 
  missing value where TRUE/FALSE needed

#用probit=FALSE拟合模型

//model without intercept: runs well
    probit <- mlogit(choice_with_6_alternative ~ random_utility|0, 
      data=DT_head_long, 
      probit=FALSE)

//model with intercept: runs well
    logit <- mlogit(choice_with_6_alternative ~ random_utility, 
      data=DT_head_long, 
      probit=FALSE)

#我的问题:

1-错误与什么有关?
2- 模型是否未识别?

标签: rstatisticsmultinomialmlogit

解决方案


推荐阅读