Skip to content

how to standardize one variable to control for another confounding variable

2 messages · 李保平, Bede-Fazekas Ákos

#
Dera Thierry,
     Thanks for the sugestion. Would you please give me more information about how to standardize one variable 
to control for the effect of another confounding one? it would be much helpful to expalin it with a example, as my statistic knowledge is limited. 

    I am looking for your reply. 

    with best wishes,

     Baoping
#
Hello Baoping,

I think that's the solution proposed by Thierry.

 > df <- data.frame(size = runif(20) * 10, stage = c(rep("stage1", 7), 
rep("stage2", 7), rep("stage3", 6)))
 > df
         size  stage
1  3.4074887 stage1
2  8.4906095 stage1
3  9.4942578 stage1
4  5.8881368 stage1
5  8.8361620 stage1
6  0.7794099 stage1
7  1.1040311 stage1
8  9.2610258 stage2
9  2.8905632 stage2
10 4.1408304 stage2
11 2.8982138 stage2
12 2.9397847 stage2
13 2.6144625 stage2
14 4.9374664 stage2
15 8.6828374 stage3
16 0.2172812 stage3
17 4.8933184 stage3
18 5.2880694 stage3
19 1.8981373 stage3
20 5.5865985 stage3

 > df$size <- unlist(tapply(X = df$size, INDEX = df$stage, FUN = scale, 
simplify = TRUE))
 > df
           size  stage
1  -0.54627592 stage1
2   0.82762513 stage1
3   1.09889813 stage1
4   0.12421080 stage1
5   0.92102343 stage1
6  -1.25661121 stage1
7  -1.16887036 stage1
8   2.11969642 stage2
9  -0.56986326 stage2
10 -0.04201016 stage2
11 -0.56663322 stage2
12 -0.54908230 stage2
13 -0.68643082 stage2
14  0.29432335 stage2
15  1.42580094 stage3
16 -1.41082143 stage3
17  0.15601616 stage3
18  0.28828858 stage3
19 -0.84760338 stage3
20  0.38831913 stage3

HTH,
?kos Bede-Fazekas
Hungarian Academy of Sciences,
Centre for Ecological Research
Institute of Ecology and Botany

2016.05.21. 3:13 keltez?ssel, ??? ?rta: