[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:
> net <- nnet(response.variable~., data = dataset, subset=train.set)
> 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.
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
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)
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.
More information about the R-help