[R-sig-ME] (no subject)
Greg.Snow at imail.org
Wed Jan 28 18:21:10 CET 2009
The formatting is a bit garbled, but hopefully this addresses the correct question.
You ask if there is a way to change which level in a factor is the baseline with treatment contrasts (the default) in one line rather than using relevel on the factor before calling mle (is this correct?).
First one issue to be aware of is whether the baseline level is considered to be a property of the data or a property of the analysis (some packages (maybe most or all other than S/R) don't allow for this distinction so people don't consider it, even though it can be quite important).
If the baseline level (or even the full ordering) is a property of the data (or even if the correct set of contrasts to be used is a property of the data), then this information should be stored as part of the meta-data for the factor. R/S allows for you to set the ordering of the levels in the factor as part of creating/editing the factor itself. This information will then be used for analysis and plotting of that factor (unless overridden). We can even set up a set of contrasts to be used for the factor (see ?contrasts) that will override the default (but can also be overridden in a specific analysis).
In my opinion, in most cases the order of the levels is either irrelevant or a property of the data itself and therefore should be set as part of the data, not the analysis (and this saves work by not having to specify the order in every analysis/plot/etc.)
If you want to keep the current order and just override some specifics for one particular analysis, then one option is to use the C function (note uppercase) along with the appropriate contr function. For example:
> lm( Sepal.Width~Species, data=iris)
lm(formula = Sepal.Width ~ Species, data = iris)
(Intercept) Speciesversicolor Speciesvirginica
3.428 -0.658 -0.454
> lm( Sepal.Width~C(Species,contr.treatment,base=2), data=iris)
lm(formula = Sepal.Width ~ C(Species, contr.treatment, base = 2), data = iris)
(Intercept) C(Species, contr.treatment, base = 2)1
C(Species, contr.treatment, base = 2)3
> 3.428 -0.658
Note that the intercept in the 2nd case is the mean of Species 2 (as can be seen by combining the values from the 1st case) and that the first slope changed sign but not absolute value since it is still the difference between the first 2 species, just which one is baseline changed.
Hope this helps,
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
greg.snow at imail.org
> -----Original Message-----
> From: r-sig-mixed-models-bounces at r-project.org [mailto:r-sig-mixed-
> models-bounces at r-project.org] On Behalf Of Lawrence Lee
> Sent: Tuesday, January 27, 2009 12:21 PM
> To: r-sig-mixed-models at r-project.org
> Subject: Re: [R-sig-ME] (no subject)
> Hi all, Thanks a lot. Besides, is there a way to do this task
> just in 1 line of code? Thats is, combine age<-relevel (age,ref =
> "3")lme( ...) into: lme(...) and have the same effect? Lawrence> From:
> a.renwick at abdn.ac.uk> To: lawandqueen at hotmail.com; r-sig-mixed-
> models at r-project.org> Date: Tue, 27 Jan 2009 09:51:54 +0000> Subject:
> RE: [R-sig-ME] (no subject)> > If I understand your question correctly
> you need to relevel your variable:> age<-relevel(age,ref="3")> Then
> rerun the model and age3 should be used as the reference group> > -----
> Original Message-----> From: r-sig-mixed-models-bounces at r-project.org
> [mailto:r-sig-mixed-models-bounces at r-project.org] On Behalf Of Lawrence
> Lee> Sent: 27 January 2009 09:24> To: r-sig-mixed-models at r-project.org>
> Subject: [R-sig-ME] (no subject)> > > Dear all,> > Does anyone know how
> to change the reference group within lme().> For example,> lme(fixed =
> obs ~ line + age - 1,random = ~1 |sire, data = lambweight)> > Suppose
> age has 3 levels, so the code above will give me estimate of age2 and
> age3:> > Fixed effects: obs ~ line + age - 1 Value Std.Error DF t-value
> p-valueline1 10.491153 0.7261881 18 14.446882 0.0000line2 12.290287
> 0.8242309 18 14.911219 0.0000line3 11.032864 0.7647870 18 14.426061
> 0.0000line4 10.276735 0.7389137 18 13.907897 0.0000line5 10.952840
> 0.6084109 18 18.002373 0.0000age2 -0.155435 0.7157030 38 -0.217178
> 0.8292age3 0.009646 0.5481034 38 0.017599 0.9861> > How I can change
> within lme() in order to give me the estimate of age1 and age2.> > >
> Thanks,> Lawrence>
> _________________________________________________________________> > >
> ore_012009> [[alternative HTML version deleted]]> >
> _______________________________________________> R-sig-mixed-models at r-
> project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-
> mixed-models> > > The University of Aberdeen is a charity registered in
> Scotland, No SC013683.
> Windows Live(tm) Hotmail(r)...more than just e-mail. See how it works.
> [[alternative HTML version deleted]]
More information about the R-sig-mixed-models