R/loo.R

"loo" =
function (X, Y, lambda1, lambda2) 
{
    n = nrow(X)
    xscore = vector(mode = "numeric", length = n)
    yscore = vector(mode = "numeric", length = n)
    for (i in 1:n) {
        Xcv = X[-i, ]
        Ycv = Y[-i, ]
        res = rcc(Xcv, Ycv, lambda1, lambda2)
        xscore[i] = t(X[i, ]) %*% res$xcoef[, 1]
        yscore[i] = t(Y[i, ]) %*% res$ycoef[, 1]
    }
    cv = cor(xscore, yscore, use = "pairwise")
    return(invisible(cv))
}

Try the CCA package in your browser

Any scripts or data that you put into this service are public.

CCA documentation built on Sept. 8, 2023, 5:19 p.m.