R/pca.covridge.R

Defines functions pca.covridge

Documented in pca.covridge

## File Name: pca.covridge.R
## File Version: 0.20

pca.covridge <- function( x, ridge=1E-10, wt=NULL )
{
    use_Rcpp <- TRUE
    if (is.null(wt)){
        cx <- stats::cov(x)
    } else {
        if (! use_Rcpp){
            cx <- stats::cov.wt(x=x, wt=wt)
            cx <- cx$cov
        } else {
            res <- miceadds_rcpp_weighted_cor( x=x, y=x, wt=wt, eps=ridge^2)
            cx <- res$Cov_xy
        }
    }
    diag(cx) <- diag(cx) + ridge
    pcax <- stats::princomp( covmat=cx )
    L <- pcax$loadings
    sdev <- pcax$sdev
    D <- diag(pcax$sdev^2)
    scores <- x %*% L
    res <- list( "loadings"=L, "scores"=scores, "sdev"=sdev )
    return(res)
}
alexanderrobitzsch/miceadds documentation built on Feb. 2, 2024, 10:21 a.m.