[R] multinomial conditional logit models

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Thu Jan 30 20:58:03 CET 2003

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.

> 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?

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-help mailing list