Skip to contents

Log-likelihood function of a Gaussian-hidden Markov model

Usage

f_ll_hmm(theta, data, N, neg = FALSE)

Arguments

theta

A numeric vector of model parameters.

  • The first N*(N-1) elements are the logarithms of the non-diagonal elements of the transition probability matrix.

  • The next N elements are the mean values of the state-dependent normal distributions.

  • The last N elements are the logarithms of the standard deviations of the state-dependent normal distributions.

data

A numeric vector, the time series data.

N

An integer, the number of states.

neg

Set to TRUE to return the negative log-likelihood value.

Value

A numeric, the log-likelihood value at theta given data.

References

https://en.wikipedia.org/wiki/Hidden_Markov_model

Examples

theta <- c(-1, -1, -2, 2, 0.5, 0.5)
data <- sim_hmm(Tp = 1000, N = 2, theta = theta)
f_ll_hmm(theta = theta, data = data, N = 2)
#> [1] -2278.964
# \donttest{
nlm(f_ll_hmm, p = theta, data = data, N = 2, neg = TRUE)$estimate
#> Warning: NA/Inf replaced by maximum positive value
#> [1] -0.8295929 -1.0619608 -1.7896455  2.1832781  0.5091347  0.4173019
# }