Given the following dataset:
csf age sex tiv group
0,30 7,92 1 1,66 1
0,26 33,75 0 1,27 3
0,18 7,83 0 1,43 2
0,20 9,42 0 1,70 1
0,29 22,33 1 1,68 2
0,40 20,75 1 1,56 1
0,26 13,25 0 1,68 1
0,28 6,67 0 1,66 1
0,22 10,58 0 1,38 1
0,22 13,08 0 1,41 2
0,33 36,42 1 1,68 3
0,29 35,00 1 1,34 3
0,11 7,25 1 1,20 2
0,13 10,00 0 1,12 3
0,32 34,58 1 1,33 3
0,68 8,25 1 1,90 1
0,25 11,08 1 1,92 2
0,33 10,92 0 1,24 1
0,20 9,33 1 1,58 1
0,25 51,67 0 1,15 3
0,16 27,67 0 1,19 3
0,19 33,25 0 1,29 3
0,16 7,92 1 1,67 1
0,17 13,42 0 1,34 3
0,45 48 1 1,85 1
0,34 14,67 1 1,80 1
0,23 35,33 0 1,31 3
0,18 15,50 1 1,59 1
0,11 12,08 0 1,34 2
0,21 9,92 0 1,43 1
0,19 8,83 0 1,59 1
0,21 6,83 1 1,78 1
0,13 10 0 1,28 1
0,38 38,42 1 1,63 3
0,27 13,83 0 1,63 1
0,28 15,33 0 1,43 2
0,31 38 1 1,70 1
0,19 13,08 0 1,56 1
0,13 26,25 0 1,07 3
0,14 63,08 1 1,34 3
0,19 10,25 1 1,27 3
0,38 37,25 1 1,63 3
0,28 37,33 0 1,47 3
0,34 20,25 1 1,41 2
0,36 40,33 1 1,44 3
0,26 42,83 0 1,43 2
0,29 46,08 1 1,74 2
0,19 10,25 0 1,56 1
0,20 12,08 1 1,76 1
0,29 30,58 1 1,39 3
0,23 44,67 1 1,45 3
I want to know whether CSF is different between groups. But I know that CSF is highly affected by age, sex, and tiv. So, I would like to plot the differences between groups beyond the influence of age, sex, and tiv. To that end, I need to adjust CSF for those three covariates. My question is: how can I obtain, for each individual, his/her adjusted CSF value?
I did the following linear model:
model1 <- lm(csf ~ age + sex + tiv,data=mri22))
And used the sum of (residuals+intercept) in order to obtain the csf value free from the effects of age, sex, and tiv:
csf_adj <- resid(model1) + coef(model1)[1]
However, I get many negative values that make no sense, given that CSF cannot be negative. So my question is: how can I obtain the good CSF values adjusted for all three covariates?