You are here

correcting raw score for age and gender

3 posts / 0 new
Last post
valentinav's picture
Offline
Joined: 06/15/2020 - 08:45
correcting raw score for age and gender

Hi Everyone,
I received suggestions to correct the the raw score for age and sex main effects, and for the age x sex interaction. However, I am not familiar with this procedure, does someone knows more about it?

So far, what I had done was to insert age a covariate in my analysis.

Thanks!

AdminNeale's picture
Offline
Joined: 03/01/2013 - 14:09
Can use lm() with predict

I snagged this from https://stackoverflow.com/questions/20907583/how-to-return-predicted-values-residuals-r-square-from-lm
which is ok, but to get the interaction term I am told you need to use * instead of + for the independent variables (age & sex): lm(y~age*sex)

set.seed(1)
n=10
 
y=rnorm(n)
x1=rnorm(n)
x2=rnorm(n)
 
lm.ft=function(y,x1,x2)
#   return(lm(y~x1+x2)$coef)
    return(lm(y~x1+x2))
 
  res=lm.ft(y,x1,x2)
ypredicted <- predict(res)
residuals <- y - ypredicted
tbates's picture
Offline
Joined: 07/31/2009 - 14:25
umx_residualize can help (also for twin data)

FYI, umx_residualize() packages this up cleanly, and works for wide data.

The help page is useful, but:

residDF = umx_residualize(mpg ~ cyl * disp, data = mtcars)
plot(residDF$mpg ~mtcars$mpg)

twin example

r1 = umx_residualize(ht ~ wt, data = twinData, suffixes=1:2)

multiple left hand side variables

r1 = umx_residualize(var = c("disp", "mpg"),cov = "cyl", data = mtcars)