[R] Setting up contrasts

BXC (Bendix Carstensen) bxc at steno.dk
Mon May 3 10:42:42 CEST 2004


> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of David 
> J. Netherway
> Sent: Monday, May 03, 2004 10:25 AM
> To: r-help at 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 at 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 at 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
>




More information about the R-help mailing list