Skip to contents

Gets composition data proportions normalized according to the assessment specifications from RTMB

Usage

get_comp_prop(data, rep, age_labels, len_labels, year_labels)

Arguments

data

list of data inputs

rep

report file from RTMB

age_labels

vector of observed age labels in assessment

len_labels

vector of length labels in assessment

year_labels

vector of years

Value

List of fishery age, lengths, survey age, lengths dataframe as well as in matrix form (dimensioned by region, year, bin, sex, fleet)

Examples

if (FALSE) { # \dontrun{
comp_props <- get_comp_prop(data = data, rep = rep, age_labels = 2:31, len_labels = seq(41, 99, 2), year_labels = 1960:2024)
comp_props$Fishery_Ages %>%
  filter(Fleet == 1, Sex == 1) %>%
  ggplot() +
  geom_col(aes(x = Age, y = obs)) +
  geom_line(aes(x = Age, y = pred)) +
  facet_wrap(~Year, ncol = 3)

  comp_props$Survey_Ages %>%
    group_by(Region, Age, Sex, Fleet) %>%
    summarize(lwr_obs = quantile(obs, 0.1),
              upr_obs = quantile(obs, 0.9),
              lwr_pred = quantile(pred, 0.1),
              upr_pred = quantile(pred, 0.9),
              obs = mean(obs),
              pred = mean(pred)) %>%
    ggplot() +
    geom_line(mapping = aes(x = Age, y = obs, color = 'Obs', lty = 'Obs'), lwd = 1.3) +
    geom_ribbon(mapping = aes(x = Age, y = obs, ymin = lwr_obs, ymax = upr_obs, fill = 'Obs'), alpha = 0.3) +
    geom_line(mapping = aes(x = Age, y = pred, color = 'Pred', lty = 'Pred'), lwd = 1.3) +
    geom_ribbon(mapping = aes(x = Age, y = pred, ymin = lwr_pred, ymax = upr_pred, fill = 'Pred'), alpha = 0.3) +
    facet_grid(Region~Fleet, labeller = labeller(
      Region = c('1' = "Region 1"),
      Fleet = c('1' = 'Domestic LL Survey', '3' = 'JP LL Survey')
    )) +
    labs(x = 'Age', y = 'Proportion', color = '', linetype = '', fill = '') +
    theme_bw(base_size = 20) +
    theme(legend.position = 'top')
} # }