[R] How to do covariate adjustment in R

Peter Langfelder peter.langfelder at gmail.com
Sat May 21 01:23:19 CEST 2011


On Thu, May 19, 2011 at 10:58 PM, karena <dr.jzhou at gmail.com> wrote:
> Thank you so much for this reply, Peter. It helps.
>
> I know this is one way to adjust for covariates. However, if what I want is
> to get the 'remaining values' after adjustment. For example, say, 'gene
> expression' value is denoted as 'ge', and for each gene,
> ge=a*age+b*sex+c*per_se
>
> My question is: how to get the value of 'per_se' for each gene?

You could use the residuals after regressing the expression on sex and
age.  I think the call would be

residuals(lm(expression~age+sex))

but try it and see if it makes sense. Just note that the residual
depends on how you define sex and and age; for example, if you shift
age by 10, the residuals shift by a*age. Similarly, the residuals will
depend on whether you use sex values (1,2) or (0,1) or (2,1) etc.  for
(female, male). Thus you need to be careful when interpreting the
residuals. I would suggest standardizing age to mean zero so the
residuals have the interpretation of expression at average age.
Standardization for sex makes statistical but not biological sense
since there are no samples with average sex.

Peter



More information about the R-help mailing list