diff --git a/R/fit_nhmm.R b/R/fit_nhmm.R index 4225d34..3c78411 100644 --- a/R/fit_nhmm.R +++ b/R/fit_nhmm.R @@ -243,7 +243,7 @@ fit_nhmm <- function(model, inits, init_sd, restarts, lambda, method, logliks <- unlist(lapply(out, "[[", "penalized_logLik")) * n_obs optimum <- out[[which.max(logliks)]] - init <- setNames( + init <- stats::setNames( optimum[c("eta_pi", "eta_A", "eta_B")], c("pi", "A", "B") ) if (save_all_solutions) { diff --git a/man/estimate_mnhmm.Rd b/man/estimate_mnhmm.Rd index a64e5f7..de477dd 100644 --- a/man/estimate_mnhmm.Rd +++ b/man/estimate_mnhmm.Rd @@ -21,6 +21,8 @@ estimate_mnhmm( inits = "random", init_sd = 2, restarts = 0L, + lambda = 0, + method = "EM", store_data = TRUE, ... ) @@ -82,6 +84,14 @@ of the regression coefficients to zero, use \code{init_sd = 0}.} \item{restarts}{Number of times to run optimization using random starting values (in addition to the final run). Default is 0.} +\item{lambda}{Penalization factor \code{lambda} for penalized log-likelihood, where the +penalization is \code{lambda * sum(parameters^2)/(2 * n_obs)}, where \code{n_obs} is +the number of non-missing observations.} + +\item{method}{Optimization method used. Default is \code{"EM"} which uses EM +algorithm with L-BFGS in the M-step. Another option is \code{"DNM"} which uses +direct maximization of the log-likelihood using \code{\link[nloptr:nloptr]{nloptr::nloptr()}}.} + \item{store_data}{If \code{TRUE} (default), original data frame passed as \code{data} is stored to the model object. For large datasets, this can be set to \code{FALSE}, in which case you might need to pass the data separately to some diff --git a/man/estimate_nhmm.Rd b/man/estimate_nhmm.Rd index ab2d245..eb9d3d5 100644 --- a/man/estimate_nhmm.Rd +++ b/man/estimate_nhmm.Rd @@ -18,7 +18,7 @@ estimate_nhmm( inits = "random", init_sd = 2, restarts = 0L, - penalty = 0, + lambda = 0, method = "EM", store_data = TRUE, ... @@ -71,8 +71,8 @@ of the regression coefficients to zero, use \code{init_sd = 0}.} \item{restarts}{Number of times to run optimization using random starting values (in addition to the final run). Default is 0.} -\item{penalty}{Penalization factor for penalized log-likelihood, where the -penalization is \code{penalty * sum(parameters^2)/(2 * n_obs)}, where \code{n_obs} is +\item{lambda}{Penalization factor \code{lambda} for penalized log-likelihood, where the +penalization is \code{lambda * sum(parameters^2)/(2 * n_obs)}, where \code{n_obs} is the number of non-missing observations.} \item{method}{Optimization method used. Default is \code{"EM"} which uses EM diff --git a/tests/testthat/test-build_hmm.R b/tests/testthat/test-build_hmm.R index 3c4dc7d..54ba72c 100644 --- a/tests/testthat/test-build_hmm.R +++ b/tests/testthat/test-build_hmm.R @@ -83,11 +83,11 @@ test_that("build_hmm returns the correct probabilities", { expect_equal( rowSums(model$transition_probs), - setNames(rep(1, s), paste("State", 1:s)) + stats::setNames(rep(1, s), paste("State", 1:s)) ) expect_equal( rowSums(model$emission_probs), - setNames(rep(1, s), paste("State", 1:s)) + stats::setNames(rep(1, s), paste("State", 1:s)) ) expect_equal(colnames(model$emission_probs), letters[1:s]) expect_true(all(model$transition_probs >= 0)) diff --git a/tests/testthat/test-build_mm.R b/tests/testthat/test-build_mm.R index b5a2a37..09300d1 100644 --- a/tests/testthat/test-build_mm.R +++ b/tests/testthat/test-build_mm.R @@ -86,11 +86,11 @@ test_that("build_mm returns the correct probabilities", { ) expect_equal( rowSums(model$transition_probs), - setNames(rep(1, s), letters[1:s]) + stats::setNames(rep(1, s), letters[1:s]) ) expect_equal( rowSums(model$emission_probs), - setNames(rep(1, s), letters[1:s]) + stats::setNames(rep(1, s), letters[1:s]) ) expect_true(all(model$transition_probs >= 0)) expect_true(all(model$emission_probs >= 0)) diff --git a/tests/testthat/test-build_mmm.R b/tests/testthat/test-build_mmm.R index dbbfa3b..356c475 100644 --- a/tests/testthat/test-build_mmm.R +++ b/tests/testthat/test-build_mmm.R @@ -68,6 +68,6 @@ test_that("build_mmm returns the correct number of states", { ) expect_equal( lengths(model$initial_probs), - setNames(rep(s, k), paste("Cluster", 1:k)) + stats::setNames(rep(s, k), paste("Cluster", 1:k)) ) })