1 | cor.from.basis(V, Vbase)
|
V |
|
Vbase |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (V, Vbase)
{
p <- dim(Vbase)[1]
Cor.mat <- diag(rep(1, p))
Cov.mat <- diag(Vbase[, 1])
idx <- combn(p, 2)
for (i in 1:(p - 1)) {
idxslice <- idx[1, ] == i
cov.tmp <- 0.5 * (Vbase[i] + Vbase[idx[2, idxslice]] -
V[i, idx[2, idxslice]])
denom <- sqrt(Vbase[i]) * sqrt(Vbase[idx[2, idxslice]])
cor.tmp <- cov.tmp/denom
abscor <- abs(cor.tmp)
if (any(abscor > 1)) {
idxthr <- abscor > 1
cor.tmp[idxthr] <- sign(cor.tmp[idxthr])
cov.tmp[idxthr] <- cor.tmp[idxthr] * denom[idxthr]
}
Cor.mat[i, idx[2, idxslice]] <- Cor.mat[idx[2, idxslice],
i] <- cor.tmp
Cov.mat[i, idx[2, idxslice]] <- Cov.mat[idx[2, idxslice],
i] <- cov.tmp
}
return(list(Cor.mat = Cor.mat, Cov.mat = Cov.mat))
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.