Skip to main content
Version: 🚧 Alpha 🚧

4. Stochastic Analysis

Before applying any sensitivity analysis method, there is a fundamental question to answer: how much of the variability in nb_recovered is due to the random seed, and how many replications are needed to produce robust results?

The stochanalyse method summarizes output variability across replications for sampled parameter points. Its report can inform decisions about replication counts before interpreting later sensitivity analyses.

In particular, this step presents:

  • What the stochanalyse method measures and how to interpret its report
  • How repeat and sample interact in this context
  • How to use the permanent block to visualise stochastic spread directly in GAMA
  • How the result informs the repeat: value to use in subsequent batch experiments

The model file for this step can be found in: Tutorials/SIR Analysis/models/SIR_Stochanalysis.gaml


How stochanalyse works​

For each sampled parameter point, the method evaluates output variability across replications. The checked-in model sets sample: 100, repeat: 25 and keep_seed: false. The current implementation reports two measures for each output:

Report measureMeaning
Coefficient of variationThe replication count where the marginal decrease in the coefficient of variation first falls within the configured threshold.
Standard errorThe replication count where the marginal decrease in standard error first falls within the configured threshold.

For each measure, the report gives the minimum, maximum and average replication count across sampled parameter points. The thresholds are 0.05, 0.01 and 0.001; they set how small the marginal decrease must be relative to the minimum observed statistic before that replication count is selected. If no count meets a threshold, the largest tested replication count is reported. The model's settings request 100 parameter samples × 25 replications, for 2,500 simulation runs. These diagnostics do not select a universally appropriate repeat value.


The method stochanalyse statement​

The method is declared exactly like the others. The outputs: facet lists the global variables to analyse. The report: facet writes the human-readable indices to a .txt file. The sample: facet controls how many distinct parameter points are probed.

method stochanalyse
outputs: ["nb_recovered"]
report: "../results/stoch_report.txt"
results: "../results/stoch_raw.csv"
sampling: uniform
sample: 100;

Note: This model sets sampling: uniform explicitly. Set the sampling: facet to use a different sampling strategy.

Inside the SIR_Stochanalyse batch experiment, the model defines this permanent display to inspect output values across completed simulations:

permanent {
display "Stochastic spread" renderer: 3d {
chart "nb_recovered distribution across all runs" kind: histogram
background: #white {
data "nb_recovered"
value: simulations collect each.nb_recovered
color: #steelblue;
}
}
}

Reading the report​

The report is written to ../results/stoch_report.txt.

Generate the report for the sampling and replication settings used in your run, then interpret its estimates alongside those settings.

The stoch_report.txt file bundled with the example contains legacy critical-effect and power-test result sections. The current implementation generates result sections only for coefficient of variation and standard error, although its report header still mentions the effect-size and test settings. Rerun the experiment to generate a report with current results.

For each output and measure, the report lists the minimum, maximum and average replication count across sampled parameter points at each threshold. Interpret these values alongside the output, parameter ranges and sampling settings.

Choose the replication count based on the output, parameter ranges and thresholds relevant to the analysis. The following Morris, Sobol and Beta^d experiments define their own repeat settings; this tutorial does not infer one shared setting from the stochastic-analysis report.


Model in GAMA​

The complete runnable model is included in the SIR Analysis project: SIR_Stochanalysis.gaml.


What's next?​

Now that we know the stochastic contribution of the model, we can move on to sensitivity analysis. Step 5 introduces the Morris method, which screens parameters by their influence on nb_recovered at a low computational cost.