R/mice_impute_pls_catpmm_R2.R

Defines functions mice_impute_pls_catpmm_R2

## File Name: mice_impute_pls_catpmm_R2.R
## File Version: 0.05

mice_impute_pls_catpmm_R2 <- function(res, Y, nfac)
{

    R2 <- cumsum(res$Xvar) / res$Xtotvar
    ncomp <- nfac
    ny <- ncol(Y)
    for (dd in 1:ny){
        R21 <- sapply( 1:ncomp, FUN=function(cc){
                    e1 <- res$fitted.values[,dd,cc]
                    y <- Y[,dd]
                    1 - stats::var(y-e1) / stats::var(y)
                } )
        R2 <- rbind( R2, R21)
    }
    rownames(R2) <- c("R2(X)", paste0("R2(Y,", 1:ny, ")") )
    colnames(R2) <- paste0("Comp",1:ncomp)
    res$R2 <- R2
    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.