R mlogit-Error系统在计算上是单数的:倒数条件数

时间:2015-08-19 14:58:03

标签: r mixed-models mlogit

我在R中使用库(mlogit)而且我被困在这个看起来像这样的特定数据集

 CustomerID Item Price Calories Choice
           1  200  1.99      490    NO 
           1  312  4.99      887    NO 
           1  560  5.19      910    NO 
           1  700  4.79      690    NO 
           1  909  4.89      660    NO 
           1 1705  4.00      840    NO 

共有187个项目和4个customerID(1,2,3和4)。每个客户都会看到一组187个项目,他们根据价格和卡路里选择一个项目。 4位客户的价格和卡路里保持不变。

> str(data)
'data.frame':   748 obs. of  5 variables:
 $ CustomerID: int  1 1 1 1 1 1 1 1 1 1 ...
 $ Item      : Factor w/ 187 levels "200","231","232",..: 1 11 14 15 18 25 33 34 36 39 ...
 $ Price     : num  1.99 4.99 5.19 4.79 4.89 4 4 4 4 6.21 ...
 $ Calories  : int  490 887 910 690 660 840 1638 1559 1530 1559 ...
 $ Choice    : Factor w/ 2 levels "NO ","YES": 1 1 1 1 1 1 1 1 1 1 ...

我按照以下方式根据mlogit命令格式化数据: -

m<- mlogit.data(data, choice="Choice", shape="long", alt.levels=c("200",    "231",    "232",    "240",.....(*all the 187 'Item' here)*))

给了我这个: -

head(m)
      CustomerID Item Price Calories Choice
1.200          1  200  1.99      490    NO 
1.231          1  231  1.19      320    YES
1.232          1  232  1.49      320    NO 
1.240          1  240  4.79      590    NO 
1.250          1  250  2.39      490    NO 
1.253          1  253  4.49      691    NO 

我的数据集按照CutomerID和Item排序,正如我之前在上一个问题中所读到的那样,它可能会导致问题。

我尝试了几个公式,但没有一个运行

Tr.ml <- mlogit(Choice ~0|Price+Calories|0,m)
Error in solve.default(H, g[!fixed]) : 
  Lapack routine dgesv: system is exactly singular: U[548,548] = 0
In addition: There were 50 or more warnings (use warnings() to see the first 50)

价格和卡路里之间的相关性约为43%

cor(m$Price,m$Calories)
[1] 0.429796

我也试过这个: -

Tr.ml <- mlogit(Choice ~Price+Calories,m)
Error in solve.default(H, g[!fixed]) : 
  system is computationally singular: reciprocal condition number = 1.06243e-23
In addition: There were 50 or more warnings (use warnings() to see the first 50)

有人可以提供一些解决此错误的想法吗?我已经待了两个星期了。

0 个答案:

没有答案