[R] multinomial logistic regression with equality constraints?

Walter Mebane wrm1 at macht.arts.cornell.edu
Wed Feb 7 04:38:50 CET 2007


Roger,

 > Error in if (logliklambda < loglik) bvec <- blambda :
 > 	missing value where TRUE/FALSE needed
 > In addition: Warning message:
 > NaNs produced in: sqrt(sigma2GN)

That message comes from the Newton algorithm (defined in source file
multinomMLE.R).  It would be better if we bullet-proofed it a bit
more.  The first thing is to check the data.  I don't have the
multinomLogis() function, so I can't run your code.  But do you really
mean

 > for(i in 1:length(choice)) {
and
 > dim(counts) <- c(length(choice),length(choice))

Should that be

  for(i in 1:n) {
and
  dim(counts) <- c(n, length(choice))

or instead of n, some number m > length(choice).  As it is it seems to
me you have three observations for three categories, which isn't going
to work (there are five coefficient parameters, plus sigma for the
dispersion).

Otherwise, you can get more diagnostic messages by setting a
print.level greater than 32.  To have a bad value of sigma2GN is
unusual.

I should mention that supplying starting values won't help you,
because for multinomRob's primary purpose the ML estimates are
themselves no more than starting values.  So if you supply starting
values it will skip the ML step.

Walter

Roger Levy writes:
 > Hi again Jasjeet, Walter,
 > 
 > I have a further question about an error message I get when running 
 > multinomRob.  I am simulating a dataset where I look at the effect of 
 > making a previous categorical choice on the probability of making the 
 > same choice later on.  Given the following code:
 > 
 > 
 > n <- 20
 > choice <- c("A","B","C")
 > intercepts <- c(0.5,0.3,0.2)
 > prime.strength <- rep(0.4,length(intercepts))
 > counts <- c()
 > for(i in 1:length(choice)) {
 >    u <- intercepts[1:length(choice)]
 >    u[i] <- u[i] + prime.strength[i]
 >    counts <- c(counts,rmultinomial(n = n, pr = multinomLogis(u)))
 > }
 > dim(counts) <- c(length(choice),length(choice))
 > counts <- t(counts)
 > row.names(counts) <- choice
 > colnames(counts) <- choice
 > data <- data.frame(Prev.Choice=choice,counts)
 > 
 > for(i in 1:length(choice)) {
 >    data[[paste("last",choice[i],sep=".")]] <- 
 > ifelse(data$Prev.Choice==choice[i],1,0)
 > }
 > 
 > multinomRob(list(A ~ last.A ,
 >                   B ~ last.B ,
 >                   C ~ last.C - 1 ,
 >                   ),
 >              data=data,
 >              print.level=1)
 > 
 > 
 > I get the following error:
 > 
 > 
 > multinomRob(): Grouped MNL Estimation
 > Error in if (logliklambda < loglik) bvec <- blambda :
 > 	missing value where TRUE/FALSE needed
 > In addition: Warning message:
 > NaNs produced in: sqrt(sigma2GN)
 > 
 > 
 > It's not clear to me what this error means, or why the resulting dataset 
 > would be problematic for MLE estimation.
 > 
 > Many thanks once again!
 > 
 > Roger



More information about the R-help mailing list