Why Repeat Simulations at the Same Locations?
An agent-based simulation can produce different outcomes for two distinct reasons. Random events—such as cell division, death, or movement—can make repeated runs differ even when the modeled environment is unchanged. In addition, cells at different locations may experience different signals, geometry, or boundary conditions, producing systematic spatial differences. A single simulated spatial pattern mixes these sources; repeated runs under a fixed spatial setup help separate them.
The separation is conditional on what is held fixed. If the geometry, initial conditions, parameter values, and spatial fields are identical across runs, run-to-run variation estimates the effect of stochastic events under that setup. Differences in average response across locations can then indicate location-dependent model behavior. They do not, by themselves, establish which environmental feature caused that behavior: location may also encode unmodeled initial conditions or implementation artifacts.
For a numerical comparison, suppose \(Y_{ij}\) is one spatial summary at location \(j\) in simulation run \(i\). Each run uses the same specified spatial setup, and each location is measured in every run. A simple model is
where \(\mu\) is an overall mean, \(\alpha_j\) is the fixed location effect, and \(\varepsilon_{ij}\) is the stochastic deviation. For the basic variance calculation, assume that the stochastic deviations have mean zero, common variance \(\sigma^2\), and are independent across runs and locations. The location effects are fixed across runs, with \(\sum_{j=1}^{J}\alpha_j=0\). These assumptions are approximations to check, not automatic properties of an agent-based model.
Estimating the Two Sources of Variation
Let \(J\) be the number of locations and \(R\) the number of repeated runs. At each location, calculate the run average \(\bar{Y}_{j\cdot}\). Variation among the observations within a location estimates stochastic variability: because the location is held fixed, its \(\alpha_j\) does not contribute to those deviations. Pooling the within-location sums of squares gives
The sample variance of the location averages is
where \(\bar{Y}_{\cdot\cdot}\) is the average across all locations and runs. This between-location variance includes both real differences among the \(\alpha_j\) values and noise in estimating each location’s mean. With \(R\) independent runs per location, the noise contribution to the variance of a location mean is \(\sigma^2/R\).
The correction follows from the variance of a location average. Since \(\bar{Y}_{j\cdot}=\mu+\alpha_j+\bar{\varepsilon}_{j\cdot}\), independent deviations with variance \(\sigma^2\) give \(\operatorname{Var}(\bar{\varepsilon}_{j\cdot})=\sigma^2/R\). Consequently, across locations the observed variance of the averages contains the location-effect variance plus this average-level noise:
Replacing \(\sigma^2\) with its pooled within-location estimate yields the stated correction. More runs reduce the noise contribution \(\sigma^2/R\), making spatial differences easier to resolve. This is a descriptive variance decomposition, not a significance test and not proof that a particular environmental mechanism caused the location effect.
Worked Calculations
Worked Example: Estimating Variability Across Three Locations
Suppose a hypothetical agent model reports local cell counts (cells per region) at three fixed tissue locations across four independent runs. The data are A: 8, 10, 9, 9; B: 14, 13, 15, 14; and C: 10, 11, 9, 10. The geometry and environmental fields are unchanged across runs.
The location means are A: \((8+10+9+9)/4=9\), B: \(56/4=14\), and C: \(40/4=10\). Their grand mean is \((9+14+10)/3=11\) cells per region. Within A, the squared deviations sum to \(1+1+0+0=2\). Within B they sum to \(0+1+1+0=2\), and within C they sum to \(0+1+1+0=2\). Thus
The variance among the three location means is \(( (9-11)^2+(14-11)^2+(10-11)^2 )/(3-1)=14/2=7.00\) \((\text{cells per region})^2\). Correcting for noise in each four-run mean gives
The observed location means differ considerably relative to the estimated run-to-run noise. Under the stated assumptions, this supports substantial location-dependent variation in expected local cell count for this setup. It does not identify the responsible spatial feature without further analysis.
Worked Example: Checking Whether an Environmental Gradient Matters
Consider a hypothetical controlled comparison at two locations, A and B, across four paired random seeds. Under a heterogeneous signal field, the local responses are A: 5, 7, 6, 6 and B: 9, 11, 10, 10 cells per region. The means are 6 and 10, so the average spatial contrast \(B-A\) is \(10-6=4\) cells per region. In each paired seed, the difference is also \(4\).
Now repeat the simulations with the signal field made spatially uniform, holding other setup choices fixed and using the same random seeds. Suppose the responses at both A and B are 7, 9, 8, 8. The mean at each location is 8, so the spatial contrast is \(8-8=0\). The within-location sample variance is \((1+1+0+0)/(4-1)=0.667\) \((\text{cells per region})^2\) at either location.
In this hypothetical result, the original four-cell contrast disappears when the field is homogenized, while run-to-run variability remains. That is evidence, within the model, that the specified gradient contributes to the spatial contrast. Reusing random seeds makes the comparison paired: shared random draws can reduce noise in the difference. The conclusion depends on the intervention changing only the intended field and on the simulation implementation not introducing other differences.
Worked Example: A Spatial Difference Can Be Clear Despite Run Noise
Suppose local signal concentration (arbitrary model units) at locations A and B is measured over three runs: A: 2, 3, 4 and B: 8, 9, 10. The means are 3 and 9, giving a spatial contrast of \(9-3=6\) units. At each location the sample variance is \((1+0+1)/(3-1)=1\) unit squared.
The variance of the two location means is \(((3-6)^2+(9-6)^2)/(2-1)=18\) unit squared. The estimated spatial variance is \(18-1/3=17.7\) unit squared. Thus stochastic fluctuations are present, but they are small relative to the observed contrast. Because there are only two locations and three runs, this estimate is imprecise; additional locations and runs would be needed to characterize variability across a larger tissue domain.
Diagnostics, Alternatives, and Limitations
Before interpreting a decomposition, verify that the replicates truly hold the intended setup fixed. Record the random seed or random-number stream, initial agent configuration, parameter values, boundary conditions, and spatial fields. Check that each run uses comparable update scheduling and that the spatial summary is calculated in the same way. A difference between locations is not interpretable as an environmental effect if one location also has a different initialization or measurement rule.
Inspect the per-location run averages and within-location spread, not only the two variance estimates. Plotting each run’s spatial profile can reveal a gradient, a localized hotspot, or a small number of extreme runs. A run-to-run pattern that persists across adjacent locations may indicate correlated stochastic noise. In that case, the independence assumption behind the simple correction fails, and \(s^2_{\mathrm{within}}/R\) may not correctly represent uncertainty in location means. Runs with different numbers of cells or unequal replication also require a method that accounts for that imbalance rather than this balanced formula.
The decomposition applies to a specified summary. A model may have low variability in total cell count but high variability in where cells accumulate. Therefore, define spatial summaries that answer the scientific question—such as regional counts, gradients, front positions, or spatially averaged signal—and analyze them separately when they capture different features. A single global average can erase spatial structure.
A mixed-effects model is a useful alternative when locations are viewed as sampled from a broader tissue domain, replication is unequal, or additional covariates are needed. It can represent location-to-location variance and run-level noise while accommodating a more complex design. A paired comparison of spatial contrasts across shared seeds is useful when comparing two environmental conditions. By contrast, simply comparing the variance of all individual cell outcomes across a whole tissue does not separate location effects from stochastic variation.
Finally, spatial variation in the expected simulation response is not the same as uncertainty about model parameters, nor does it automatically represent biological variation among patients or tissues. The estimates describe variability conditional on the model, its parameters, its spatial setup, and the chosen output summary. If spatial artifacts or mesh sensitivity could alter the pattern, those must be investigated separately; a variance decomposition cannot distinguish a biological mechanism from a numerical artifact on its own.
A Common Pitfall
A common mistake is to calculate the variance of every observed value across all locations and runs, then label it “stochastic variance.” That total spread includes systematic differences among location means as well as run-to-run noise. The correction is to first compare repeated runs within each fixed location to estimate stochastic variability, then compare location averages while accounting for the noise in those averages. Conversely, a large spatial contrast alone does not prove that the environment caused it; controlled changes to the spatial setup are needed to probe that explanation.
Check Your Understanding
Answer each question, then check the concise solutions below.
- At a fixed location, what source of variability does the within-location spread estimate under the simple model?
- If \(s^2_{\mathrm{means}}=2.4\), \(s^2_{\mathrm{within}}=1.2\), and \(R=3\), calculate the corrected spatial variance estimate.
- Why can the variance among location averages overstate spatial variability when there are few repeated runs?
- Name one reason the simple variance decomposition may be unreliable even when the same number of runs is used at each location.
- What does the disappearance of a spatial contrast after homogenizing an environmental field support, and what does it not establish?
Solutions. (1) Run-to-run stochastic variability conditional on the fixed location and setup. (2) \(2.4-1.2/3=2.0\) squared units. (3) Each location average contains stochastic noise with variance \(\sigma^2/R\), which contributes to the observed between-location variance. (4) For example, stochastic deviations may be correlated across locations, or the initial conditions may differ across runs. (5) It supports the field as a contributor to the model’s spatial contrast under the controlled comparison; it does not establish that the field is the sole cause or that the modeled mechanism is biologically true.