correcting raw score for age and gender

Posted on
No user picture. valentinav Joined: 06/15/2020
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!

Replied on Fri, 02/11/2022 - 10:50
Picture of user. AdminNeale Joined: 03/01/2013

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

Replied on Fri, 02/11/2022 - 18:54
Picture of user. tbates Joined: 07/31/2009

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)