# Re: [R] Multinomial Logit Regression

From: Ruben Roa Ureta <rroa_at_udec.cl>
Date: Sat, 12 Apr 2008 10:24:13 -0400 (CLT)

> 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

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sat 12 Apr 2008 - 14:27:10 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 12 Apr 2008 - 15:30:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.