Skip to content

Commit

Permalink
fix another mistake in find and replace
Browse files Browse the repository at this point in the history
  • Loading branch information
helske committed Sep 6, 2024
1 parent 6fe434c commit 8915cec
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 15 deletions.
2 changes: 2 additions & 0 deletions R/estimate_mnhmm.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
#' states = mvad_scodes, labels = mvad_labels, xtstep = 6,
#' cpal = unname(colorpalette[[6]]))
#'
#' \dontrun{
#' set.seed(1)
#' fit <- estimate_mnhmm(mvad_seq, n_states = 3, n_clusters = 2)
#' }
estimate_mnhmm <- function(
observations, n_states, n_clusters, initial_formula = ~1,
transition_formula = ~1, emission_formula = ~1, cluster_formula = ~1,
Expand Down
2 changes: 2 additions & 0 deletions R/estimate_nhmm.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@
#' cpal = unname(colorpalette[[6]]))
#'
#' set.seed(1)
#' \dontrun{
#' fit <- estimate_nhmm(mvad_seq, n_states = 3)
#' }
estimate_nhmm <- function(
observations, n_states, initial_formula = ~1,
transition_formula = ~1, emission_formula = ~1,
Expand Down
2 changes: 1 addition & 1 deletion R/forwardBackward.R
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ forward_backward.mnhmm <- function(model, forward_only = FALSE,
model$n_clusters,
model$n_channels > 1
)
theta_raw <- model$coefficientstheta_raw
theta_raw <- model$coefficients$theta_raw
out <- list()
if (model$n_channels == 1) {
out$forward_probs <- forward_mnhmm_singlechannel(
Expand Down
2 changes: 1 addition & 1 deletion R/get_probs.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ get_probs.mnhmm <- function(model, newdata = NULL, nsim = 0,
X_transition <- aperm(model$X_transition, c(3, 1, 2))
X_emission <- aperm(model$X_emission, c(3, 1, 2))
X_cluster <- t(model$X_cluster)
theta_raw <- model$coefficientstheta_raw
theta_raw <- model$coefficients$theta_raw
initial_probs <- vector("list", D)
transition_probs <- vector("list", D)
emission_probs <- vector("list", D)
Expand Down
2 changes: 1 addition & 1 deletion R/hidden_paths.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ hidden_paths.mnhmm <- function(model, respect_void = TRUE, ...) {
model$n_clusters,
model$n_channels > 1
)
theta_raw <- model$coefficientstheta_raw
theta_raw <- model$coefficients$theta_raw
if (model$n_channels == 1) {
out <- viterbi_mnhmm_singlechannel(
beta_i_raw, X_initial,
Expand Down
2 changes: 1 addition & 1 deletion R/sample_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ sample_parameters <- function(model, nsim, probs, return_samples = FALSE) {
p_s <- length(beta_s_raw)
p_o <- length(beta_o_raw)
if (mixture) {
theta_raw <- model$coefficientstheta_raw
theta_raw <- model$coefficients$theta_raw
pars <- c(pars, theta_raw)
if (mixture) p_d <- length(theta_raw)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-build_mnhmm.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ test_that("estimate_mnhmm returns object of class 'mnhmm'", {
"y", s, d, initial_formula = ~ x, transition_formula = ~z,
emission_formula = ~ z, cluster_formula = ~ x,
data = data, time = "time", id = "id",
iter = 0),
iter = 0, verbose = FALSE, hessian = FALSE),
NA
)
expect_s3_class(
Expand Down
7 changes: 4 additions & 3 deletions tests/testthat/test-build_nhmm.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ test_that("build_nhmm returns object of class 'nhmm'", {
model <- build_nhmm(
obs, s, initial_formula = ~ x, transition_formula = ~z,
emission_formula = ~ z, data = data,
time = "time", id = "id", state_names = 1:s, channel_names = "obs"
time = "time", id = "id", state_names = 1:s, channel_names = "obs",
verbose = FALSE
),
NA
)
Expand All @@ -33,10 +34,10 @@ test_that("build_nhmm returns object of class 'nhmm'", {
})
test_that("estimate_nhmm returns object of class 'nhmm'", {
expect_error(
capture.output(fit <- estimate_nhmm(
fit <- estimate_nhmm(
"y", s, initial_formula = ~ x, transition_formula = ~z,
emission_formula = ~ z, data = data, time = "time", id = "id",
iter = 0)),
iter = 0, verbose = FALSE, hessian = FALSE),
NA
)
expect_s3_class(
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-forward_backward.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ test_that("'forward_backward' works for multichannel 'nhmm'", {
inits = hmm_biofam[
c("initial_probs", "transition_probs", "emission_probs")
],
iter = 1, verbose = FALSE, hessian = FALSE,
iter = 1, verbose = FALSE, hessian = FALSE
),
NA
)
Expand Down Expand Up @@ -93,7 +93,7 @@ test_that("'forward_backward' works for multichannel 'mnhmm'", {
expect_error(
fit <- estimate_mnhmm(
hmm_biofam$observations, n_states = 3, n_clusters = 2,
iter = 1, verbose = FALSE, hessian = FALSE,
iter = 1, verbose = FALSE, hessian = FALSE
),
NA
)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-hidden_paths.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test_that("'hidden_paths' works for 'nhmm'", {
inits = hmm_biofam[
c("initial_probs", "transition_probs", "emission_probs")
],
iter = 1, verbose = FALSE, hessian = FALSE,
iter = 1, verbose = FALSE, hessian = FALSE
),
NA
)
Expand Down Expand Up @@ -59,7 +59,7 @@ test_that("'hidden_paths' works for 'mnhmm'", {
expect_error(
fit <- estimate_mnhmm(
hmm_biofam$observations, n_states = 3, n_clusters = 2,
iter = 1, verbose = FALSE, hessian = FALSE,
iter = 1, verbose = FALSE, hessian = FALSE
),
NA
)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-posterior_probs.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ test_that("'posterior_probs' works for 'nhmm'", {
inits = hmm_biofam[
c("initial_probs", "transition_probs", "emission_probs")
],
iter = 1, verbose = FALSE, hessian = FALSE,
iter = 1, verbose = FALSE, hessian = FALSE
),
NA
)
Expand Down Expand Up @@ -74,7 +74,7 @@ test_that("'posterior_probs' works for 'mnhmm'", {
expect_error(
fit <- estimate_mnhmm(
hmm_biofam$observations, n_states = 3, n_clusters = 2,
iter = 1, verbose = FALSE, hessian = FALSE,
iter = 1, verbose = FALSE, hessian = FALSE
),
NA
)
Expand Down
21 changes: 20 additions & 1 deletion tests/testthat/test-simulate_mnhmm.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
test_that("simulate_mnhmm works", {
test_that("simulate_mnhmm, coef and get_probs works", {
set.seed(1)
p <- 50
n <- 10
Expand Down Expand Up @@ -35,5 +35,24 @@ test_that("simulate_mnhmm works", {
"*", "%")), names = ""), class = "table")

)
expect_error(
fit <- estimate_mnhmm(
sim$observations, n_states = 2,
n_clusters = 3,
initial_formula = ~1, transition_formula = ~ x,
emission_formula = ~ x + z, cluster_formula = ~w,
data = d, time = "month", id = "person",
init = sim$model$coefficients,
iter = 1, verbose = FALSE, hessian = FALSE),
NA
)
expect_error(
cf <- coef(fit),
NA
)
expect_error(
p <- get_probs(fit, nsim = 0),
NA
)
})

0 comments on commit 8915cec

Please sign in to comment.