[R] FW: Reference category for explanatory factors
Jason Ferris
J.Ferris at latrobe.edu.au
Wed Nov 14 02:42:30 CET 2007
Dear Brian,
Thanks for your prompt response.
I had tried both 'relevel' and 'reorder'
preg_fyear5a.msm<-msm(outcome~ipi, subject=id, data, qmatrix=crudemat,
exacttimes=TRUE, covariates=~factor(relevel(year5a),1))
preg_fyear5a.msm<-msm(outcome~ipi, subject=id, data, qmatrix=crudemat,
exacttimes=TRUE, covariates=~factor(reorder(year5a),1))
But after reading your suggestion I tried it again in other forms...
The following worked for me:
preg_fyear5a.msm<-msm(outcome~ipi, subject=id, data, qmatrix=crudemat,
exacttimes=TRUE, covariates=~relevel(factor(year5a),1))
I also found out that factor use a range with the first factor (i.e., 1)
representing the first item (in my case 0) - so I had to add 1 to use
the value 1 as the reference group.
Yay!
Jase
-----Original Message-----
From: Prof Brian Ripley [mailto:ripley at stats.ox.ac.uk]
Sent: Tuesday, 13 November 2007 10:10 PM
To: Jason Ferris
Cc: r-help at r-project.org
Subject: Re: [R] FW: Reference category for explanatory factors
On Tue, 13 Nov 2007, Jason Ferris wrote:
> (Oops first mistake was posting to the wrong area)
>
> I am not sure what is needed to be posted in terms of what I have done
> but will explain nonetheless.
>
> I am using the msm.package and trying to specify my reference category
> for an outcome covariate. The following command line works:
>
> ## age of respondent - using year5a: categorical
> preg_fyear5a.msm<-msm(outcome~ipi, subject=id, data, qmatrix=crudemat,
> exacttimes=TRUE, covariates=~factor(year5a))
>
> However, in the dataset (data) the reference category 0 is a
moderately
> small cell, so I would like to change it to 1 which is much large.
> There are 5 categories in the covariates year5a (0,1,2,3,4).
>
> I have tried all sorts of approaches with 'ordered' and 'level' but no
> love.
Which is of not much use to us, as we don't know what you tried nor what
went wrong. See
?relevel
?contr.treatment (see 'base')
?C (to specify a contrast for a term)
>
> Cheers,
>
> Jase
>
> PS. Operating in Win XP on a fast machine!
>
> Jason Ferris
> Research Officer
> Australian Research Centre in Sex, Health and Society
> Level 1, 215 Franklin St
> Melbourne
> VIC 3000
> P: 61 (0)3 9285 5282
> F: 61 (0)3 9285 5220
--
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