Skip to content

Commit

Permalink
fix NA handling in build_mm
Browse files Browse the repository at this point in the history
  • Loading branch information
helske committed Jul 5, 2023
1 parent a948e5d commit 2a50b04
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: seqHMM
Title: Mixture Hidden Markov Models for Social Sequence Data and Other Multivariate, Multichannel Categorical Time Series
Version: 1.2.6
Date: 2023-06-14
Date: 2023-06-7
Authors@R:
c(person(given = "Jouni",
family = "Helske",
Expand Down
6 changes: 4 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
seqHMM 1.2.6 (Release date: )
seqHMM 1.2.6 (Release date: 2023-06-07)
==============
* Armadillo solver now fails directly instead of trying approximate solution
in case of numerical issues when estimating the regression coefficients.
* `build_mm` now correctly runs EM algorithm only in case of real missing
observations in data, i.e. it correctly handles void values.

seqHMM 1.2.5 (Release date: 2023-05-30)
seqHMM 1.2.5 (Release date: 2023-06-13)
==============
* New methods `state_names` and `cluster_names` for getting and setting state
and cluster names of the model objects.
Expand Down
9 changes: 2 additions & 7 deletions R/build_mm.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,15 @@ build_mm <- function(observations) {
state_names <- alphabet(observations)
n_states <- length(state_names)

nobs <- sum(!(observations == attr(observations, "nr") |
observations == attr(observations, "void") |
is.na(observations)))


if (nobs < prod(dim(observations))) {
if (any(observations == attr(observations, "nr"))) {
model <- build_hmm(
observations,
transition_probs = matrix(1 / n_states, n_states, n_states),
emission_probs = diag(n_states),
initial_probs = rep(1 / n_states, n_states),
state_names = state_names)
model <- fit_model(model)$model
message("Sequences contain missing/void values, initial and transition probabilities estimated via EM. ")
message("Sequences contain missing values, initial and transition probabilities estimated via EM. ")
} else {
first_timepoint <- suppressMessages(seqdef(observations[observations[, 1] %in% state_names, 1], alphabet = state_names))
initial_probs <- TraMineR::seqstatf(first_timepoint)[, 2] / 100
Expand Down

0 comments on commit 2a50b04

Please sign in to comment.