R/modelMixAK_GLMMlist.R

Defines functions getGLMM_MCMCs deviance.lcModelMixAK_GLMMlist coef.lcModelMixAK_GLMMlist

#' @include model.R
setClass('lcModelMixAK_GLMMlist', contains = 'lcModel')

#' @rdname interface-mixAK
setMethod('postprob', 'lcModelMixAK_GLMMlist', function(object, ...) {
  models = getGLMM_MCMCs(object)
  pp = Reduce('+', lapply(models, .postprob_GLMM_MCMC)) / length(models)
  colnames(pp) = clusterNames(object)
  pp
})

#' @rdname interface-mixAK
setMethod('predictForCluster', 'lcModelMixAK_GLMMlist', function(object, newdata, cluster, what = 'mu', ...) {
  models = getGLMM_MCMCs(object)
  k = match(cluster, clusterNames(object))

  Reduce('+', lapply(models, .predictForCluster_GLMM_MCMC,
                     k = k,
                     method = getLcMethod(object),
                     newdata = newdata, ...)) / length(models)
})


coef.lcModelMixAK_GLMMlist = function(object, ...) {
  models = getGLMM_MCMCs(object)
  Reduce('+', lapply(models, coef, ...)) / length(models)
}

deviance.lcModelMixAK_GLMMlist = function(object) {
  models = getGLMM_MCMCs(object)
  Reduce('+', lapply(models, deviance)) / length(models)
}


getGLMM_MCMCs = function(object) {
  object@model[which(vapply(names(object@model), nchar, FUN.VALUE = 0) == 0)]
}

Try the latrend package in your browser

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

latrend documentation built on March 31, 2023, 5:45 p.m.