R/mgsem_proc_data.R

Defines functions mgsem_proc_data

## File Name: mgsem_proc_data.R
## File Version: 0.055

mgsem_proc_data <- function(data, group, weights)
{
    N <- nrow(data)
    if (is.null(group)){
        group <- rep(1,N)
    }
    groups <- unique(group)
    G <- length(groups)
    if (is.null(weights)){
        weights <- rep(1,N)
    }
    idgroup <- match(group, groups)
    suffstat <- list()
    for (gg in 1:G){
        ind_gg <- which(group==groups[gg])
        dat_gg <- data[ ind_gg, ]
        w <- weights[ind_gg]
        res <- stats::cov.wt( x=dat_gg, w=w, method='ML')
        s_gg <- list(M=res$center, S=res$cov, N=sum(w) )
        suffstat[[gg]] <- s_gg
    }
    #-- output
    res <- list(suffstat=suffstat, weights=weights, groups=groups,
                    G=G, N=N, idgroup=idgroup, data=data)
    return(res)
}

Try the sirt package in your browser

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

sirt documentation built on Aug. 11, 2023, 5:07 p.m.