[R] Conditional correlation in R?

Gabor Grothendieck ggrothendieck at gmail.com
Fri Mar 17 01:10:00 CET 2006


Using the builtin iris data set here is the correlation between Sepal.Length
and Sepal.Width:

> cor(iris[,1:2])
             Sepal.Length Sepal.Width
Sepal.Length    1.0000000  -0.1175698
Sepal.Width    -0.1175698   1.0000000

and here it is after removing the effect of the other variables:

> cor(resid(lm(cbind(Sepal.Length, Sepal.Width) ~., iris)))
             Sepal.Length Sepal.Width
Sepal.Length    1.0000000   0.4328206
Sepal.Width     0.4328206   1.0000000

On 3/16/06, Ming Chen <chenming at gmail.com> wrote:
> hi all,
>
> Suppose I have four  variables (X1,X2,Y1,Y2)
> I want to calculate conditional correlation of (X1,Y1) given (X2, Y2).
> How can I do it in R?
>
> Thanks
>
> Ming Chen
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list