as_vcov <- function(sd, cor) { x <- diag(rep(1, length(sd))) x[upper.tri(x)] <- cor x <- t(x) x[upper.tri(x)] <- cor res <- diag(sd) %*% x %*% diag(sd) res <- as.matrix(Matrix::nearPD(res)$mat) assertthat::assert_that(isSymmetric(res)) dimnames(res) <- NULL return(res) }