Skip to content

Sensitivity Indices

PRCC is the partial rank correlation coefficient. The script computes it for each parameter that a Sensitivity batch varied, against each output variable. It reads the collated Output.csv of the batch and the parameter values drawn behind it. It ranks the parameters by effect size and writes one tornado chart per output variable.

The app bundles this script as Sensitivity_Indices.R and Sensitivity_Indices.py. Type the bare file name as a Script’s File, or pick it with Bundled scripts… on a Script row. A copy beside the Experiment file runs in place of the bundled one. See Run your own R or Python. Back to the Scripts.

FileNeeds
Sensitivity_Indices.RRscript, jsonlite and ggplot2. Install them with install.packages(c("jsonlite", "ggplot2"))
Sensitivity_Indices.pypython3, pandas, numpy and matplotlib. Install them with pip install pandas numpy matplotlib

The two agree to 1e-9 on the same input. The test suite checks this on every fixture.

Requirements

LanguageNeeds
PythonPython 3.11 or later, with pandas, numpy and matplotlib. Install them with pip install pandas numpy matplotlib.
RR 4.3 or later, with jsonlite and ggplot2. Install them with install.packages(c("jsonlite", "ggplot2")).

The test suite runs on these versions in GitHub Actions. Older versions are not tested.

What It Computes

PRCC1 measures the effect of one parameter on an output and holds the effect of every other parameter constant. For each parameter, the script takes these steps:

  1. It rank-transforms every parameter and the output over the Samples.
  2. It drops each parameter column with no variance at all. Such a column would make the fit singular.
  3. It regresses the rank of the parameter on the ranks of every OTHER parameter. It does the same for the rank of the output.
  4. It correlates the residuals of the two regressions.

A value near 1 or -1 is a strong, monotonic effect. A value near 0 is a weak one, after the script removes the effect of every other parameter.

PRCC needs more Samples than parameters. With exactly one Sample per parameter plus one, the residual space has a single dimension. Then |PRCC| is 1 by construction, whatever the data. The script refuses a Variable with too few Samples and does not report that number.

The result goes to Sensitivity_Indices.csv beside Output.csv. It has one row per (Variable, Parameter) pair, with the Sample count behind it and a Rank by |PRCC| within that Variable. A parameter with no defined PRCC prints blank and ranks last. A constant column has no PRCC. A column that is too collinear with the others to resolve has none either.

Sensitivity_Indices_<Variable>.png is one chart per output variable. It draws the parameters as horizontal bars in Rank order. The longest bar is the largest effect. Each bar carries its parameter name as a label. The PRCC value is on the x axis.

Which rows count

Each sample is a job row of Output.csv, told apart by the source_kind column. The script skips saved_run rows, and a source name never decides which rows count.

Choosing the Dataset

The Output.csv of a sweep can carry more than one dataset. EXPERIMENTER_DATASET selects one. If the file holds more than one dataset and you select none, the script stops. It does not mix their Samples.

Which Time Is Scored

The Output.csv of a Sensitivity batch carries a time series for each Sample, not one value. This script scores one time for each run. By default it scores the last time that Output.csv carries. If you set EXPERIMENTER_SENSITIVITY_TIME, it scores that time:

EXPERIMENTER_SENSITIVITY_TIME=2040 Rscript Sensitivity_Indices.R

If the file does not carry the time, the script stops and lists the times that it does carry.

In an Experimenter Script step, write the variable with env. A Script step starts the command without a shell, so NAME=value Rscript ... fails to launch. The env form starts, and the step uses the copy of the script that ships with the app, as it does without env. A copy of the script in the folder of the Experiment takes precedence.

env EXPERIMENTER_SENSITIVITY_TIME=2040 Rscript Sensitivity_Indices.R

Why No Sobol

This script computes PRCC on every batch, whatever method drew the sample. The first-order and total-order indices of Sobol2, 3 need a special sample design. It holds a base matrix and its cross-matrices, each matched to its output. No Experimenter batch writes that design, so the script does not compute those indices.

