Description Usage Arguments Value Note Author(s) See Also Examples
The function computes the correlation matrix of the k-dimensional standard normal r.v. yielding the desired correlation matrix Sigma
for the k-dimensional r.v. with desired marginal distributions marginal
1 2 |
marginal |
a list of k elements, where k is the number of variables.
The i-th element of |
Sigma |
the target correlation matrix of the discrete variables |
support |
a list of k elements, where k is the number of variables. The i-th element of |
Spearman |
if |
epsilon |
the maximum tolerated error between target and actual correlations |
maxit |
the maximum number of iterations allowed for the algorithm |
a list of five elements
SigmaC |
the correlation matrix of the multivariate standard normal variable |
SigmaO |
the actual correlation matrix of the discretized variables (it should approximately coincide with the target correlation matrix |
Sigma |
the target correlation matrix of the discrete variables |
niter |
a matrix containing the number of iterations performed by the algorithm, one for each pair of variables |
maxerr |
the actual maximum error (the maximum absolute deviation between actual and target correlations of the discrete variables) |
For some choices of marginal
and Sigma
, there may not exist a feasible k-variate probability mass function or the algorithm may not provide a feasible correlation matrix SigmaC
. In this case, the procedure stops and exits with an error.
The value of the maximum tolerated absolute error epsilon
on the elements of the correlation matrix for the target r.v. can be set by the user: a value between 1e-6 and 1e-2 seems to be an acceptable compromise assuring both the precision of the results and the convergence of the algorithm; moreover, a maximum number of iterations can be chosen (maxit
), in order to avoid possible endless loops
Alessandro Barbiero, Pier Alda Ferrari
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 | # consider a 4-dimensional ordinal variable
k <- 4
# with different number of categories
kj <- c(2,3,4,5)
# and uniform marginal distributions
marginal <- list(0.5, (1:2)/3, (1:3)/4, (1:4)/5)
corrcheck(marginal)
# and the following correlation matrix
Sigma <- matrix(c(1,0.5,0.4,0.3,0.5,1,0.5,0.4,0.4,0.5,1,0.5,0.3,0.4,0.5,1),
4, 4, byrow=TRUE)
Sigma
# the correlation matrix of the standard 4-dimensional standard normal
# ensuring Sigma is
res <- ordcont(marginal, Sigma)
res[[1]]
# change some marginal distributions
marginal <- list(0.3, c(1/3, 2/3), c(1/5, 2/5, 3/5), c(0.1, 0.2, 0.4, 0.6))
corrcheck(marginal)
# and notice how the correlation matrix of the multivariate normal changes...
res <- ordcont(marginal, Sigma)
res[[1]]
# change Sigma, adding a negative correlation
Sigma[1,2] <- -0.2
Sigma[2,1] <- Sigma[1,2]
Sigma
# checking whether Sigma is still positive definite
eigen(Sigma)$values # all >0, OK
res <- ordcont(marginal, Sigma)
res[[1]]
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.