Package: LaMa 2.0.3

Jan-Ole Koslik

LaMa: Fast Numerical Maximum Likelihood Estimation for Latent Markov Models

A variety of latent Markov models, including hidden Markov models, hidden semi-Markov models, state-space models and continuous-time variants can be formulated and estimated within the same framework via directly maximising the likelihood function using the so-called forward algorithm. Applied researchers often need custom models that standard software does not easily support. Writing tailored 'R' code offers flexibility but suffers from slow estimation speeds. We address these issues by providing easy-to-use functions (written in 'C++' for speed) for common tasks like the forward algorithm. These functions can be combined into custom models in a Lego-type approach, offering up to 10-20 times faster estimation via standard numerical optimisers. To aid in building fully custom likelihood functions, several vignettes are included that show how to simulate data from and estimate all the above model classes.

Authors:Jan-Ole Koslik [aut, cre]

LaMa_2.0.3.tar.gz
LaMa_2.0.3.tar.gz(r-4.5-noble)LaMa_2.0.3.tar.gz(r-4.4-noble)
LaMa_2.0.3.tgz(r-4.4-emscripten)LaMa_2.0.3.tgz(r-4.3-emscripten)
LaMa.pdf |LaMa.html
LaMa/json (API)

# Install 'LaMa' in R:
install.packages('LaMa', repos = c('https://cran.r-universe.dev', 'https://cloud.r-project.org'))

Peer review:

Bug tracker:https://github.com/janoleko/lama/issues

Pkgdown site:https://janoleko.github.io

Uses libs:
  • openblas– Optimized BLAS
  • c++– GNU Standard C++ Library v3
  • openmp– GCC OpenMP (GOMP) support library
Datasets:
  • nessi - Loch Ness Monster Acceleration Data
  • trex - T-Rex Movement Data

openblascppopenmp

4.30 score 567 downloads 58 exports 21 dependencies

Last updated 3 days agofrom:d22289a494. Checks:2 OK. Indexed: no.

TargetResultLatest binary
Doc / VignettesOKJan 29 2025
R-4.5-linux-x86_64OKJan 29 2025

Exports:buildSmoothDenscalc_trackIndddirichletdgamma2dgmrf2dskewnormdvmdwrpcauchyforwardforward_gforward_hsmmforward_ihsmmforward_pforward_phsmmforward_sforward_spgeneratormake_matricesmake_matrices_denspenaltypgamma2pred_matrixpseudo_respseudo_res_discretepskewnormpvmqgamma2qremlqskewnormrgamma2rskewnormrvmrwrpcauchysdreportMCstateprobsstateprobs_gstateprobs_pstationarystationary_contstationary_pstationary_p_sparsestationary_sparsetpmtpm_conttpm_embtpm_emb_gtpm_gtpm_hsmmtpm_hsmm2tpm_ihsmmtpm_ptpm_phsmmtpm_phsmm2tpm_thinnedtrigBasisExpviterbiviterbi_gviterbi_p

Dependencies:bootCircStatscircularlatticeMASSMatrixMatrixModelsmgcvmnormtmvtnormnlmenumDerivquantregRcppRcppArmadilloRcppEigenRTMBsnSparseMsurvivalTMB

Continuous-time HMMs

Rendered fromContinuous_time_HMMs.Rmdusingknitr::rmarkdownon Jan 29 2025.

Last update: 2024-11-12
Started: 2024-06-05

Hidden semi-Markov models

Rendered fromHSMMs.Rmdusingknitr::rmarkdownon Jan 29 2025.

Last update: 2024-11-12
Started: 2024-06-05

Inhomogeneous HMMs

Rendered fromInhomogeneous_HMMs.Rmdusingknitr::rmarkdownon Jan 29 2025.

Last update: 2024-11-12
Started: 2024-06-05

Introduction to LaMa

Rendered fromIntro_to_LaMa.Rmdusingknitr::rmarkdownon Jan 29 2025.

Last update: 2024-11-12
Started: 2024-06-05

LaMa and RTMB

Rendered fromLaMa_and_RTMB.Rmdusingknitr::rmarkdownon Jan 29 2025.

Last update: 2024-11-12
Started: 2024-11-12

Longitudinal data

Rendered fromLongitudinal_data.Rmdusingknitr::rmarkdownon Jan 29 2025.

Last update: 2024-11-12
Started: 2024-06-05

Markov-modulated (marked) Poisson processes

Rendered fromMMMPPs.Rmdusingknitr::rmarkdownon Jan 29 2025.

Last update: 2024-11-12
Started: 2024-06-05

Penalised splines

