- delta
initial or stationary distribution of length N, or matrix of dimension c(k,N) for k independent tracks, if trackID is provided
- Gamma
array of transition probability matrices of dimension c(N,N,n-1), as in a time series of length n, there are only n-1 transitions.
If an array of dimension c(N,N,n) for a single track is provided, the first slice will be ignored.
If the elements of \(\Gamma^{(t)}\) depend on covariate values at t or covariates t+1 is your choice in the calculation of the array, prior to using this function.
When conducting the calculation by using tpm_g(), the choice comes down to including the covariate matrix Z[-1,] oder Z[-n,].
If trackID is provided, Gamma needs to be an array of dimension c(N,N,n), matching the number of rows of allprobs. For each track, the transition matrix at the beginning will be ignored.
If the parameters for Gamma are pooled across tracks or not, depends on your calculation of Gamma. If pooled, you can use tpm_g(Z, beta) to calculate the entire array of transition matrices when Z is of dimension c(n,p).
This function can also be used to fit continuous-time HMMs, where each array entry is the Markov semigroup \(\Gamma(\Delta t) = \exp(Q \Delta t)\) and \(Q\) is the generator of the continuous-time Markov chain.
- allprobs
matrix of state-dependent probabilities/ density values of dimension c(n, N)
- trackID
optional vector of length n containing IDs
If provided, the total log-likelihood will be the sum of each track's likelihood contribution.
In this case, Gamma needs to be an array of dimension c(N,N,n), matching the number of rows of allprobs. For each track, the transition matrix at the beginning of the track will be ignored (as there is no transition between tracks).
Furthermore, instead of a single vector delta corresponding to the initial distribution, a delta matrix of initial distributions, of dimension c(k,N), can be provided, such that each track starts with it's own initial distribution.
- ad
optional logical, indicating whether automatic differentiation with RTMB should be used. By default, the function determines this itself.
- report
logical, indicating whether delta, Gamma, allprobs, and potentially trackID should be reported from the fitted model.
Defaults to TRUE, but only works if ad = TRUE, as it uses the RTMB package.
Caution: When there are multiple tracks, for compatibility with downstream functions like viterbi_g, stateprobs_g or pseudo_res,
forward_g should only be called once with a trackID argument.
- logspace
logical, indicating whether the probabilities/ densities in the allprobs matrix are on log-scale. If so, internal computations are also done on log-scale which is numerically more robust when the entries are very small.