knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  echo = TRUE,
  fig.width = 6
)

Different ways to simulate data, and to fit it, and to do multiple simulations with different stochasticity or assumptions/scenarios. Haven't yet decided on exact terminology. The notation in the code matches that in the write up of the second manuscript (in the edm-work repository).

# load_all()          # use this for local up-to-date testing
library(EDMsimulate)
library(pbsEDM)      # https://github.com/pbs-assess/pbsEDM

To run a simulation

sim_data <- salmon_sim()
sim_data

Simple plot of resulting time series of spawners

plot_sim(sim_data)

To run and plot in one go

salmon_run()

See ?salmon_sim for settings to change the default parameters and initial conditions for the simulations.

To do bifurcation diagrams

See code in salmon_bif.R, not needed here yet.

To fit using pbsEDM

Basing on example analysis in pbsEDM vignette analyse_simple_time_series.Rmd.

sim_fit <- pbsEDM::pbsEDM(sim_data,
                          lags = list(R_prime_t = 0,     # can test
                                        # others. Biologically defendible assumptions
                                      S_t = 0:3),
                          first_difference = TRUE)    # can try both
sim_fit$results

Try a deterministic simulation, and then again using the new sim_and_fit() wrapper:

sim_data_determ <- salmon_sim(deterministic = TRUE)

sim_fit_determ_fit <- pbsEDM::pbsEDM(sim_data_determ,
                          lags = list(R_prime_t = 0,     # can test
                                        # others. Biologically defendible assumptions
                                      S_t = 0:3),
                          first_difference = TRUE)    # can try both

# Then in one function
sim_fit_determ_fit_2 <- sim_and_fit(salmon_sim_args = list(deterministic =
                                                             TRUE),
                                    pbsEDM_args = list(lags = list(R_prime_t = 0,
                                                                   S_t = 0:3),
                                                       first_difference = TRUE))

# These should match:
sim_fit_determ_fit$results
sim_fit_determ_fit_2$fit$results
expect_equal(sim_fit_determ_fit$results,
             sim_fit_determ_fit_2$fit$results)

To run multiple realisations using the same parameter values but differing in stochasticity

Using the term realisations specifically for multiple runs that have the same parameters but only differ in the resulting process noise (i.e. just different due to stochasticity). Then scenarios for different assumptions of parameter values. Maybe scenarios A, B, and C for the three sets of assumptions on the proportions that we talked about last week, since they're the main things we want to change, and then numbered scenarios for changing other things (and A1, A2, ..., for combining them).

TODO centre and scale for all fits, go back and do functions and tests.

Then vary over E, but not simple as need to vary over multivariate lags. So need to pick the best combination of lags, not the best E.

Then do s-map as well using the best lags? May as well, to get the best results. Then do the uncertainty ideas on just the optimal ones (getting a confidence interval for each realisation).



andrew-edwards/EDMsimulate documentation built on Oct. 25, 2023, 2:43 p.m.