客户面临一系列独特的选择。例如:
客户 1 在备选方案 A1、A2、A3、A4 之间进行选择;客户 1 在选项 B1、B2 之间进行选择;客户 2 在备选方案 C1、C2、C3 之间进行选择;客户 2 在备选方案 D1、D2、D3 等之间进行选择
任何 R 包都可以处理它吗?
例如.csv
CHOICE,CUSTOMER,CHID,ALT,DIST,INCOME
1,1,1,1,100,70
0,1,1,2,372,70
0,1,1,3,417,70
0,1,1,4,180,70
1,1,2,1,68,70
0,1,2,2,354,70
0,2,3,1,68,100
0,2,3,2,354,100
1,2,3,3,399,100
1,2,4,1,180,100
0,2,4,2,100,100
0,2,4,3,80,100
mlogit失败
> library(mlogit)
> ExData <- read.csv("C:/Users/John/Desktop/R/example.csv")
> MLData <- mlogit.data(ExData, shape="long", choice="CHOICE", chid.var="CHID", id.var="CUSTOMER", alt.var="ALT")
> res <- mlogit(CHOICE~DIST|INCOME, data=MLData, shape="long", alt.var="ALT")
Error in `row.names<-.data.frame`(`*tmp*`, value = paste(chid, alt, sep = ".")) :
duplicate 'row.names' are not allowed
In addition: Warning message:
non-unique values when setting 'row.names': ‘2.1’, ‘2.2’, ‘3.3’
而对于 example1.csv,其中的替代品数量是恒定的
CHOICE,CUSTOMER,CHID,ALT,DIST,INCOME
1,1,1,1,100,70
0,1,1,2,372,70
0,1,1,3,417,70
0,1,2,1,180,70
1,1,2,2,68,70
0,1,2,3,354,70
0,2,3,1,68,100
0,2,3,2,354,100
1,2,3,3,399,100
1,2,4,1,180,100
0,2,4,2,100,100
0,2,4,3,80,100
一切都很好。