PRCC needs only the drawn values and the output. It is valid on a Sobol sequence, because a space-filling design suits PRCC as well as a Latin hypercube does. A batch drawn by sobol_sequence therefore gets PRCC, and the summary line names the method.

What It Prints

One summary line. It holds the variable count, the parameter count, the Sample count and the sampling method, the scored time, and the number of tornado charts that the script wrote. A Stella batch records no sampling method, and the line says so. The script also prints one line for each parameter column that it leaves out, with the reason. Each of these cases stops the script with a message that names the problem:

  • A missing output folder, a folder that does not exist, or a missing Output.csv.
  • A file that lacks source, source_kind, variable or value, or an unknown column.
  • No sample column.
  • An unrecoverable sample. The message reads “no job here recorded the parameter values it drew”.
  • A blank cell in a parameter column that has values in other Samples, or no parameter column with values.
  • A cell in a parameter column that is not a decimal number. The script reads a sign, digits, a decimal point and an exponent. NaN, Inf and hexadecimal text stop the script in both languages.
  • Too few Samples for the parameter count.
  • An unknown scored time.
  • A repeated (variable, Sample) pair.

Reading a Sensitivity Batch

This script reads the Output.csv of the Sensitivity, the one with its sample column populated. It also reads the parameter values drawn for that Sensitivity, from sample.csv in the job folder. The job entry in the Batch record (batch.json) names that file. Both engines write it:

EngineField in the job entry
Pythonexperimenter.sensitivity.sample_file, with the sampling method
Stellasensitivity_output.sample_file.file, with no sampling method

Experimenter reads the Stella values out of the comparative table that Stella exports. For some inputs the export holds no value. Then the column in sample.csv is empty, and the empty field of the record gives one of these reasons:

  • The input is not in the model, or more than one module holds it.
  • The input is a graphical function.
  • The input is an array named without one element.
  • The export has no value column for the input.

The script leaves that column out of the PRCC and prints the reason.

With no argument, the folder of the Sensitivity comes from EXPERIMENTER_OUTPUT_DIR. This is the shape that an Experimenter Script step runs in. You can also give the folder of a finished batch by hand as the first command-line argument. Then the script finds the time column by elimination against the column set that Experimenter publishes. This is the rule of Script_Template.R. The argument wins when you give both.

Rscript Sensitivity_Indices.R /path/to/Outputs/MySensitivity

In a Chain

The script reads Output.csv and writes Sensitivity_Indices.csv and one Sensitivity_Indices_<variable>.png per variable into the same folder. It writes one file for the whole batch, so no dataset name is in the file name. No other script reads these files. See the chaining rules.

Version Policy

The library README sets the format policy. The header of this file names the Experimenter version that it targets. The script checks every column before it reads anything. An unknown column stops the script with a message that names it. A version difference prints one line and does not stop the run.

References

  1. Marino, S., Hogue, I.B., Ray, C.J., Kirschner, D.E. (2008). A methodology for performing global uncertainty and sensitivity analysis in systems biology. Journal of Theoretical Biology, 254(1), 178-196. doi:10.1016/j.jtbi.2008.04.011. Defines the PRCC procedure this script implements: rank-transform, regress out the other parameters, correlate the residuals.
  2. Sobol, I.M. (2001). Global sensitivity indices for nonlinear mathematical models and their Monte Carlo estimates. Mathematics and Computers in Simulation, 55(1-3), 271-280. doi:10.1016/S0378-4754(00)00270-6. Defines the first- and total-order indices this script does not compute (see “Why No Sobol”).
  3. Saltelli, A., Annoni, P., Azzini, I., Campolongo, F., Ratto, M., Tarantola, S. (2010). Variance based sensitivity analysis of model output. Design and estimator for the total sensitivity index. Computer Physics Communications, 181(2), 259-270. doi:10.1016/j.cpc.2009.09.018. The estimator that Experimenter would need to write a Sobol-sampled batch against.