Skip to content

Commit

Permalink
Merge pull request #136 from pfmc-assessments/desgin_based
Browse files Browse the repository at this point in the history
Desgin based
  • Loading branch information
chantelwetzel-noaa authored Jul 9, 2024
2 parents cf8446b + e6a7433 commit c6723fd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion R/check_strata.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ check_strata <- function(

if (!is.null(dir)) {
write.csv(
x = out,
x = tows_by_strata,
file = file.path(plotdir, "strata_observations.csv"),
row.names = FALSE
)
Expand Down
14 changes: 6 additions & 8 deletions R/get_design_based.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#' Calculates design based estimates from survey data for West Coast surveys.
#'
#' @details
#' The design based index is calculated based on the area of the strata and
#' the mean catch by strata. This function returns a list of design-based
#' The design based index is calculated based on the area of the strata with the
#' output estimates representing the adjusted median estimates
#' (e.g., est * exp(0.5*log(var)). This function returns a list of design-based
#' estimates by strata and estimates combined across stratas by year. This
#' function is designed to work with data frames pulled from the NWFSC
#' data warehouse using [pull_catch()].
Expand Down Expand Up @@ -108,10 +109,7 @@ get_design_based <- function(
mean_cpue = mean(cpue_mt_km2),
var_cpue = var(cpue_mt_km2),
est = area * mean_cpue,
var = var_cpue * (area * area) / ntows,
cv = sqrt(var_cpue) / (mean_cpue + 1e-09),
log_var = sqrt(log(cv^2 + 1)),
se = log(cv^2 + 1)
var = var_cpue * (area * area) / ntows
) |>
dplyr::ungroup()

Expand Down Expand Up @@ -140,8 +138,8 @@ get_design_based <- function(
year = biomass[, "year"],
month = month,
fleet = fleet,
est = est,
se_log = se_log
est = biomass[, "est"],
se_log = biomass[, "se_log"]
)
write.csv(
biomass_out,
Expand Down
8 changes: 4 additions & 4 deletions R/plot_index.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#' 2. Design based index by year and strata.
#' @param width,height Numeric values for the figure width and height in
#' inches. The defaults are 7 by 7 inches.
#' @param res The resolution to apply when saving figures. Lower resolution values
#' @param dpi The resolution to apply when saving figures. Lower resolution values
#' can reduce file size which can be helpful when creating large documents
#' with many figures. The default is 300.
#'
Expand All @@ -34,7 +34,7 @@ plot_index <- function(
plot = 1:2,
height = 7,
width = 7,
res = 300) {
dpi = 300) {

plotdir <- file.path(dir, "plots")
check_dir(plotdir)
Expand Down Expand Up @@ -88,7 +88,7 @@ plot_index <- function(
if (!is.null(dir)) {
ggplot2::ggsave(
filename = plot_names[1], plot = gg,
height = height, width = width, units = "in", res = res
height = height, width = width, units = "in", dpi = dpi
)
} else {
print(gg)
Expand Down Expand Up @@ -117,7 +117,7 @@ plot_index <- function(
if (!is.null(dir)) {
ggplot2::ggsave(
filename = plot_names[1], plot = g2,
height = height, width = width, units = "in", res = res
height = height, width = width, units = "in", dpi = dpi
)
} else {
print(g2)
Expand Down

0 comments on commit c6723fd

Please sign in to comment.