[R] multinomial conditional logit models
John Hendrickx
john_hendrickx at yahoo.com
Thu Jan 30 22:01:03 CET 2003
--- ripley at stats.ox.ac.uk wrote:
> On Thu, 30 Jan 2003, John Hendrickx wrote:
>
> > Thanks, that did the trick. My "mclgen" function can be written
> as
> >
> > mclgen <- function (datamat,catvar) {
> > ncat <- nlevels(catvar)
> > perschoice<-as.data.frame(rep(datamat,ncat))
> > perschoice<-reshape(perschoice,direction="long",
> > varying=lapply(names(datamat),rep,ncat),
> > timevar="newy")
> > perschoice<-perschoice[sort.list(perschoice$id),]
> > dep<-parse(text=paste("perschoice$",substitute(catvar),sep=""))
> > perschoice$depvar<-as.numeric(eval(dep)==perschoice$newy)
> > perschoice
> > }
> >
> > I'd still appreciate the help of R-listers on how to use the
> value of
> > "catvar" on the left-hand side of an expression within a function
> > (perschoice$"valueof(catvar)"<-perschoice$newy), and how to get R
> to
>
> Use perschoice[[catvar]], on either side.
Thanks, "perschoice[[substitue(catvar)]])<-perschoice$newy" did the
trick!
>
> > drop the reference category of a factor in an interaction effect
> > without the main effect (in
> > "clogit(depvar~occ+occ:educ+occ:black+strata(id),data=pc)").
>
> Let me guess a lot what you mean. You are using treatment contrasts
> (hence
> the `reference category') and you want the model matrix which is
> that given by depvar ~ occ + edu + occ:educ + black + occ:black
> less the
> columns for edu and black? That's a model that depends on the
> details of
> the coding, and does not make sense in the Wilkinson-Rogers
> framework.
> Could you spell this out please?
I'm trying to use "clogit" to estimate a multinomial logit model
"multinom(occ ~ educ+black)". This can be done by restructing the
data using the "mclgen" function, then estimating a model of the main
effects of "occ" for the intercept of a MNL model and interactions
between "occ" and "educ" and "black" for the effects of these
variables. "occ" is a factor with 5 levels and I expected the first
category to be dropped in all terms containing "occ". However, this
only happens for the main effect of "occ". In the interactions with
"educ" and "black", the highest category of "occ" is dropped due to
collinearity.
The model makes sense in the context of a conditional logit model and
will produce correct effects using other software packages such as
Stata and SAS. Apparently, R doesn't omit one category of a factor in
an interaction with no main effect. I'd like to know if there's an
option to make it do so nevertheless.
Many thanks for the help,
John Hendrickx
More information about the R-help
mailing list