RE: [R] Setting up contrasts

About this list Date view Thread view Subject view Author view Attachment view

From: BXC (Bendix Carstensen) (bxc@steno.dk)
Date: Mon 03 May 2004 - 18:42:42 EST


Message-id: <0ABD88905D18E347874E0FB71C0B29E90179E81C@exdkba022.novo.dk>


> -----Original Message-----
> From: r-help-bounces@stat.math.ethz.ch
> [mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of David
> J. Netherway
> Sent: Monday, May 03, 2004 10:25 AM
> To: r-help@stat.math.ethz.ch
> Subject: [R] Setting up contrasts
>
>
> I am using the following model:
> lm <- lm(mydata[[variableName]] ~ Age + Gender + Group, data=mydata)
>
> There are 5 groups in "Group": nonc (the control), c1,c2,c3 and c4.
>
> How do I contrast nonc vs the others?

"nonc" will be the reference if you use treatment contrasts (the
default).

>
> and
>
> How do I contrast c1 vs other c's (ie c2,c3,c4 as a subgroup)?

In the second case you just replace:

Group

with

relevel( Group, "c1" )

--- see the help page for "relevel".

Try for example:

table( Group, relevel( Group, "c1" ) )
table( Group, relevel( Group, 2 ) )

to see the mechanics of it.

Bendix Carstensen
----------------------
Bendix Carstensen
Senior Statistician
Steno Diabetes Center
Niels Steensens Vej 2
DK-2820 Gentofte
Denmark
tel: +45 44 43 87 38
mob: +45 30 75 87 38
fax: +45 44 43 07 06
bxc@steno.dk
www.biostat.ku.dk/~bxc
----------------------
>
> I have looked at the contrasts option in lm and model.matrix
> and am really none the wiser. Though it looks like I need to
> read up on model matrices again.
>
> Any help would be appreciated.
>
> Thanks, David
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo> /r-help
> PLEASE
> do read the posting guide!
> http://www.R-project.org/posting-guide.html
>

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Mon 31 May 2004 - 23:05:07 EST