library(magrittr)
ling_imm <- g3_stock(c(species = 'ling', 'imm'), seq(20, 156, 4)) %>% g3s_age(3, 10)
initialconditions_action <- g3a_initialconditions_normalparam(
ling_imm,
factor_f = g3a_renewal_initabund(by_stock_f = 'species'),
by_stock = 'species',
by_age = TRUE)
# Timekeeping action
time_action <- g3a_time(
start_year = 2000,
end_year = 2004,
c(3, 3, 3, 3))
# Generate a model from the above 2 actions
# NB: Obviously in reality we'd need more actions
fn <- g3_to_r(list(initialconditions_action, time_action))
if (interactive()) {
# Edit the resulting function
fn <- edit(fn)
}
param <- attr(fn, 'parameter_template')
param$project_years <- 0
param$ling.init.F <- 0.4
param$ling.Linf <- 160
param$ling.K <- 90
param$ling.recl <- 12
param$recage <- g3_stock_def(ling_imm, 'minage')
param[grepl('^ling.init.sd.', names(param))] <- 50.527220
param[grepl('^ling_imm.init.\\d+', names(param))] <- 1
param$ling_imm.init.scalar <- 200
param$ling_imm.walpha <- 2.27567436711055e-06
param$ling_imm.wbeta <- 3.20200445996187
param$ling_imm.M <- 0.15
# Run the model with the provided parameters
nll <- fn(param)
# Get the report from the last model run
report <- attributes(nll)
# Fetch a value from the model data
environment(fn)$ling_imm__midlen
stopifnot(dim(environment(fn)$ling_imm__midlen) == 35)
Run the code above in your browser using DataLab