-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed test data generation and single- and multi-individual testing…
… structures for constant model.
- Loading branch information
1 parent
8d3b268
commit cc8b9e3
Showing
12 changed files
with
1,598 additions
and
1,440 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file removed
BIN
-18.3 KB
tests/testthat/fixtures/constant/constant_baseline_output_multi_ind.rds
Binary file not shown.
Binary file removed
BIN
-6.78 KB
tests/testthat/fixtures/constant/constant_baseline_output_single_ind.rds
Binary file not shown.
Binary file modified
BIN
+9 Bytes
(100%)
tests/testthat/fixtures/constant/constant_data_multi_ind.rds
Binary file not shown.
Binary file modified
BIN
+8 Bytes
(100%)
tests/testthat/fixtures/constant/constant_data_single_ind.rds
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
rmot_test_model_functions <- function(model_name){ | ||
single_ind_name <- paste0(model_name, "_single_ind") | ||
multi_ind_name <- paste0(model_name, "_multi_ind") | ||
|
||
# Single individual | ||
expect_named(rmot_model(single_ind_name)) | ||
expect_type(rmot_model(single_ind_name), "list") | ||
expect_visible(rmot_model(single_ind_name)) | ||
#Multiple individuals | ||
expect_named(rmot_model(multi_ind_name)) | ||
expect_type(rmot_model(multi_ind_name), "list") | ||
expect_visible(rmot_model(multi_ind_name)) | ||
} | ||
|
||
rmot_test_single_individual <- function(model_name, | ||
par_names){ | ||
data <- readRDS(test_path("fixtures", model_name, | ||
paste0(model_name, "_data_single_ind.rds"))) | ||
|
||
# Test constant single individual | ||
suppressWarnings( #Suppresses stan warnings | ||
single_ind_test <- rmot_model(paste0(model_name, "_single_ind")) |> | ||
rmot_assign_data(n_obs = data$n_obs, #integer | ||
y_obs = data$y_obs, | ||
obs_index = data$obs_index, #vector length N_obs | ||
time = data$time, #Vector length N_obs | ||
y_0_obs = data$y_0_obs #vector length N_ind | ||
) |> | ||
rmot_run(chains = 1, iter = 1000, verbose = FALSE, show_messages = FALSE) | ||
) | ||
|
||
# Extract samples and check if parameter estimates are reasonable. | ||
ind_samples <- rstan::extract(single_ind_test, permuted = TRUE, | ||
inc_warmup = FALSE) | ||
par_ests <- c() | ||
for(i in length(par_names)){ | ||
par_ests[i] <- mean(ind_samples[[par_names[i]]]) | ||
} | ||
|
||
initial_condition <- mean(ind_samples$ind_y_0) | ||
expect_equal(par_ests, data$single_true_data$DE_pars, | ||
tolerance = 1e-1) | ||
expect_equal(initial_condition, data$single_true_data$initial_conditions, | ||
tolerance = 1e-1) | ||
|
||
# hecks for output existence and type | ||
expect_visible(single_ind_test) | ||
expect_s4_class(single_ind_test, "stanfit") | ||
} | ||
|
||
rmot_test_multi_individual <- function(model_name, data, est_dim){ | ||
# Test constant multi-individual | ||
suppressWarnings( #Suppresses stan warnings | ||
multi_ind_test <- rmot_model(paste0(model_name, "_multi_ind")) |> | ||
rmot_assign_data(n_obs = data$n_obs, #integer | ||
n_ind = data$n_ind, #integer | ||
y_obs = data$y_obs, #vector length N_obs | ||
obs_index = data$obs_index, #vector length N_obs | ||
time = data$time, #Vector length N_obs | ||
ind_id = data$ind_id, #Vector length N_obs | ||
y_0_obs = data$y_0_obs #vector length N_ind | ||
) |> | ||
rmot_run(chains = 2, iter = 100, verbose = FALSE, show_messages = FALSE) | ||
) | ||
|
||
# Extract samples | ||
multi_samples <- rstan::extract(multi_ind_test, permuted = FALSE, inc_warmup = TRUE) | ||
expect_equal(dim(multi_samples), c(100, 2, est_dim)) | ||
|
||
expect_visible(multi_ind_test) | ||
expect_s4_class(multi_ind_test, "stanfit") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#Testing for constant model | ||
test_that("Model structures: Constant", { | ||
# Single individual | ||
expect_named(rmot_model("constant_single_ind")) | ||
expect_type(rmot_model("constant_single_ind"), "list") | ||
expect_visible(rmot_model("constant_single_ind")) | ||
#Multiple individuals | ||
expect_named(rmot_model("constant_multi_ind")) | ||
expect_type(rmot_model("constant_multi_ind"), "list") | ||
expect_visible(rmot_model("constant_multi_ind")) | ||
}) | ||
|
||
test_that("Execution: Constant single individual", { | ||
model_name <- "constant" | ||
par_names <- "ind_beta" | ||
|
||
rmot_test_single_individual(model_name, par_names) | ||
}) | ||
|
||
test_that("Execution: Constant multiple individuals", { | ||
model_name <- "constant" | ||
|
||
data <- readRDS(test_path("fixtures", "constant", | ||
"constant_data_multi_ind.rds")) | ||
|
||
#Dimension is: | ||
est_dim <- data$n_ind + #Initial condition | ||
data$n_pars * data$n_ind + #Individual parameters | ||
data$n_pars * 2 + #Population parameters | ||
1 + #Global error | ||
data$n_obs + #y_ij | ||
data$n_obs + #Delta y_ij | ||
1 #lp__ | ||
|
||
rmot_test_multi_individual(model_name, data, est_dim) | ||
}) |