fix_cor  R Documentation 
Shrinks the target correlation using a uniform scaling factor so that the overall correlation matrix is positive semidefinite. The method is described in detail in Gerard (2020).
fix_cor(design_perm, target_cor, num_steps = 51)
design_perm 
A numeric design matrix whose rows are to be permuted (thus controlling the amount by which they are correlated with the surrogate variables). The rows index the samples and the columns index the variables. The intercept should not be included (though see Section "Unestimable Components"). 
target_cor 
A numeric matrix of target correlations between the
variables in 
num_steps 
The number of steps between 0 and 1 to take in the
grid search for the shrinkage factor. The stepsize would be

Let W
= cor(design_perm)
. Let R
= target_cor
.
Then the overall correlation matrix is:
\left(
\begin{array}{cc}
W & R\\
R' & I_K
\end{array}
\right).
This function applies a multiplicative scaling factor to R
until
the above matrix is positive semidefinite. That is, it finds a
between 0 and 1 such that
\left(
\begin{array}{cc}
W & aR\\
aR' & I_K
\end{array}
\right)
is positive semidefinite.
A matrix of correlations the same dimension as target_cor
.
Actually, the returned matrix is a * target_cor
, where a
was determined to make the overall correlation matrix positive
semidefinite.
David Gerard
Gerard, D (2020). "Databased RNAseq simulations by binomial thinning." BMC Bioinformatics. 21(1), 206. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1186/s1285902034509")}.
n < 10
design_perm < matrix(rep(c(0, 1), length.out = n))
target_cor < matrix(seq(1, 0, length.out = 10), nrow = 1)
new_cor < seqgendiff:::fix_cor(design_perm = design_perm, target_cor = target_cor)
new_cor / target_cor
## In the case of one observed covariate, the requirement is just that
## the sum of squared correlations is less than or equal to one.
sum(target_cor ^ 2)
sum(new_cor ^ 2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.