您知道为什么 mlogit 函数会产生错误吗?
不允许重复的 'row.names'
如果你问我,行名不重复。这真让我抓狂。
> mlORDERS <- mlogit.data(ORDERS, choice="PAYMENT_METHOD", shape="wide", id.var="ORDER_NUMBER")
> head(mlORDERS)
ORDER_NUMBER CUSTOMER_ID PAYMENT_METHOD GROSS_RETAIL_TOTAL GENDER SOLVENCY_SCORE EXISTING_CUSTOMER chid alt
1.CCA 1.010311e+13 1402114 FALSE 1271.6 male 527 TRUE 1 CCA
1.INV 1.010311e+13 1402114 TRUE 1271.6 male 527 TRUE 1 INV
1.PPA 1.010311e+13 1402114 FALSE 1271.6 male 527 TRUE 1 PPA
1.PRE 1.010311e+13 1402114 FALSE 1271.6 male 527 TRUE 1 PRE
2.CCA 1.010311e+13 758980 FALSE 53.9 female 385 TRUE 2 CCA
2.INV 1.010311e+13 758980 TRUE 53.9 female 385 TRUE 2 INV
> str(mlORDERS)
Classes ‘mlogit.data’ and 'data.frame': 100 obs. of 9 variables:
$ ORDER_NUMBER : num 1.01e+13 1.01e+13 1.01e+13 1.01e+13 1.01e+13 ...
$ CUSTOMER_ID : int 1402114 1402114 1402114 1402114 758980 758980 758980 758980 217054 217054 ...
$ PAYMENT_METHOD : logi FALSE TRUE FALSE FALSE FALSE TRUE ...
$ GROSS_RETAIL_TOTAL: num 1271.6 1271.6 1271.6 1271.6 53.9 ...
$ GENDER : Factor w/ 2 levels "male","female": 1 1 1 1 2 2 2 2 2 2 ...
$ SOLVENCY_SCORE : int 527 527 527 527 385 385 385 385 543 543 ...
$ EXISTING_CUSTOMER : logi TRUE TRUE TRUE TRUE TRUE TRUE ...
$ chid : num 1 1 1 1 2 2 2 2 3 3 ...
$ alt : chr "CCA" "INV" "PPA" "PRE" ...
- attr(*, "index")='data.frame': 100 obs. of 3 variables:
..$ chid: Factor w/ 25 levels "1","2","3","4",..: 1 1 1 1 2 2 2 2 3 3 ...
..$ alt : Factor w/ 4 levels "CCA","INV","PPA",..: 1 2 3 4 1 2 3 4 1 2 ...
..$ id : Factor w/ 25 levels "10103114445506",..: 20 20 20 20 1 1 1 1 18 18 ...
- attr(*, "choice")= chr "PAYMENT_METHOD"
> mlModel <- mlogit(ORDERS$PAYMENT_METHOD ~ 1 | ORDERS$GENDER + ORDERS$SOLVENCY_SCORE, data=mlORDERS)
Error in `row.names<-.data.frame`(`*tmp*`, value = value) :
duplicate 'row.names' are not allowed
In addition: Warning message:
non-unique value when setting 'row.names': ‘NA.NA’
我什至尝试过make.unique(rownames(mlORDERS))
,which(duplicated(mlORDERS[, 1]))
但这也无济于事。