私の主な質問は次のとおりです。 のpredict()
関数からどのような確率が与えられ、パッケージおよびおよび の確率mnlogit()
とどのように異なりますか?nnet
mlogit
いくつかの背景として、選択メーカーの選択肢がわからないため、個々の特定の変数のみから結果をモデル化しようとしています。特定のモデルについて、3 つすべてから各結果について同じ予測確率を取得できますが、mnlogit
いくつかの確率のセットが得られます。最初のセットは、他のパッケージによって与えられたものと似ています。のビネットを見ると、mnlogit
個人固有の確率を取得できることがわかりますが、それは私が抽出したものだとは思いませんでした (?)、また、それらを取得するためにモデルが指定されているとは思いませんでした。
以下の例を見てください (最もコンパクトなものではありませんが、これらの関数を学習するときに使用していたものです)、mnlogit
いくつかの確率のセットが得られることがわかります。
library(data.table);library(stringr);library(nnet);library(mlogit);library(mnlogit)
data("ModeCanada", package = "mlogit")
bususers <- with(ModeCanada, case[choice == 1 & alt == "bus"])
ModeCanada <- subset(ModeCanada, !case %in% bususers)
ModeCanada <- subset(ModeCanada, nchoice == 4)
ModeCanada <- subset(ModeCanada, alt != "bus")
ModeCanada$alt <- ModeCanada$alt[drop = TRUE]
KoppWen00 <- mlogit.data(ModeCanada, shape='long', chid.var = 'case',
alt.var = 'alt', choice='choice',
drop.index=TRUE)
data("ModeCanada", package = "mlogit")
busUsers <- with(ModeCanada, case[choice == 1 & alt == "bus"])
Bhat <- subset(ModeCanada, !case %in% busUsers & alt != "bus" &
nchoice == 4)
Bhat$alt <- Bhat$alt[drop = TRUE]
head(ModeCanada)
Mode = data.table(ModeCanada)
# Some additional editing in order to make it more similar to the typical data sets I work with
Bhat2 = data.table(KoppWen00)
Bhat2[,Choice:=gsub("\\.","",str_sub(row.names(KoppWen00),5,-1))][,id:=as.character(as.numeric(str_sub(row.names(Bhat),1,4)))]
Bhat2 = Bhat2[choice=="TRUE"][,c("Choice","urban","income","id"),with=F]
# nnet package
ml.nn<- multinom(Choice ~ urban + income,
Bhat2)
tmp = data.table(cbind(Bhat2, predict(ml.nn, type="probs", newdata=Bhat2)))
# nnet predictions
tmp[urban=="0" & income==45 & Choice=="air"][1,c("Choice", "urban", "income" , "air","car","train"),with=F]
# mlogit package
ml <- mlogit(Choice ~ 1| urban + income,shape="wide",
Bhat2)
pml = data.table(cbind(Bhat2, predict(ml,mlogit.data(Bhat2, shape="wide", choice="Choice"))))
# mlogit predictions
unique(pml[Choice=="air" & urban=="0" & income==45 ][,c("Choice", "urban", "income" , "air","car","train"),with=F])
# mnlogit packages
mln.MC <- mnlogit(Choice ~ 1| urban + income, mlogit.data(Bhat2,choice = "Choice",shape="wide"))
preddata = data.table(cbind(mlogit.data(Bhat2,choice = "Choice",shape="wide"), predict(mln.MC)))
# mnlogit predictions, returns several probabilities for each outcome
preddata[Choice==TRUE & urban=="0" & income==45 & alt == "air"]
追伸!タグ「mnlogit」を自由に追加してください。