get_marginals: Compute the Marginal Probabilities from NHMMs

View source: R/get_marginals.R

get_marginalsR Documentation

Compute the Marginal Probabilities from NHMMs

Description

get_marginals returns the marginal state, response, transition, and emission probabilities, optionally per grouping defined by condition. By default, the marginalization weights sequences by the corresponding posterior probabilities of the latent states, i.e., conditional probabilities of the latent states given all data (weighting = "posterior"). If weighting = "forward", marginalization is based on forward probabilities, i.e. state probabilities given data up to that point which allows you to compute, for example, state marginals of form P(state_t | data_1, \ldots, data_t) (whereas in posterior probability weighting the conditioning is on data_1,\ldots,data_T. If weighting = "none", all individuals and time points are treated equally, without accounting for the probability that individual is at particular state at particular time.

Usage

get_marginals(
  model,
  probs = NULL,
  condition = NULL,
  newdata = NULL,
  type = c("state", "response", "transition", "emission"),
  weighting = c("posterior", "forward", "none")
)

Arguments

model

An object of class nhmm or mnhmm.

probs

Vector defining the quantiles of interest. Default is NULL, in which case no quantiles are computed. The quantiles are based on bootstrap samples of coefficients, stored in object$boot.

condition

An optional vector of variable names used for conditional marginal probabilities. Default is NULL, in which case marginalization is done over all variables, so that for example marginal emission probabilities are computed over all individuals and time points.

newdata

An optional data frame containing the new data to be used in computing the probabilities.

type

A character vector defining the marginal probabilities of interest. Can be one or multiple of "state", "response", "transition", and "emission". Default is to compute all of these.

weighting

A character string defining the type of weighting used in marginalization. One of "posterior" , "forward", "none". See details.


seqHMM documentation built on June 8, 2025, 10:16 a.m.