Skip to content

Commit

Permalink
replace process distribution with helper function in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea-Havron-NOAA committed Oct 5, 2024
1 parent 77b030e commit 2956bcd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 27 deletions.
21 changes: 6 additions & 15 deletions tests/testthat/helper-integration-tests-setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 5 additions & 12 deletions vignettes/fims-demo.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down

0 comments on commit 2956bcd

Please sign in to comment.