Skip to content

Commit

Permalink
fix(data_mile1): sd of log(x) instead of CV
Browse files Browse the repository at this point in the history
For catch and index data the measurement of uncertainty should be the
standard deviation (sd) of the logged observations. The operating model
outputs a CV. I added a temporary function in data_mile1.R to calculate
the sd from the CV. In the future we will need to, behind the scenes,
take the log of the sd so the parameters stay within the bounds, which
is what the vignette is doing now. This time series of uncertainty can
later be fed to the modules but I did not change the vignette.

Close #136
  • Loading branch information
kellijohnson-NOAA committed Jun 20, 2024
1 parent f939fc0 commit 2c16ff4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
6 changes: 5 additions & 1 deletion R/data_mile1.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
#' viable units for the composition data, where the former is the preferred
#' unit of measurement.}
#' \item{uncertainty}{A real value providing a measurement of uncertainty
#' for value.}
#' for value. For catches and survey indices of abundance this should be
#' the standard deviation of the logged observations if you are using the
#' lognormal distribution to fit your data. For composition data it will
#' be your input sample size.
#' }
#' }
#' @source \url{www.github.com/Bai-Li-NOAA/Age_Structured_Stock_Assessment_Model_Comparison}
"data_mile1"
15 changes: 8 additions & 7 deletions data-raw/data_mile1.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
###############################################################################
# Helper functions and load packages
###############################################################################
cv_2_sd <- function(x) {
sqrt(log(x^2 + 1))
}

check_ASSAMC <- function() {
packages_all <- .packages(all.available = TRUE)
if (!"ASSAMC" %in% packages_all) {
Expand All @@ -25,6 +29,7 @@ check_ASSAMC <- function() {
library("ASSAMC")
return(TRUE)
}

check_ASSAMC()
library(dplyr)

Expand Down Expand Up @@ -52,11 +57,7 @@ landings_data <- data.frame(
),
value = returnedom[["em_input"]]$L.obs[[1]],
unit = "mt", # metric tons
# TODO: discuss if CV the appropriate input here given that landings will be
# modeled with a lognormal or similar likelihood. Just because previous
# models have used CV doesn't mean we have to continue to use it.
# E.g., `dlnorm(sdlog = )` uses a standard deviation on the log scale.
uncertainty = returnedom[["em_input"]]$cv.L[[1]]
uncertainty = cv_2_sd(returnedom[["em_input"]]$cv.L[[1]])
)

###############################################################################
Expand All @@ -76,7 +77,7 @@ index_data <- data.frame(
),
value = returnedom[["em_input"]]$surveyB.obs[[1]],
unit = "mt",
uncertainty = returnedom[["em_input"]]$cv.survey[[1]]
uncertainty = cv_2_sd(returnedom[["em_input"]]$cv.survey[[1]])
)

###############################################################################
Expand Down Expand Up @@ -164,7 +165,7 @@ unlink("FIMS_input_data.csv")

usethis::use_data(data_mile1, overwrite = TRUE)
rm(
check_ASSAMC,
check_ASSAMC, cv_2_sd,
age_data, landings_data, index_data, weightatage_data,
timingfishery, weightsfishery,
data_mile1, returnedom,
Expand Down
Binary file modified data/data_mile1.rda
Binary file not shown.
6 changes: 5 additions & 1 deletion man/data_mile1.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2c16ff4

Please sign in to comment.