[R] multinomial conditional logit models
Friedrich.Leisch@univie.ac.at
Friedrich.Leisch at univie.ac.at
Thu Jan 30 12:12:03 CET 2003
>>>>> On Wed, 29 Jan 2003 11:57:20 -0800 (PST),
>>>>> John Hendrickx (JH) wrote:
> A multinomial logit model can be specified as a conditional logit
> model after restructuring the data. Doing so gives flexibility in
> imposing restrictions on the dependent variable. One application is
> to specify a loglinear model for square tables, e.g. quasi-symmetry
> or quasi-independence, as a multinomial logit model with covariates.
> Further details on this technique and examples with several packages
> are on my homepage at http://www.xs4all.nl/~jhckx/mcl/
> I've been trying to implement an MCL model in R and have been mostly
> succesful. However I'm still stuck on a few points and I'm hoping
> someone can point out how to do fix them.
> To estimate an MCL model, the data must be restructured into a
> person-choice file.
> * Each case must be duplicated "ncat" times ("ncat" is the number of
> categories of the dependent variable)
> * Each case must be identified by a strata variable (id)
> * Each duplicate must be identified by a variable indexing the
> choices (newy)
> * A dichotomous variable must indicate which duplicate corresponds
> with the respondent's choice (didep)
I'm not completely sure if I understand your target format completely,
but it sounds like reshape() could do all you want:
R> df3
id age dose1 dose2 dose4
1 1 40 1 2 3
2 2 50 2 1 3
3 3 60 1 2 3
4 4 50 2 1 3
R> reshape(df3, direction = "long", idvar=1,
varying=list(dose=c("dose1", "dose2", "dose4")))
id age time dose1
1.1 1 40 1 1
2.1 2 50 1 2
3.1 3 60 1 1
4.1 4 50 1 2
1.2 1 40 2 2
2.2 2 50 2 1
3.2 3 60 2 2
4.2 4 50 2 1
1.3 1 40 3 3
2.3 2 50 3 3
3.3 3 60 3 3
4.3 4 50 3 3
which is a (modified) example from help(reshape) ... there you find
much more examples.
Hope this helps,
Fritz
--
-------------------------------------------------------------------
Friedrich Leisch
Institut für Statistik & DSS Tel: (+43 1) 4277 38613
Universität Wien Fax: (+43 1) 4277 38639
Universitätsstraße 5 Friedrich.Leisch at univie.ac.at
A-1010 Wien, Austria http://www.ci.tuwien.ac.at/~leisch
-------------------------------------------------------------------
More information about the R-help
mailing list