mycols <- c("FIMS" = "blue", "ASAP" = "red", "ASAP_orig" = "darkgreen")
for (i in 1:rdat$parms$nindices) {
index_results <- data.frame(
survey = i,
year = years,
observed = rdat$index.obs[[i]],
FIMS = report$index_expected[[rdat$parms$nfleet+i]],
ASAP = rdat$index.pred[[i]]
)
if (i==1){
allinds_results <- index_results
}else{
allinds_results <- rbind(allinds_results, index_results)
}
}
#print(allinds_results)
comp_index <- ggplot2::ggplot(allinds_results, ggplot2::aes(x = year, y = observed)) +
ggplot2::geom_point() +
ggplot2::geom_line(ggplot2::aes(x = year, y = FIMS), color = "blue") +
ggplot2::geom_line(ggplot2::aes(x = year, y = ASAP), color = "red") +
ggplot2::facet_wrap(~survey, scales = "free_y", nrow = 2) +
ggplot2::xlab("Year") +
ggplot2::ylab("Index") +
ggplot2::ggtitle("Blue=FIMS, Red=ASAP") +
ggplot2::theme_bw()
#print(comp_index)
catch_results <- data.frame(
observed = get_data(data_4_model) |>
dplyr::filter(type == "index", name == "survey1") |>
dplyr::pull(value),
FIMS = report$landings_expected[[1]],
ASAP = as.numeric(rdat$catch.pred[1,])
)
#print(catch_results)
comp_catch <- ggplot2::ggplot(catch_results, ggplot2::aes(x = years, y = observed)) +
ggplot2::geom_point() +
ggplot2::xlab("Year") +
ggplot2::ylab("Catch (mt)") +
ggplot2::geom_line(ggplot2::aes(x = years, y = FIMS), color = "blue") +
ggplot2::geom_line(ggplot2::aes(x = years, y = ASAP), color = "red") +
ggplot2::ggtitle("Blue=FIMS, Red=ASAP") +
ggplot2::theme_bw()
#print(comp_catch)
pop_results <- data.frame(
Year = c(years, max(years)+1, years, years, years, years, max(years)+1, years),
Metric = c(rep("SSB", 2*n_years+1), rep("F_mort", 2*n_years), rep("Recruitment", 2*n_years+1)),
Model = c(rep("FIMS", n_years+1), rep("ASAP", n_years), rep(c("FIMS", "ASAP"), each=n_years),
rep("FIMS", n_years+1), rep("ASAP", n_years)),
Value = c(
report$spawning_biomass[[1]],
rdat$SSB,
output |>
dplyr::filter(label == "log_Fmort", module_id == 1) |>
dplyr::pull(estimated) |>
exp(),
rdat$F.report,
report$expected_recruitment[[1]],
as.numeric(rdat$N.age[,1])
)
)
#print(pop_results)
# ggplot(filter(pop_results, Year <=2019), aes(x=Year, y=Value, color=Model)) +
# geom_line() +
# facet_wrap(~Metric, ncol=1, scales = "free_y") +
# theme_bw() +
# scale_color_manual(values = mycols)
orig_years <- seq(orig$parms$styr, orig$parms$endyr)
orig_pop_results <- data.frame(
Year = rep(orig_years, 3),
Metric = rep(c("SSB", "F_mort", "Recruitment"), each = length(orig_years)),
Model = "ASAP_orig",
Value = c(orig$SSB, orig$F.report, as.numeric(orig$N.age[,1]))
)
pop_results_3 <- rbind(pop_results, orig_pop_results)
#print(pop_results_3)
# ggplot(filter(pop_results_3, Year <=2019), aes(x=Year, y=Value, color=Model)) +
# geom_line() +
# facet_wrap(~Metric, ncol=1, scales = "free_y") +
# theme_bw() +
# scale_color_manual(values = mycols)
comp_FRSSB3 <- ggplot2::ggplot(pop_results_3, ggplot2::aes(x=Year, y=Value, color=Model)) +
ggplot2::geom_line() +
ggplot2::facet_wrap(~Metric, ncol=1, scales = "free_y") +
ggplot2::theme_bw() +
ggplot2::scale_color_manual(values = mycols)
#print(comp_FRSSB3)
FIMS_naa_results <- data.frame(
Year = rep(c(years, max(years)+1), each = n_ages),
Age = rep(ages, n_years+1),
Metric = "NAA",
Model = "FIMS",
Value = report$numbers_at_age[[1]]
)
ASAP_naa_results <- data.frame(
Year = rep(years, each = n_ages),
Age = rep(ages, n_years),
Metric = "NAA",
Model = "ASAP",
Value = as.numeric(t(rdat$N.age))
)
orig_naa_results <- data.frame(
Year = rep(orig_years, each = n_ages),
Age = rep(ages, length(orig_years)),
Metric = "NAA",
Model = "ASAP_orig",
Value = as.numeric(t(orig$N.age))
)
naa_results <- rbind(FIMS_naa_results, ASAP_naa_results, orig_naa_results)
#print(naa_results)
# ggplot(filter(naa_results, Year <= 2019), aes(x=Year, y=Value, color=Model)) +
# geom_line() +
# facet_wrap(~Age, ncol=1, scales = "free_y") +
# ylab("NAA") +
# theme_bw() +
# scale_color_manual(values = mycols)
comp_naa2 <- ggplot2::ggplot(
dplyr::filter(naa_results, Year <= 2019, Model %in% c("ASAP", "FIMS")), ggplot2::aes(x=Year, y=Value, color=Model)) +
ggplot2::geom_line() +
ggplot2::facet_wrap(~Age, ncol=1, scales = "free_y") +
ggplot2::ylab("NAA") +
ggplot2::theme_bw() +
ggplot2::scale_color_manual(values = mycols)
#print(comp_naa2)
# ggplot(filter(naa_results, Year == 1973, Model %in% c("ASAP", "FIMS")), aes(x=Age, y=Value, color=Model)) +
# geom_line() +
# ylab("NAA in Year 1") +
# theme_bw() +
# scale_color_manual(values = mycols)
saveplots <- TRUE
if(saveplots){
ggplot2::ggsave(filename = "figures/NEFSC_YT_compare_index.png", plot = comp_index, width = 4, height = 4, units = "in")
ggplot2::ggsave(filename = "figures/NEFSC_YT_compare_catch.png", plot = comp_catch, width = 4, height = 4, units = "in")
ggplot2::ggsave(filename = "figures/NEFSC_YT_compare_FRSSB3.png", plot = comp_FRSSB3, width = 5, height = 6.5, units = "in")
ggplot2::ggsave(filename = "figures/NEFSC_YT_compare_NAA2.png", plot = comp_naa2, width = 5, height = 6.5, units = "in")
}