R/mice_multilevel_impute_groupmean.R

## File Name: mice_multilevel_impute_groupmean.R
## File Version: 0.09



mice_multilevel_impute_groupmean <- function (y, ry, x, type, grmeanwarning=TRUE, ...)
{
    if ( ( ncol(x) > 2 ) & grmeanwarning ){
        warning("\nMore than one variable is requested to be aggregated.\n")
    }
    # calculate aggregated values
    a1 <- stats::aggregate( x[, type %in% c(1,2) ],
                            list( x[,type==-2] ), mean, na.rm=TRUE)
    i1 <- match( x[,type==-2], a1[,1] )
    ximp <- as.matrix(a1[i1,-1])
    colnames(ximp) <- paste( names(type)[ type %in% c(1,2) ],
                                names(type)[ type==-2 ], sep="." )
    return(ximp)
}
alexanderrobitzsch/miceadds documentation built on Feb. 2, 2024, 10:21 a.m.