Dear Karena, x = 1:100 y = rnorm(100)
fit = lm(x~y) # what properties does a fit have? names(fit) # [1] "coefficients" "residuals" "effects" "rank" "fitted.values" "assign" "qr" # [8] "df.residual" "xlevels" "call" "terms" "model" x.resid = fit$residuals plot(x~x.resid) cor.test(y,x.resid) # -> r = 3.019388e-17 A gotcha is NAs in your data frame: Look at ?lm to see how to handle these properly best, t On 20 May 2011, at 6:58 AM, karena 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? > > thanks again. > > Karena > > -- > View this message in context: > http://r.789695.n4.nabble.com/How-to-do-covariate-adjustment-in-R-tp3537463p3537711.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.