Rendered fromPenalised_splines.Rmdusingknitr::rmarkdownon Jan 29 2025.

Last update: 2025-01-29
Started: 2024-11-12

Periodic HMMs

Rendered fromPeriodic_HMMs.Rmdusingknitr::rmarkdownon Jan 29 2025.

Last update: 2024-11-12
Started: 2024-11-12

State-space models

Rendered fromState_space_models.Rmdusingknitr::rmarkdownon Jan 29 2025.

Last update: 2024-11-20
Started: 2024-06-05

Readme and manuals

Help Manual

Help pageTopics
Build the design and penalty matrices for smooth density estimationbuildSmoothDens
Calculate the index of the first observation of each track based on an ID variablecalc_trackInd
Reparametrised multivariate Gaussian distributiondgmrf2
Dirichlet distributionddirichlet dirichlet
Forward algorithm with homogeneous transition probability matrixforward
General forward algorithm with time-varying transition probability matrixforward_g
Forward algorithm for homogeneous hidden semi-Markov modelsforward_hsmm
Forward algorithm for hidden semi-Markov models with inhomogeneous state durations and/ or conditional transition probabilitiesforward_ihsmm
Forward algorithm with for periodically varying transition probability matricesforward_p
Forward algorithm for hidden semi-Markov models with periodically inhomogeneous state durations and/ or conditional transition probabilitiesforward_phsmm
Forward algorithm for hidden semi-Markov models with homogeneous transition probability matrixforward_s
Forward algorithm for hidden semi-Markov models with periodically varying transition probability matricesforward_sp
Reparametrised gamma distributiondgamma2 gamma2 pgamma2 qgamma2 rgamma2
Computes generalised determinantgdeterminant
Build the generator matrix of a continuous-time Markov chaingenerator
Build the design matrix and the penalty matrix for models involving penalised splines based on a formula and a data setmake_matrices
Build a standardised P-Spline design matrix and the associated P-Spline penalty matrixmake_matrices_dens
Loch Ness Monster Acceleration Datanessi
Computes penalty based on quadratic formpenalty
Build the prediction design matrix based on new data and model_matrices object created by 'make_matrices'pred_matrix
Calculate pseudo-residualspseudo_res
Calculate pseudo-residuals for discrete-valued observationspseudo_res_discrete
Quasi restricted maximum likelihood (qREML) algorithm for models with penalised splines or simple i.i.d. random effectsqreml
Monte Carlo version of 'sdreport'sdreportMC
Skew normal distributiondskewnorm pskewnorm qskewnorm rskewnorm skewnorm
Calculate conditional local state probabilities for homogeneous HMMsstateprobs
Calculate conditional local state probabilities for inhomogeneous HMMsstateprobs_g
Calculate conditional local state probabilities for periodically inhomogeneous HMMsstateprobs_p
Compute the stationary distribution of a homogeneous Markov chainstationary
Compute the stationary distribution of a continuous-time Markov chainstationary_cont
Compute the periodically stationary distribution of a periodically inhomogeneous Markov chainstationary_p
Sparse version of 'stationary_p'stationary_p_sparse
Sparse version of 'stationary'stationary_sparse
Build the transition probability matrix from unconstrained parameter vectortpm
Calculate continuous time transition probabilitiestpm_cont
Build the embedded transition probability matrix of an HSMM from unconstrained parameter vectortpm_emb
Build all embedded transition probability matrices of an inhomogeneous HSMMtpm_emb_g
Build all transition probability matrices of an inhomogeneous HMMtpm_g
Builds the transition probability matrix of an HSMM-approximating HMMtpm_hsmm
Build the transition probability matrix of an HSMM-approximating HMMtpm_hsmm2
Builds all transition probability matrices of an inhomogeneous-HSMM-approximating HMMtpm_ihsmm
Build all transition probability matrices of a periodically inhomogeneous HMMtpm_p
Builds all transition probability matrices of an periodic-HSMM-approximating HMMtpm_phsmm
Build all transition probability matrices of an periodic-HSMM-approximating HMMtpm_phsmm2
Compute the transition probability matrix of a thinned periodically inhomogeneous Markov chain.tpm_thinned
T-Rex Movement Datatrex
Compute the design matrix for a trigonometric basis expansiontrigBasisExp
Viterbi algorithm for state decoding in homogeneous HMMsviterbi
Viterbi algorithm for state decoding in inhomogeneous HMMsviterbi_g
Viterbi algorithm for state decoding in periodically inhomogeneous HMMsviterbi_p
von Mises distributiondvm pvm rvm vm
wrapped Cauchy distributiondwrpcauchy rwrpcauchy wrpcauchy