Description Usage Arguments Details Value References Examples

This function builds a rank correlation structure between columns of a matrix or between mcnode objects using the Iman and Conover method (1982).

1 |

`...` |
A matrix (each of its n columns but the first one will be reordered) or n mcnode objects (each elements but the first one will be reordered). |

`target` |
A scalar (only if n=2) or a (n x n) matrix of correlation. |

`outrank` |
Should the order be returned? |

`result` |
Should the correlation eventually obtained be printed? |

`seed` |
The random seed used for building the correlation. If NULL the seed is unchanged. |

The arguments should be named.

The function accepts for data a matrix or:

some "V" mcnode objects separated by a comma;

some "U" mcnode objects separated by a comma;

some "VU" mcnode objects separated by a comma. In that case, the structure is built columns by colums (the first column of each "VU" mcnode will have a correlation structure, the second ones will have a correlation structure, ....).

one "V" mcnode as a first element and some "VU" mcnode objects, separated by a comma. In that case, the structure is built between the "V" mcnode and each column of the "VU" mcnode objects. The correlation result (result = TRUE) is not provided in that case.

The number of variates of the elements should be equal.

target should be a scalar (two columns only) or a real
symmetric positive-definite square matrix. Only the upper triangular
part of target is used (see `chol`

).

The final correlation structure should be checked because it is not always possible to build the target correlation structure.

In a Monte-Carlo simulation, note that the order of the values within each mcnode will be changed by this function (excepted for the first one of the list). As a consequence, previous links between variables will be broken. The outrank option may help to rebuild these links (see the Examples).

If rank = FALSE: the matrix or a list of rearranged mcnodes.

If rank = TRUE: the order to be used to rearranged the matrix or the mcnodes to build the desired correlation structure.

Iman, R. L., & Conover, W. J. (1982). A distribution-free approach to inducing rank correlation among input variables. *Communication in Statistics - Simulation and Computation*, 11(3), 311-334.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | ```
x1 <- rnorm(1000)
x2 <- rnorm(1000)
x3 <- rnorm(1000)
mat <- cbind(x1, x2, x3)
## Target
(corr <- matrix(c(1, 0.5, 0.2, 0.5, 1, 0.2, 0.2, 0.2, 1), ncol=3))
## Before
cor(mat, method="spearman")
matc <- cornode(mat, target=corr, result=TRUE)
## The first row is unchanged
all(matc[, 1] == mat[, 1])
##Using mcnode and outrank
cook <- mcstoc(rempiricalD, values=c(0, 1/5, 1/50), prob=c(0.027, 0.373, 0.600), nsv=1000)
serving <- mcstoc(rgamma, shape=3.93, rate=0.0806, nsv=1000)
roundserv <- mcdata(round(serving), nsv=1000)
## Strong relation between roundserv and serving (of course)
cor(cbind(cook, roundserv, serving), method="spearman")
##The classical way to build the correlation structure
matcorr <- matrix(c(1, 0.5, 0.5, 1), ncol=2)
matc <- cornode(cook=cook, roundserv=roundserv, target=matcorr)
## The structure between cook and roundserv is OK but ...
## the structure between roundserv and serving is lost
cor(cbind(cook=matc$cook, serv=matc$roundserv, serving), method="spearman")
##An alternative way to build the correlation structure
matc <- cornode(cook=cook, roundserv=roundserv, target=matcorr, outrank=TRUE)
## Rebuilding the structure
roundserv[] <- roundserv[matc$roundserv, , ]
serving[] <- serving[matc$roundserv, , ]
## The structure between cook and roundserv is OK and ...
## the structure between roundserv and serving is preserved
cor(cbind(cook, roundserv, serving), method="spearman")
``` |

```
Loading required package: mvtnorm
Attaching package: 'mc2d'
The following objects are masked from 'package:base':
pmax, pmin
[,1] [,2] [,3]
[1,] 1.0 0.5 0.2
[2,] 0.5 1.0 0.2
[3,] 0.2 0.2 1.0
x1 x2 x3
x1 1.000000000 -0.09934766 -0.007409839
x2 -0.099347655 1.00000000 0.013825010
x3 -0.007409839 0.01382501 1.000000000
Spearman Rank Correlation Post Function
x1 x2 x3
x1 1.0000000 0.4998972 0.1956993
x2 0.4998972 1.0000000 0.1659506
x3 0.1956993 0.1659506 1.0000000
[1] TRUE
cook roundserv serving
cook 1.000000000 -0.006836998 -0.006485743
roundserv -0.006836998 1.000000000 0.999873506
serving -0.006485743 0.999873506 1.000000000
cook serv serving
cook 1.000000000 0.41659472 -0.006485743
serv 0.416594717 1.00000000 -0.037856354
serving -0.006485743 -0.03785635 1.000000000
cook roundserv serving
cook 1.0000000 0.4322883 0.4330319
roundserv 0.4322883 1.0000000 0.9998735
serving 0.4330319 0.9998735 1.0000000
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.