Type: | Package |
Title: | Concurrent Generation of Ordinal and Normal Data with Given Correlation Matrix and Marginal Distributions |
Version: | 2.2.3 |
Date: | 2021-03-05 |
Author: | Anup Amatya, Hakan Demirtas, Ran Gao |
Maintainer: | Ran Gao <rgao8@uic.edu> |
Depends: | mvtnorm, corpcor, Matrix, GenOrd |
Imports: | stats |
Description: | Implementation of a procedure for generating samples from a mixed distribution of ordinal and normal random variables with a pre-specified correlation matrix and marginal distributions. The details of the method are explained in Demirtas et al. (2015) <doi:10.1080/10543406.2014.920868>. |
License: | GPL-2 | GPL-3 [expanded from: GPL] |
NeedsCompilation: | no |
Packaged: | 2021-03-05 17:37:29 UTC; rangao |
Repository: | CRAN |
Date/Publication: | 2021-03-05 18:20:06 UTC |
Concurrently generates ordinal and normal variables with a specified correlation matrix and marginal distributions
Description
The package implements a procedure for concurrently generating samples from ordinal and normal random variables with a pre-specified correlation matrix and marginal distributions. It is accomplished by first calculating an intermediate correlations (cmat.star
) which is used to generate a sample from multivariate normal distribution. Then, the first few components (corresponding to number of ordinal variables) are ordinalized. The resulting data are composed of a mixture of ordinal and normal variables that conform with a pre-specified marginal distributions and correlation structure. The function valid.limits
returns the lower and upper bounds of the correlation coefficients of ordinal-ordinal (OO) and ordinal-normal (ON) pairs given their marginal distributions, i.e. returns the range of feasible pairwise correlations. The function validate.target.cormat
checks the validity of the values of pairwise correlations. Additionally, it checks positive definitiveness, symmetry and correct dimension. The engine function genOrdNor
generates mixed data in accordance with the specified marginal and correlational quantities.
Details
Package: | OrdNor |
Type: | Package |
Version: | 2.2.3 |
Date: | 2021-03-05 |
License: | GPL |
Author(s)
Anup Amatya, Hakan Demirtas, Ran Gao
Maintainer: Ran Gao <rgao8@uic.edu>
Computes intermediate correlations for ordinal-normal pairs before ordinalization
Description
The function computes the intermediate correlation values of pairwise correlations between ordinal and normal variables.
Usage
IntermediateON(plist, ONCorrMat)
Arguments
plist |
A list of probability vectors corresponding to each ordinal variable. The i-th element of |
ONCorrMat |
A matrix of pairwise target correlations between ordinal and normal variables. This is a submatrix of the overall correlation matrix, and it is pertinent to the ordinal-normal part. Hence, the matrix may or may not be square. Even when it is square, it may not be symmetric. |
Value
A pairwise correlation matrix of intermediate correlations.
See Also
Examples
no.ord=3
no.norm =4
n = 200
q=no.ord + no.norm
set.seed(12345)
Sigma = diag(q)
Sigma[lower.tri(Sigma)] = runif( (q*(q-1)/2),-0.4,0.4 )
Sigma = Sigma + t(Sigma)
diag(Sigma)=1
Sigma=as.matrix( nearPD(Sigma,corr = TRUE, keepDiag = TRUE)$mat )
marginal = list( 0.3, cumsum( c(0.30, 0.40) ), cumsum(c(0.4, 0.2, 0.3) ) )
ONCorrMat = Sigma[4:7, 1:3]
IntermediateON(marginal, ONCorrMat)
Computes intermediate correlations for ordinal-ordinal pairs before ordinalization
Description
This function computes the correlation of normal-normal pairs before ordinalizing both components.
Usage
IntermediateOO(plist, OOCorrMat)
Arguments
plist |
A list of probability vectors corresponding to each ordinal variable. The i-th element of |
OOCorrMat |
A matrix of pairwise target correlations between ordinal variables. It is a symmetric square matrix whose diagonal elements are 1. |
Value
A pairwise correlation matrix of intermediate correlations for ordinal variables.
See Also
Examples
no.ord=3
no.norm =4
n = 200
q=no.ord + no.norm
set.seed(12345)
Sigma = diag(q)
Sigma[lower.tri(Sigma)] = runif( (q*(q-1)/2),-0.4,0.4 )
Sigma = Sigma + t(Sigma)
diag(Sigma)=1
Sigma=as.matrix( nearPD(Sigma,corr = TRUE, keepDiag = TRUE)$mat )
marginal = list( 0.3, cumsum( c(0.30, 0.40) ), cumsum(c(0.4, 0.2, 0.3) ) )
OOCorrMat = Sigma[1:3, 1:3]
IntermediateOO(marginal, OOCorrMat)
Finds the feasible correlation range for a pair of ordinal and normal variable
Description
The function computes the lower and upper bounds of a pairwise correlation between an ordinal and a normal variable via the method of Demirtas and Hedeker (2011).
Usage
LimitforON(pvec1)
Limit_forON(pvec1) #deprecated
Arguments
pvec1 |
A vector of marginal probabilities for an ordinal variable of the pair. |
Value
A vector of two elements. The first element is the lower bound and the second element is the upper bound.
References
Demirtas, H., Hedeker, D. (2011). A practical way for computing approximate lower and upper correlation bounds. The American Statistician, 65(2), 104-109.
Examples
pvec = cumsum( c(0.30, 0.40) )
LimitforON(pvec)
Finds the feasible correlation range for a pair of ordinal variables
Description
The function computes the lower and upper bounds of correlation between two ordinal variables via the method of Demirtas and Hedeker (2011).
Usage
LimitforOO(pvec1, pvec2)
Limit_forOO(pvec1, pvec2) #deprecated
Arguments
pvec1 |
A vector of marginal probabilities for the first ordinal variable. |
pvec2 |
A vector of marginal probabilities for the second ordinal variable. |
Value
A vector of two elements. The first element is the lower bound and the second element is the upper bound.
References
Demirtas, H., Hedeker, D. (2011). A practical way for computing approximate lower and upper correlation bounds. The American Statistician, 65(2), 104-109.
Examples
pvec1 = cumsum( c(0.30, 0.40) )
pvec2=cumsum(c(0.4, 0, 0.3) ) # The second category is skipped in this setting
LimitforOO(pvec1, pvec2)
Computes the correlation of intermediate multivariate normal data before subsequent ordinalization
Description
The function computes an intermediate correlation matrix which leads to the target correlation matrix after ordinalization of the samples generated from a multivariate normal distribution with the intermediate correlation matrix.
Usage
cmat.star(plist, CorrMat, no.ord, no.norm)
Arguments
plist |
A list of probability vectors corresponding to each ordinal variable. The i-th element of |
CorrMat |
The target correlation matrix which must be positive definite and within the valid limits. |
no.ord |
Number of ordinal variables in the data. |
no.norm |
Number of normal variables in the data. |
Value
An intermediate correlation matrix of size (no.ord + no.norm) \times (no.ord + no.norm)
See Also
Examples
Sigma = diag(4)
Sigma[lower.tri(Sigma)] = c(0.42, 0.78, 0.29, 0.37, 0.14, 0.26)
Sigma = Sigma + t(Sigma)
diag(Sigma)=1
marginal = list( c(0.2, 0.5), c(0.4, 0.7, 0.9))
cmat.star(marginal, Sigma, 2, 2)
Generates a data set with ordinal and normal variables
Description
The function simulates a data set with ordinal and normal components with a pre-specified correlation matrix and marginals.
Usage
genOrdNor(n, plist, cmat.star, mean.vec, sd.vec, no.ord, no.norm)
Arguments
n |
Number of rows |
plist |
A list of probability vectors corresponding to each ordinal variable. The i-th element of |
cmat.star |
The intermediate correlation matrix obtained from |
mean.vec |
A vector of means for the normal variables. |
sd.vec |
A vector of standard deviations for the normal variables. |
no.ord |
Number of ordinal variables. |
no.norm |
Number of normal variables. |
Value
A matrix of size n \times (no.ord + no.norm)
, of which first no.ord
are ordinal variables.
References
Demirtas, H., Yavuz, Y. (2015). Concurrent generation of ordinal and normal data. Journal of Biopharmaceutical Statistics; 25(4), 635-650.
See Also
cmat.star
, validate.target.cormat
, validate.plist
Examples
Sigma = diag(4)
Sigma[lower.tri(Sigma)] = c(0.42, 0.78, 0.29, 0.37, 0.14, 0.26)
Sigma = Sigma + t(Sigma)
diag(Sigma)=1
marginal = list( c(0.2, 0.5), c(0.4, 0.7, 0.9))
cmat= cmat.star(marginal, Sigma, 2, 2)
mean.vec = c(2,4)
sd.vec = c(0.5, 1.5)
Y=genOrdNor(10000,marginal, cmat, mean.vec, sd.vec, 2, 2)
cor(Y)
Ordinalizes the standard normal variable
Description
The function transforms the standard normal variable to an ordinal variable with a specified probability for each category.
Usage
ordinalize(pvec, z)
Arguments
pvec |
A vector of probabilities for an ordinal variable. The i-th element of the |
z |
A vector of samples from the standard normal distribution. |
Value
A vector of ordinalized variates.
Computes the lower and upper bounds of correlation in the form of two matrices
Description
The function computes the lower and upper bounds for the target correlation based on the marginal probabilities.
Usage
valid.limits(plist, no.ord, no.norm)
Arguments
plist |
A list of probability vectors corresponding to each ordinal variable. The i-th element of |
no.ord |
Number of ordinal variables. |
no.norm |
Number of normal variables. |
Details
The function returns a list of two matrices. The lower
contains the lower bounds and the upper
contains the upper bounds of the feasible correlations.
Examples
marginal = list( c(0.2, 0.5), c(0.4, 0.7, 0.9))
valid.limits (marginal, 2,2)
Checks the validity of ordinal probabilities
Description
The function checks the validity of the probability vectors of the ordinal variables. It verifies that the elements in the vectors are cumulative probabilities and the values are between 0 and 1. It also checks a number of vectors within the list matches the specified number of ordinal variables.
Usage
validate.plist(plist, no.ord)
Arguments
plist |
A list of probability vectors corresponding to each ordinal variable. The i-th element of |
no.ord |
Number of ordinal variables. |
Details
The function returns error message if there are any violations. No message is displayed for the correct specifications.
Examples
marginal = list( c(0.2, 0.5), c(0.4, 0.7, 0.9))
validate.plist(marginal, 2)
Checks the target correlation matrix
Description
The function checks the validity of the values of pairwise correlations. Additionally, it checks positive definitiveness, symmetry and correct dimension.
Usage
validate.target.cormat(plist, CorrMat, no.ord, no.norm)
Arguments
plist |
A list of probability vectors corresponding to each ordinal variable. The i-th element of |
CorrMat |
The target correlation matrix which must be positive definite and within the valid limits. |
no.ord |
Number of ordinal variables. |
no.norm |
Number of normal variables. |
Details
In addition to being positive definite and symmetric, the values of pairwise correlations in the target correlation matrix must also fall within the limits imposed by the marginal distributions of the ordinal variables.The function ensures that the supplied correlation matrix is valid for simulation. If a violation occurs, an error message is displayed that identifies the violation. The function returns a logical value TRUE
when no such violation occurs.
Examples
Sigma = diag(4)
Sigma[lower.tri(Sigma)] = c(0.42, 0.78, 0.29, 0.37, 0.14, 0.26)
Sigma = Sigma + t(Sigma)
diag(Sigma)=1
marginal = list( c(0.2, 0.5), c(0.4, 0.7, 0.9))
validate.target.cormat(marginal, Sigma, 2,2)