Learn R Programming

GenOrd (version 2.0.0)

ordcont: Computing the "intermediate" correlation matrix for the multivariate standard normal in order to achieve the "target" correlation matrix for the multivariate discrete variable

Description

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

Usage

ordcont(marginal, Sigma, support = list(), Spearman = FALSE,
epsilon = 1e-06, maxit = 100, df=Inf)

Value

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)

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)

Arguments

marginal

a list of \(k\) elements, where \(k\) is the number of variables. The \(i\)-th element of marginal is the vector of the cumulative probabilities defining the marginal distribution of the \(i\)-th component of the multivariate variable. If the \(i\)-th component can take \(k_i\) values, the \(i\)-th element of marginal will contain \(k_i-1\) probabilities (the \(k_i\)-th is obviously 1 and shall not be included).

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 support is the vector containing the ordered values of the support of the \(i\)-th variable. By default, the support of the \(i\)-th variable is \(1,2,...,k_i\)

Spearman

if TRUE, the function finds Spearman's correlations (and it is not necessary to provide support), if FALSE (default) Pearson's correlations

epsilon

the maximum tolerated error between target and actual correlations

maxit

the maximum number of iterations allowed for the algorithm

df

the degrees of freedom of the multivariate Student's t

Author

Alessandro Barbiero, Pier Alda Ferrari

See Also

contord, ordsample, corrcheck

Examples

Run this code
# consider a 4-dimensional ordinal variable
k <- 4
# with different number of categories
kj <- 2:5
# and uniform marginal distributions with variable number of categories
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]]
# consider now a multivariate Student's t with 10 dof
res.t <- ordcont(marginal, Sigma, df=10)
res.t$SigmaC
res.t$SigmaO

Run the code above in your browser using DataLab