From 2956bcd7810689a5bf3752f5c8ceca4001e7b0de Mon Sep 17 00:00:00 2001 From: Andrea-Havron-NOAA <85530309+Andrea-Havron-NOAA@users.noreply.github.com> Date: Sat, 5 Oct 2024 22:18:51 +0000 Subject: [PATCH] replace process distribution with helper function in tests --- .../testthat/helper-integration-tests-setup.R | 21 ++++++------------- vignettes/fims-demo.Rmd | 17 +++++---------- 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/tests/testthat/helper-integration-tests-setup.R b/tests/testthat/helper-integration-tests-setup.R index 5c58fa77..7690a150 100644 --- a/tests/testthat/helper-integration-tests-setup.R +++ b/tests/testthat/helper-integration-tests-setup.R @@ -82,21 +82,12 @@ setup_and_run_FIMS <- function(iter_id, # alternative setting: recruitment$log_devs <- rep(0, length(om_input$logR.resid)) recruitment$log_devs <- methods::new(ParameterVector, om_input$logR.resid[-1], om_input$nyr-1) - recruitment_distribution <- new(TMBDnormDistribution) - # set up logR_sd using the normal log_sd parameter - # logR_sd is NOT logged. It needs to enter the model logged b/c the exp() is - # taken before the likelihood calculation - recruitment_distribution$log_sd <- new(ParameterVector, 1) - recruitment_distribution$log_sd[1]$value <- log(om_input$logR_sd) - recruitment_distribution$log_sd[1]$estimated <- FALSE - recruitment_distribution$x <- new(ParameterVector, om_input$nyr) - recruitment_distribution$expected_values <- new(ParameterVector, om_input$nyr) - for (i in 1:om_input$nyr) { - recruitment_distribution$x[i]$value <- 0 - recruitment_distribution$expected_values[i]$value <- 0 - } - recruitment_distribution$set_distribution_links("random_effects", recruitment$log_devs$get_id()) - recruitment$estimate_log_devs <- TRUE + recruitment_distribution <- + new_process_distribution(par = "log_devs", module = recruitment, family = gaussian(), + sd = list(value = om_input$logR_sd, estimated = FALSE), + is_random_effect = FALSE) + + recruitment$estimate_log_devs = TRUE # Data catch <- em_input$L.obs$fleet1 diff --git a/vignettes/fims-demo.Rmd b/vignettes/fims-demo.Rmd index 6bd5858a..eaf75c3e 100644 --- a/vignettes/fims-demo.Rmd +++ b/vignettes/fims-demo.Rmd @@ -283,18 +283,11 @@ recruitment$log_devs <- new(ParameterVector, c( In order to estimate *log_devs*, a new distribution needs to be created. This will be left commented out as we will proceed with not estimating log_devs. ```{r recruitment-distribution} -recruitment_distribution <- new(TMBDnormDistribution) -recruitment_distribution$log_sd <- new(ParameterVector, 1) -recruitment_distribution$log_sd[1]$value <- log(0.4) -recruitment_distribution$log_sd[1]$estimated = FALSE -# set dimension of observations -recruitment_distribution$x <- new(ParameterVector, nyears) -recruitment_distribution$expected_values <- new(ParameterVector, nyears) -for(i in 1:nyears){ - recruitment_distribution$x[i]$value <- 0 - recruitment_distribution$expected_values[i]$value <- 0 -} -recruitment_distribution$set_distribution_links("random_effects", recruitment$log_devs$get_id()) +recruitment_distribution <- + new_process_distribution(par = "log_devs", module = recruitment, family = gaussian(), + sd = list(value = 0.4, estimated = FALSE), + is_random_effect = FALSE) + recruitment$estimate_log_devs = TRUE ```