[R] Multinomial Logit Regression

Ruben Roa Ureta rroa at udec.cl
Sat Apr 12 16:24:13 CEST 2008


> Hi again. I believe that I described the things bad before.
>
> I want to make the analysis with a sample data (train.set) of dataset for
> later see if the predictions adjust to the rest of data non selected with
> the sample train.
>
> Then, of the same form in glm:
>
> library(nnet)
> net <- nnet(response.variable~., data = dataset, subset=train.set)
>
> Or...
>
> z=zelig(response.variable ~., model = "mlogit",data=dataset, subset=train)
>
> But this don't work. I don't know yet if I do the MLR of this way. The
> function multinom from nnet library maybe can help but I don't know how
> can be the sintaxis in my case.

Hi Fede,
Here is how I do multinomial logistic regression with the multinom
function in package nnet. Since the response is multinomial I create a
matrix of response variables and use that matrix in the multinom formula
argument.

library(nnet)

ParasCountsF <-
as.matrix(subset(ParasCounts,Sx==2,select=c(Zone,Bodymass,P1,P2,P3,P4,P5,P6)))
MNm0.F <- multinom(ParasCountsF[,3:8]~1,Hess=TRUE)
MNm1a.F <- multinom(ParasCountsF[,3:8]~as.factor(ParasCountsF[,1]),Hess=TRUE)
MNm1b.F <- multinom(ParasCountsF[,3:8]~ParasCountsF[,2],Hess=TRUE)
MNm1.F <-
multinom(ParasCountsF[,3:8]~as.factor(ParasCountsF[,1])+ParasCountsF[,2],Hess=TRUE)
MNm2.F <-
multinom(ParasCountsF[,3:8]~as.factor(ParasCountsF[,1])*ParasCountsF[,2],Hess=TRUE,maxit=200)
anova(MNm0.F,MNm1a.F,MNm1b.F,MNm1.F,MNm2.F)

In the code above, Zone and Bodymass are the predictors, the former
categorical (six levels) and the latter continuous, and the last six
columns are the multinomial response variable. These are the number of
parasites of each of six types in the whole body of 100 fish. The question
was whether there were differences in parasite load among the zones,
accounting for different size of fish. The models are compared at the end
by likelihood ratio test, and of course, by inspecting the AIC.
Maybe you can use the same approach. It worked for me, though I didn't
care about a training sample.
Rubén



More information about the R-help mailing list