# read model output into R
model <- r4ss::SS_output()
# if maturity and/or fecundity is length-based, convert to age-based values
# if model is age based, skip ahead
# maturity * fecundity at length (matches product Mat and Fec columns)
spawn_output_at_length <- model$biology$"Mat*Fec"
# matrix of length at each age
len_at_age <- model$ALK[, , "Seas: 1 Sub_Seas: 1 Morph: 1"]
# matrix is in decreasing order of length, so reverse it
rownames(len_at_age)
len_at_age <- len_at_age[nrow(len_at_age):1, ]
rownames(len_at_age)
# spawning output at age is product of spawning output at length by distribution fo length-at-age
spawn_output_at_age1 <- spawn_output_at_length %*% len_at_age |> as.numeric()
# compare results above to spawning output at age in model output
spawn_output_at_age2 <- model$endgrowth |>
dplyr::filter(
Sex == 1
) |>
dplyr::pull("Mat*Fecund")
# confirm that spawning output at age matches
range(spawn_output_at_age1 - spawn_output_at_age2)
# female numbers at age in the final year of the model
n_at_age_fem <- model$natage |>
dplyr::filter(
Time == model$endyr,
Sex == 1
) |>
dplyr::select(paste(0:model$accuage)) |>
as.numeric()
# spawning output in the final year of the model
ssb_endyr1 <- model$timeseries |>
dplyr::filter(
Yr == model$endyr,
) |>
dplyr::pull(SpawnBio)
# sum of spawning output * numbers calculated above
ssb_endyr2 <- sum(spawn_output_at_age2 * n_at_age_fem)
# look at ratio of the values
ssb_endyr1 / ssb_endyr2