Description Usage Arguments Details Value Author(s) Examples
The function takes in input one or two data matrices, x
and y
, and uses multiple regression to remove from the variables in x
all the variance shared with variables in y
. A parameter allows to remove also the variance shared among the variables in x
.
1 |
x |
A data matrix, observations by variables. |
y |
A data matrix, observations by variables. The number of observations must be the same as in x. |
itself |
Logical. Should be the variables in x cleaned from their own shared variance? |
There are three main ways to use this function:
The first is to give a set of variables x
in input, with parameter itself
= TRUE. The variables included in the output data matrix are the same as x
, but with all their shared variance removed, so their correlation is perfectly zero.
The second is to specify a matrix y
in input and parameter itself
= FALSE. In this case, the x
variables are cleaned from the variance that they share with those in y
, but not with the variance that they share with other variables in x
.
The third is to specify a matrix y
in input and parameter itself
= TRUE. In this case, the variables are cleaned both from the shared variance with the variables in y
and from that shared with other variables in x
.
A data matrix, same dimensions as x.
Giulio Costantini
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | # generate x, a matrix of correlated variables
pcm <- matrix(c(1, .2, .3,
.2, 1, .1,
.3, .1, 1), ncol = 3)
x <- pcm2data(pcm, 1000)
round(cor(x), 3)
# clean the variables in x from their shared variance
# and save them in variable x1.
x1 <- clean(x, itself = TRUE)
round(cor(x1), 3)
# generate another matrix, y, of variables that correlate with x
y <- matrix(rnorm(3000), ncol = 3)
round(cor(cbind(x, y)), 3)
# clean the variables in x only from the variance that they share with variables in y
x2 <- clean(x, y, itself = FALSE)
round(cor(cbind(x2, y)),3)
# clean the variables in x both from the variance shared with y and from the variance shared with other variables in x
x3 <- clean(x, y, itself = TRUE)
round(cor(cbind(x3, y)),3)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.