R/modelMclustLLPA.R

#' @include model.R
setClass('lcModelMclustLLPA', contains = 'lcApproxModel')


#. clusterTrajectories ####
#' @rdname interface-mclust
#' @inheritParams clusterTrajectories
#' @inheritParams predictForCluster
setMethod('clusterTrajectories', 'lcModelMclustLLPA', function(object, at = time(object), ...) {
  if (length(at) == 0) {
    trajMat = object@model$parameters$mean
    assert_that(
      is.matrix(trajMat),
      nrow(trajMat) > 0,
      msg='empty estimate for mean. model probably did not converge'
    )

    dtclus = tsframe(
      t(trajMat),
      times = time(object),
      id = 'Cluster',
      ids = clusterNames(object),
      time = timeVariable(object),
      response = responseVariable(object))
  } else {
    callNextMethod()
  }
})


# . postprob ####
#' @rdname interface-mclust
setMethod('postprob', 'lcModelMclustLLPA', function(object, ...) {
  pp = object@model$z
  colnames(pp) = clusterNames(object)

  pp
})


#. predictPostprob ####
#' @rdname interface-mclust
setMethod('predictPostprob', 'lcModelMclustLLPA',
  function(object, newdata = NULL, ...) {
  if (is.null(newdata)) {
    callNextMethod()
  } else {
    predict(object@model, newdata = newdata)$z
  }
})


# . converged ####
#' @rdname interface-mclust
setMethod('converged', 'lcModelMclustLLPA', function(object, ...) {
  TRUE
})

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.