R/ma.wtd.corNA.R

Defines functions ma.wtd.corNA

Documented in ma.wtd.corNA

## File Name: ma.wtd.corNA.R
## File Version: 0.15


#--- weighted correlation using cov2cor function
ma.wtd.corNA <- function( data, weights=NULL, vars=NULL, method="unbiased" )
{
    #*** pre-processing
    res <- ma_wtd_stat_prepare_data(data=data, weights=weights, vars=vars )
    data <- res$data
    weights <- res$weights
    M <- length(data)
    #*** weighted covariance
    V <- ncol(data[[1]])
    res <- array( NA, dim=c(M,V,V) )
    dimnames(res)[[2]] <- colnames(data[[1]] )
    dimnames(res)[[3]] <- colnames(data[[1]] )
    for (ii in 1:M){
        data1 <- data[[ii]]
        covXY <- ma_wtd_cov_NA_compute_wtd_cov( data1=data1, vars=vars,
                        weights=weights, method=method )
        res[ii,,] <- stats::cov2cor(V=covXY)
    }
    res <- colMeans(res)
    return(res)
}

Try the miceadds package in your browser

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

miceadds documentation built on May 29, 2024, 11:05 a.m.