Title: | Concurrent Generation of Ordinal and Normal Data with Given Correlation Matrix and Marginal Distributions |
---|---|
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>. |
Authors: | Anup Amatya, Hakan Demirtas, Ran Gao |
Maintainer: | Ran Gao <[email protected]> |
License: | GPL |
Version: | 2.2.3 |
Built: | 2024-10-30 02:43:53 UTC |
Source: | https://github.com/cran/OrdNor |
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.
Package: | OrdNor |
Type: | Package |
Version: | 2.2.3 |
Date: | 2021-03-05 |
License: | GPL |
Anup Amatya, Hakan Demirtas, Ran Gao
Maintainer: Ran Gao <[email protected]>
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.
cmat.star(plist, CorrMat, no.ord, no.norm)
cmat.star(plist, CorrMat, no.ord, no.norm)
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. |
An intermediate correlation matrix of size
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)
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)
The function simulates a data set with ordinal and normal components with a pre-specified correlation matrix and marginals.
genOrdNor(n, plist, cmat.star, mean.vec, sd.vec, no.ord, no.norm)
genOrdNor(n, plist, cmat.star, mean.vec, sd.vec, no.ord, no.norm)
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. |
A matrix of size , of which first
no.ord
are ordinal variables.
Demirtas, H., Yavuz, Y. (2015). Concurrent generation of ordinal and normal data. Journal of Biopharmaceutical Statistics; 25(4), 635-650.
cmat.star
, validate.target.cormat
, validate.plist
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)
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)
The function computes the intermediate correlation values of pairwise correlations between ordinal and normal variables.
IntermediateON(plist, ONCorrMat)
IntermediateON(plist, ONCorrMat)
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. |
A pairwise correlation matrix of intermediate correlations.
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)
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)
This function computes the correlation of normal-normal pairs before ordinalizing both components.
IntermediateOO(plist, OOCorrMat)
IntermediateOO(plist, OOCorrMat)
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. |
A pairwise correlation matrix of intermediate correlations for ordinal variables.
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)
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)
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).
LimitforON(pvec1) Limit_forON(pvec1) #deprecated
LimitforON(pvec1) Limit_forON(pvec1) #deprecated
pvec1 |
A vector of marginal probabilities for an ordinal variable of the pair. |
A vector of two elements. The first element is the lower bound and the second element is the upper bound.
Demirtas, H., Hedeker, D. (2011). A practical way for computing approximate lower and upper correlation bounds. The American Statistician, 65(2), 104-109.
pvec = cumsum( c(0.30, 0.40) ) LimitforON(pvec)
pvec = cumsum( c(0.30, 0.40) ) LimitforON(pvec)
The function computes the lower and upper bounds of correlation between two ordinal variables via the method of Demirtas and Hedeker (2011).
LimitforOO(pvec1, pvec2) Limit_forOO(pvec1, pvec2) #deprecated
LimitforOO(pvec1, pvec2) Limit_forOO(pvec1, pvec2) #deprecated
pvec1 |
A vector of marginal probabilities for the first ordinal variable. |
pvec2 |
A vector of marginal probabilities for the second ordinal variable. |
A vector of two elements. The first element is the lower bound and the second element is the upper bound.
Demirtas, H., Hedeker, D. (2011). A practical way for computing approximate lower and upper correlation bounds. The American Statistician, 65(2), 104-109.
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)
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)
The function transforms the standard normal variable to an ordinal variable with a specified probability for each category.
ordinalize(pvec, z)
ordinalize(pvec, z)
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. |
A vector of ordinalized variates.
The function computes the lower and upper bounds for the target correlation based on the marginal probabilities.
valid.limits(plist, no.ord, no.norm)
valid.limits(plist, no.ord, no.norm)
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. |
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.
marginal = list( c(0.2, 0.5), c(0.4, 0.7, 0.9)) valid.limits (marginal, 2,2)
marginal = list( c(0.2, 0.5), c(0.4, 0.7, 0.9)) valid.limits (marginal, 2,2)
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.
validate.plist(plist, no.ord)
validate.plist(plist, no.ord)
plist |
A list of probability vectors corresponding to each ordinal variable. The i-th element of |
no.ord |
Number of ordinal variables. |
The function returns error message if there are any violations. No message is displayed for the correct specifications.
marginal = list( c(0.2, 0.5), c(0.4, 0.7, 0.9)) validate.plist(marginal, 2)
marginal = list( c(0.2, 0.5), c(0.4, 0.7, 0.9)) validate.plist(marginal, 2)
The function checks the validity of the values of pairwise correlations. Additionally, it checks positive definitiveness, symmetry and correct dimension.
validate.target.cormat(plist, CorrMat, no.ord, no.norm)
validate.target.cormat(plist, CorrMat, no.ord, no.norm)
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. |
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.
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)
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)