【问题标题】:How to use mnlogit with different choice set for different alternatives如何将 mnlogit 与不同的选择集用于不同的选择
【发布时间】:2018-02-19 05:20:23
【问题描述】:

我有一个类似于下面的数据集,其中我为不同的选择设置了不同的选择。例如对于chid=1,我们有alt1alt4,但对于chid=2,我们有alt5alt9

mode    income  alt     price   catch chid  weight
FALSE   7083    alt1    157.93  0.0678  1   10
FALSE   7083    alt2    157.93  0.2601  1   10
TRUE    7083    alt3    182.93  0.5391  1   10
FALSE   7083    alt4    157.93  0.0503  1   10
FALSE   1250    alt5    15.11   0.1049  2   20
FALSE   1250    alt6    10.53   0.1574  2   20
TRUE    1250    alt7    34.53   0.4671  2   20
FALSE   1250    alt8    15.11   0.0451  2   20
FALSE   3750    alt9    161.87  0.5333  2   20
TRUE    3750    alt10   24.33   0.2413  3   5
FALSE   3750    alt11   59.33   1.0266  3   5
FALSE   3750    alt12   161.87  0.4522  3   5
TRUE    7083    alt1    157.93  0.0678  4   2
FALSE   7083    alt2    157.93  0.2601  4   2
FALSE   7083    alt3    182.93  0.5391  4   2
FALSE   7083    alt4    157.93  0.0503  4   2
FALSE   1250    alt5    15.11   0.1049  5   40
TRUE    1250    alt6    10.53   0.1574  5   40
FALSE   1250    alt7    34.53   0.4671  5   40
FALSE   1250    alt8    15.11   0.0451  5   40
FALSE   3750    alt9    161.87  0.5333  5   40
FALSE   3750    alt10   24.33   0.2413  6   30
TRUE    3750    alt11   59.33   1.0266  6   30
FALSE   3750    alt12   161.87  0.4522  6   30
FALSE   7083    alt1    157.93  0.0678  7   25
TRUE    7083    alt2    157.93  0.2601  7   25
FALSE   7083    alt3    182.93  0.5391  7   25
FALSE   7083    alt4    157.93  0.0503  7   25
TRUE    1250    alt5    15.11   0.1049  8   20
FALSE   1250    alt6    10.53   0.1574  8   20
FALSE   1250    alt7    34.53   0.4671  8   20
FALSE   1250    alt8    15.11   0.0451  8   20
FALSE   3750    alt9    161.87  0.5333  8   20
FALSE   3750    alt10   24.33   0.2413  9   15
FALSE   3750    alt11   59.33   1.0266  9   15
TRUE    3750    alt12   161.87  0.4522  9   15
FALSE   7083    alt1    157.93  0.0678  10  8
FALSE   7083    alt2    157.93  0.2601  10  8
FALSE   7083    alt3    182.93  0.5391  10  8
TRUE    7083    alt4    157.93  0.0503  10  8
FALSE   1250    alt5    15.11   0.1049  11  6
FALSE   1250    alt6    10.53   0.1574  11  6
FALSE   1250    alt7    34.53   0.4671  11  6
TRUE    1250    alt8    15.11   0.0451  11  6
FALSE   3750    alt9    161.87  0.5333  11  6
FALSE   3750    alt10   24.33   0.2413  12  12
FALSE   3750    alt11   59.33   1.0266  12  12
TRUE    3750    alt12   161.87  0.4522  12  12
FALSE   1250    alt5    15.11   0.1049  13  15
FALSE   1250    alt6    10.53   0.1574  13  15
FALSE   1250    alt7    34.53   0.4671  13  15
FALSE   1250    alt8    15.11   0.0451  13  15
TRUE    3750    alt9    161.87  0.5333  13  15

我可以将 MNL 用于每个单独的替代方案的情况。

dat1 <- fread('test_mnlogit.csv')
dat2 <- mlogit.data(data = dat1,choice = "mode", shape = "long", varying = 3:4, alt.var = "alt",chid.var = "chid")
fm <- formula(mode~-1+price+catch)
fit <- mnlogit(fm, dat2)

但是当我对以下数据类型使用类似代码时,我得到以下错误。

Error in mnlogit(fm, dat2) : 
  Mismatch between number of rows in data and number of choices.

你可以在这里下载测试数据。

【问题讨论】:

    标签: r mlogit


    【解决方案1】:

    据我所知,mlogit 不处理不同的选择集。如果全能选择集包含 12 个备选方案,则所有案例都必须有相同的 12 个选择。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-09
      • 2012-08-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多