Package: LaMa 2.1.1

Jan-Ole Fischer

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 Fischer [aut, cre]

LaMa_2.1.1.tar.gz
LaMa_2.1.1.tar.gz(r-4.7-arm64)LaMa_2.1.1.tar.gz(r-4.7-x86_64)LaMa_2.1.1.tar.gz(r-4.6-arm64)LaMa_2.1.1.tar.gz(r-4.6-x86_64)
LaMa_2.1.1.tgz(r-4.6-emscripten)
manual.pdf |manual.html
card.svg |card.png
LaMa/json (API)
NEWS

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

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

Pkgdown/docs site:https://janolefi.github.io

Uses libs:
  • openblas– Optimized BLAS
  • c++– GNU Standard C++ Library v3
Datasets:
  • nessi - Loch Ness Monster Acceleration Data
  • trex - T-Rex Movement Data

On CRAN:

Conda:

openblascpp

5.39 score 136 scripts 706 downloads 76 exports 29 dependencies

Last updated from:941bd3ba96. Checks:6 OK. Indexed: no.

TargetResultTimeFilesSyslog
linux-devel-arm64OK180
linux-devel-x86_64OK462
source / vignettesOK351
linux-release-arm64OK184
linux-release-x86_64OK192
wasm-releaseOK139

Exports:%sp%calc_trackIndcosinorddwelldgamma2dgmrf2dskewnormdvmdwrpcauchyforwardforward_gforward_hsmmforward_ihsmmforward_pforward_phsmmforward_sforward_spgeneratorgenerator_gLaMaColorsmake_matricesmake_matrices_densmake_matrices_oldmax0_smoothmax2MCreportmin0_smoothmin2penaltypenalty_unipenalty2pgamma2pred_matrixprocess_hid_formulaspseudo_respskewnormpvmqgamma2qremlqreml_oldqskewnormreportrgamma2rskewnormrvmrwrpcauchysdreport_outersdreportMCsmooth_dens_constructstateprobsstateprobs_gstateprobs_pstationarystationary_contstationary_ctstationary_pstationary_p_sparsestationary_sparsetpmtpm_conttpm_cttpm_embtpm_emb_gtpm_gtpm_g2tpm_hsmmtpm_hsmm2tpm_ihsmmtpm_ptpm_phsmmtpm_phsmm2tpm_thinnedviterbiviterbi_gviterbi_pzero_inflate

Dependencies:bootcircularclueclustergamlss.distlatticeMASSMatrixMatrixModelsmgcvmnormtmovMFmvtnormnlmenumDerivquantregRcppRcppArmadilloRcppEigenRTMBRTMBdistskmeansslamsnSparseMsplines2statmodsurvivalTMB

6 Continuous-time HMMs

Rendered fromContinuous_time_HMMs.Rmdusingknitr::rmarkdownon Jun 12 2026.

Last update: 2026-05-13
Started: 2024-06-05

9 Hidden semi-Markov models

Rendered fromHSMMs.Rmdusingknitr::rmarkdownon Jun 12 2026.

Last update: 2026-05-13
Started: 2024-06-05

1 Introduction to LaMa

Rendered fromIntro_to_LaMa.Rmdusingknitr::rmarkdownon Jun 12 2026.

Last update: 2026-05-13
Started: 2024-06-05

2 Automatic differentiation via RTMB

Rendered fromLaMa_and_RTMB.Rmdusingknitr::rmarkdownon Jun 12 2026.

Last update: 2026-05-13
Started: 2024-11-12

4 Longitudinal data

Rendered fromLongitudinal_data.Rmdusingknitr::rmarkdownon Jun 12 2026.

Last update: 2026-05-13
Started: 2024-06-05

7 Markov-modulated (marked) Poisson processes

Rendered fromMMMPPs.Rmdusingknitr::rmarkdownon Jun 12 2026.

Last update: 2026-05-13
Started: 2024-06-05

3 Extensions of the basic model structure

Rendered fromExtensions.Rmdusingknitr::rmarkdownon Jun 12 2026.

Last update: 2026-05-13
Started: 2026-05-13

5 Penalised splines

Rendered fromPenalised_splines.Rmdusingknitr::rmarkdownon Jun 12 2026.

Last update: 2026-05-13
Started: 2024-11-12

8 State-space models

Rendered fromState_space_models.Rmdusingknitr::rmarkdownon Jun 12 2026.

Last update: 2026-05-13
Started: 2024-06-05

Readme and manuals

Help Manual

Help pageTopics
Sparsity-retaining matrix multiplication%sp%
Calculate the index of the first observation of each track based on an ID variablecalc_trackInd
Trigonometric basis expansioncosinor
State dwell-time distributions of periodically inhomogeneous Markov chainsddwell
Reparametrised multivariate Gaussian distributiondgmrf2
Forward algorithm to calculate the HMM log-likelihoodforward
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 generator matrices of a continuous-time Markov chaingenerator_g
Generate a colour-blind-friendly paletteLaMaColors
Extract log-likelihood from LaMaModel objectlogLik.LaMaModel
Extract log-likelihood from qremlModel objectlogLik.qremlModel
Build the design 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
Build the design and the penalty matrix for models involving penalised splines based on a formula and a data setmake_matrices_old
Sample parameters from approximate Gaussian posterior distributionMCreport
AD-compatible minimum and maximum functionsmax2 min2 minmax
Smooth approximations to max(x, 0) and min(x, 0)max0_smooth min0_smooth minmax0_smooth
Loch Ness Monster Acceleration Datanessi
Computes penalty based on quadratic formpenalty
Penalty approximation of unimodality constraints for univariates smoothspenalty_uni
Computes generalised quadratic-form penaltiespenalty2
Plot pseudo-residualsplot.LaMaResiduals
Build the prediction design matrix based on new data and model_matrices object created by 'make_matrices'pred_matrix
Build the prediction design matrix based on new data and model_matrices object created by 'make_matrices'predict.LaMa_matrices
Process and standardise formulas for the state process of hidden Markov modelsprocess_hid_formulas
Calculate pseudo-residualspseudo_res
Quasi restricted maximum likelihood (qREML) algorithm for models with penalised splines or simple i.i.d. random effectsqreml
Quasi restricted maximum likelihood (qREML) algorithm for models with penalised splines or simple i.i.d. random effectsqreml_old
Get reported quantities from and 'RTMB' object and return a 'LaMaModel'report
Report uncertainty of the estimated smoothing parameters or variancessdreport_outer
Monte Carlo version of 'sdreport'sdreportMC
Skew normal distributiondskewnorm pskewnorm qskewnorm rskewnorm skewnorm
Build the design and penalty matrices for smooth density estimationsmooth_dens_construct
Calculate conditional local state probabilities in 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 stationary_ct
Periodically stationary distribution of a periodically inhomogeneous Markov chainstationary_p
Sparse version of 'stationary_p'stationary_p_sparse
Sparse version of 'stationary'stationary_sparse
Summary method for 'qremlModel' objectssummary.qremlModel
Build the transition probability matrix from unconstrained parameter vectortpm
Calculate continuous time transition probabilitiestpm_cont tpm_ct
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
Build all transition probability matrices of an inhomogeneous HMMtpm_g2
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 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
Zero-inflated density constructerzero_inflate