inputcov function

Input (Co)Variance Matrices

Input (Co)Variance Matrices

This function inputs (co)variance matrices of a set of outcomes given the corresponding standard deviation and correlation values.

inputcov(sd, cor=NULL)

Arguments

  • sd: a mxkm x k matrix of standard deviations for kk outcomes in mm matrices, or a vector for kk outcomes in a single matrix.
  • cor: either a vector of length 1, mm or k(k1)/2k(k-1)/2, or alternatively a kxkk x k or mxk(k1)/2m x k(k-1)/2 matrix. See Details.

Details

Depending the number of outcomes kk and matrices mm, the argument cor is interpreted as:

  • if a vector of length 1 (a scalar), the same correlation for all the kk outcomes for all the mm matrices;
  • if a vector of length mm, the same correlation for all the kk outcomes for each of the mm matrices;
  • if a vector of length k(k1)/2k(k-1)/2, the lower triangular elements (without diagonal, taken by column) of the correlation matrix of the kk outcomes, the same for all the mm matrices;
  • if a kxkk x k matrix, the correlation matrix for the single matrix (only when mm=1);
  • if a mxk(k1)/2m x k(k-1)/2 matrix, each row represents the lower triangular elements (without diagonal, taken by column) of the correlation matrix of the kk outcomes for each of the mm matrices.

Returns

For a single matrix, the (co)variance matrix itself. For multiple matrices, a mxk(k+1)/2m x k(k+1)/2 matrix, where each row represents the vectorized entries of the lower triangle (with diagonal, taken by column) of the related (co)variance matrix (see vechMat).

Author(s)

Antonio Gasparrini <antonio.gasparrini@lshtm.ac.uk >

Note

This function is called internally by mixmeta for multivariate models to input the correlation(s) when only the within-unit variances are provided through the argument S. In this case, the correlation values are set through the argument Scor in the control list (see mixmeta.control).

See Also

See xpndMat. See mixmeta.control.

Examples

# SOME RANDOM SD FOR A SINGLE MATRIX, WITH CONSTANT CORRELATION (M <- inputcov(runif(4, 0.1, 3), 0.7)) # CHECK CORRELATION cov2cor(M) # NOW WITH A MORE COMPLEX CORRELATION STRUCTURE (M <- inputcov(runif(3, 0.1, 3), c(0.7,0.2,0.4))) cov2cor(M) # MULTIPLE MATRICES (V <- matrix(runif(5*3, 0.1, 3), 5, 3, dimnames=list(1:5, paste("V", 1:3, sep="")))) inputcov(V, 0.6) # WITH REAL DATA WHEN CORRELATIONS AVAILABLE hyp (S <- inputcov(hyp[c("sbp_se","dbp_se")], cor=hyp$rho)) # CHECK FIRST STUDY cov2cor(xpndMat(S[1,])) # USED INTERNALLY IN mixmeta p53 inputcov(sqrt(p53[c("V1","V2")]), 0.5) model <- mixmeta(cbind(y1,y2), S=cbind(V1,V2), data=p53, control=list(Scor=0.5)) model$S
  • Maintainer: Antonio Gasparrini
  • License: GPL (>= 2)
  • Last published: 2021-10-16