Skip to main content
PLOS Computational Biology logoLink to PLOS Computational Biology
. 2026 Sep 15;22(9):e1014786. doi: 10.1371/journal.pcbi.1014786

R-package agentBayes: Likelihood-based statistical methods for agent-based models

Niklas Moser 1,*, Dmitri Finkelshtein 2, Georgy Chargaziya 2, Stephen J Cornell 3, Sara Hamis 4, Jacob G Scott 5, Dagim Shiferaw Tadele 5,6, Otso Ovaskainen 1
Editor: Ovidiu Radulescu7
PMCID: PMC13619099  PMID: 42743361

Abstract

Statistically analysing interacting particle systems remains challenging because the governing equations are analytically intractable. Existing solutions include moment closure methods with pseudolikelihood-based frameworks, and likelihood-free frameworks based on extensive simulations, both relying on heuristic choices whose validity is difficult to predict. As a resolution, we rigorously derive an asymptotically exact expression for the likelihood of agent-based models (ABMs) operating in continuous space and time that can be formulated as reactant–catalyst–product (RCP) models. We derive an expression for the conditional density of agents given information about the current and earlier distributions of neighbouring agents. We utilize this expression to construct an asymptotically exact likelihood that applies to both spatial snapshot and time-series data. We implement the likelihood expression and a Bayesian parameter estimation framework in the R-package agentBayes and demonstrate its utility in biological research and beyond with simulated case studies and empirical data on the evolution of cancer cell populations.

Author summary

Many study systems across biology, finance, physics and the social sciences consist of discrete interacting agents, yet fitting agent-based models to data remains challenging as most models are too complicated to be treated analytically. We resolve this fundamental challenge and derive tractable likelihoods for a broad class of agent-based models and data, such as spatial snapshot and time-series data. Accompanied by our statistical software, we show how to apply our framework to address biological research questions at the example of the coevolution of cancer cell populations.

Introduction

In many disciplines, a rich array of phenomena can be described by interactions of discrete entities. These entities are often called individuals or agents in biology [1], sociology [2] and finance [3], or particles in physics [4] and chemistry [5]. The governing equations of such interacting particle systems can be described through stochastic agent-level processes of local interactions, from which patterns at larger spatial and temporal scales emerge [6].

Agent-level process descriptions are well poised for probing many study systems, which has led to a rich theoretical literature on agent-based models (ABMs) [7–11]. However, relating such models to data is highly challenging due to the analytical intractability of the governing equations. As a consequence, most methods targeted to data analysis are of correlative nature and operate at the level of aggregates rather than at the level of the interacting agents. As one example, in ecology generalized linear models [12–14] or ordinations [15–17] are used to link environment and spatial predictors to species abundances or occurrences. However, these models do not directly address the underlying agent-level processes which makes the interpretation of inferred parameters difficult [18–20]. Agent-level correlative models such as statistical point process models [21,22] use agent-level data, but still infer aggregate-level patterns, e.g., moments, rather than the underlying interactions. Mechanistic models address directly the underlying processes, but even simple aggregate-level mechanistic models [23–25] typically rely either on heuristic methods or make strong assumptions, e.g., pseudolikelihoods, in order to fit them to data.

Most attempts to parametrize ABMs use likelihood-free methods, e.g., approximate Bayesian computation, which depend on heuristic choices of summary characteristics, extensive simulations or simpler surrogate models [26–30]. Besides the usage of ABMs as simulators only, attempts have been made to build likelihoods from the governing microscopic equations, i.e., stochastic differential equations or master equations. Even if such equations can be formulated, solving them to determine the probability density of a given observation is generally analytically not possible. Therefore, microscopic treatments resort to numerical integration and variational inference approaches [31]. Mesoscopic treatments take advantage of the linear noise approximation [32–34] or moment closure methods [35,36]. Applying these likelihood-based approaches requires elaborate derivations for each specific model and their suitability greatly varies among study systems, data and computational resources. Thus, there is a need for a mathematically rigorous likelihood-based framework applicable across broad classes of ABMs.

In this paper, we overcome the above-described limitations by rigorously deriving an asymptotically (in the limit of long-ranged interactions) exact tractable likelihood for the broad class of ABMs that can be formulated as continuous-space, continuous-time reactant-catalyst-product (RCP) models. Our contributions are twofold: (i) we derive novel expressions for the local agent densities that enable deriving tractable likelihoods for RCP models and (ii) we develop the R-package agentBayes that automates the application of the likelihood framework. Regarding (i), using a perturbation expansion to compute spatiotemporal moments and cumulants of any order [37], we derive expressions for the expected local densities of agents unconditional and conditional on past and/or current observations of agents of the same or other types. Using the conditional expectation, we derive the joint probability of data observed over multiple locations and feed this likelihood into a Bayesian framework to infer model parameters such as the strength and length scale of interactions. Regarding (ii), we develop the accompanying R-package agentBayes that automates the derivation of the likelihood expression for any RCP model, facilitating the application of our framework with minimal technical effort (Fig 1). We illustrate the utility and general applicability of the approach with simulated and empirical snapshot and time-series data in both transient and stationary regimes.

Fig 1. Workflow of likelihood-based analysis of agent-based models using the R-package agentBayes.

Fig 1

Step 1 verbally defines a model through information on the types of agents and their interactions. Step 2 extracts from the verbal model definition the model components, which are described through the rates at which each process takes place and the state of the system before and after the process occurs [37]. Step 3 converts the model components into computer-readable pseudocode saved in a text file. Step 4 loads the R package, derives the governing equations, and initializes the numerical solvers. Step 5 calculates the log-likelihood of the data, given the model and a parameter vector θ, and applies this likelihood in a Bayesian parameter estimation framework. Step 6 validates the fitted model by, e.g., comparing it with independent data and uses the model for inference and prediction.

Results

A general expression of the likelihood of data under an RCP model

The RCP framework encompasses a large family of models of interactive particles in continuous space and time [37]. As one seldom has data on the exact spatiotemporal distribution of agents of all types at all times, we developed our methods for sample plot data. Thus, we assume that a researcher has recorded the number of agents (of all or some types) in discrete and finite-size plots i at locations xi. In the examples of this paper, we model snapshot data by assuming that the numbers of agents in sample plots follow the Poisson distribution ys,i~ Poisson(δirs,i), where ys,i is the number of agents of type s observed in the sample plot i, rs,i  is the (conditional) expectation of the density of agents, generated by an RCP model, of type s at location xi as defined below, and δi is the area of the sample plot. We note that even if the assumption of the Poisson distribution may not hold for many models for large sample plots, it typically holds when the area of the sample plot δi is small compared to the density of agents so that the number of agents per plot is small. In the case of time-series data, we model directly the transition rates, i.e., the rates at which new agents appear and existing agents disappear, as explained in more detail below.

The cornerstone for deriving the likelihood of data for the general class of RCP models is the observation that it is possible to predict the density of agents not only in terms of its expectation, but also in terms of its covariance structure. This is non-trivial, as RCP models are stochastic agent-based models operating in continuous space and continuous time, and hence the spatiotemporal distribution of agents is an emergent property of the model rather than directly a state-variable. If simulating realizations of an RCP model, the number of agents of all types s that are present in all sample plots i at the time of sampling will vary and hence can be considered as a multivariate random variable denoted by 𝐘={Ys,i}s,i. We denote by 𝐙={Zs,i}s,i the multivariate random variable of realized agent densities of all agent types s in all sample plots i, with Zs,i=Ys,i/δi defined as the number of agents of type s in sample plot i, divided by the area of the sample plot δi. Using mathematical methodology developed for RCP models [37], the expected value of the density at location i can be predicted as

E[Zs,i]=qs,i+εdps,i+o(εd).  (1)

Equation (1) is a first-order perturbation around a non-spatial mean-field model, where qs,i is the mean-field prediction, ps,i is the first-order correction term, ε describes the assumed spatial scale of interactions (with ε→0 corresponding to global interactions), and d is the dimensions of the space (commonly d=2 in ecological applications). The notation o(εd) is used for terms of strictly higher order in ε than d, and hence which vanish faster as ε→0 than εd. Closed-form expressions are available for both qs,i and ps,i for the general family of RCP models. Furthermore, the variance of the density can be predicted as

Var(Zs,i)=qs,i+εdps,iδi+o(εd), (2)

and the covariance between the densities of two types of agents in two locations as

Cov(Zs1,i1,Zs2,i2)=εdgs1,s2(2)(εxi1,εxi2)+o(εd). (3)

A closed-form expression for the first-order approximation of the two-point spatial cumulant gs1,s2(2) is available for the general family of RCP models.

We consider the random vector of agent densities 𝐙 to follow a multivariate distribution whose distributional form is unknown, but the expectation μ=E[𝐙] and variance-covariance matrix Σ with elements σj1j2:= Cov(Zs(j1),i(j1),Zs(j2),i(j2)) known, as they are defined by equations (1)–(3). Here, we denote the number of a given agent type s(j) at a given sample plot i(j), with the index j=1…n going over all combinations of agent types and sample plots.

Accounting for the mathematically predicted variance-covariance structure enables one to predict the expected value of the density Zs,i conditional on some of the observed densities zs,i:= ys,i/δi, with the observed number of agents ys,i being a realisation of the random variable Ys,i, and hence beyond the marginal expectation of equation (1). We define such a conditioning generally through the equation 𝐔𝐙=𝐛, where 𝐛:=𝐔𝐳 denotes the observed realization of the random variable 𝐔𝐙, 𝐔 is some k×n matrix of rank k. Then the conditional expectation of 𝐙 can be formulated as

E[𝐙|𝐔𝐙=𝐛]=μ+𝐂(𝐛−𝐔μ)+o(εd), (4)

where 𝐂= Σ𝐔T(𝐔Σ𝐔T)−1.

As exemplified below, when predicting a particular observation j, in some cases one wishes to condition the prediction on all other observations, whereas in other cases only on a particular subset. To enable a general approach, we denote by 𝐔(j) and 𝐛(j)=𝐔(j)𝐳 the conditioning applied when predicting the observation zj, resulting in the matrix 𝐂(j). We note that 𝐂(j) of equation (4) does not need to be computed from scratch for each j, but its values can be updated computationally efficiently using simple recursive formulae. We further note that as we wish to predict only the element zj (instead of the entire vector 𝐳) conditional on 𝐔(j) and 𝐛(j), one needs to include only the jth rows of the matrix 𝐂(j) when applying equation (4). As further exemplified below, the process may be partially observed, so that the data may not contain all agent types, even if they are part of the model dynamics and thus remain components of the multivariate random variable 𝐙.

The procedure described above produces an asymptotically exact likelihood in the limit where the spatial scale parameter ε is small, so that equations (1)–(3) become accurate, and the number of agents per cell can be assumed to follow a Poisson distribution. For cases where the Poisson distribution is not appropriate, one can utilize other distributional assumptions. As one alternative, we derive an expression for the likelihood assuming the multivariate normal distribution, whose covariance structure we assume to follow equations (1)–(3). Due to the Central Limit Theorem, the multivariate normal likelihood is likely to be a good approximation in case there are many agents within a sampling plot, e.g., when the sampling plot size is large. The multivariate normal likelihood is computationally cheaper to evaluate numerically than the Poisson distribution, as it can be computed directly from the covariance matrix without the need to construct it incrementally cell by cell. In cases that may conform directly to neither the multivariate normal likelihood nor the Poisson likelihood, it can be instructive to compare the parameter estimates provided by both alternatives. We illustrate the accuracy of the likelihood approximation by comparing likelihood profiles for the simulated data example, see S1 File.

We next illustrate the general framework of equations (1)–(4) with three case studies, out of which the first two are based on simulated data of a simple toy model, and the third one on a more complex model applied to empirical data.

Case study one: Snapshot data on a single species

As a toy model, we consider the spatial and stochastic logistic model (SSLM) which has been extensively studied in theoretical ecology [9,10,38,39]. This model consists of a single agent type for which the dynamics are governed by three processes: (i) density-independent death, (ii) density-dependent death, and (iii) dispersal and reproduction. Density-independent death occurs at rate m. For an agent at location x, density-dependent death occurs at rate ∑y ∈ γ∖xa−(x−y), where γ denotes the current set of agents, and the spatial kernel function a− describes how much the presence of another agent at location y increases the death rate (e.g., due to competitive interactions) of an agent located at x, with the kernel’s integral A−=∫a−(x)dx modelling the overall strength of competition. Reproduction and dispersal is defined by the spatial kernel function a+, such that an individual at location x produces offspring to the vicinity of y with the per unit-area rate a+(x−y), and A+=∫a+(x)dx is the total rate at which each agent produces offspring.

We simulated a particular parameterization of the model, with Fig 2a illustrating the distribution of agents at the end of a simulation. We assumed that data 𝐲 on counts of agents were available from sample plots that form a regular grid (blue area in Fig 2a) of N grid cells, each of equal size δ, so that the observed density is 𝐳=𝐲/δ. In the case of a single agent type, the index s in ys,i is redundant, and thus i(j)=j, and the dimension of 𝐲 is simply the number grid cells, n=N. We partition the joint probability of observing the data into the product of conditional probabilities as follows:

Fig 2. Results of the case study on snapshot data on a single species.

Fig 2

a, Snapshot of the simulation at the final time t=6, where agents are shown by black dots. The blue area showcases the discretization of the point pattern with grid cell size δ=1 used in c-d. b, Comparison of the empirical two-point cumulant (dots) with its theoretical expectation (line). Here the empirical values represent averages over 100 replicated simulations, and the error bars represent ± 2 standard errors. c, Comparison of predicted densities (horizontal axis) and observed densities (vertical axis) in grid cells of the discretized domain of the 100 replicated simulations. In this panel the predicted values are based on conditioning on all other observations, even if in the likelihood approach (equation (5)) this is not the case. The grid-cell level data have been binned to ten equally sized bins based on the predicted values, and for each bin the mean ±2 standard errors are shown. d, Comparison of prior (grey) and posterior distributions for the raw and derived model parameters with snapshot data of one replicate. Derived parameters consist of the stationary population density q* and growth rate r. The posterior is computed either based on the non-spatial model, i.e., mean-field approximation (green; obtained by setting ε=0 in equations (1)-(3)) or the first-order perturbation approximation using either the likelihood of the multivariate normal distribution (light blue) or the Poisson distribution as in equations (5)-(7) (yellow; obtained by estimating the value of ε in equations (1)-(3)). True parameter values are indicated by red lines.

Pr(𝐘=𝐲)=Pr(Y1=y1)∏j=2nPr(Yj=yj|Yk=yk ∀k<j). (5)

We thus assume some ordering of observations j, and predict the number of agents yj for observation j conditional on the observed data on all the preceding observations. As we assume that the data are Poisson distributed, these terms can be expressed as

Pr(Yj=yj|Yk=yk ∀k<j)∝λjyjexp(−λj),  (6)

where

λj=δE[Zj|Zk=zk ∀k<j]. (7)

Note that the unconditional probability Pr(Y1=y1) is given by equation (6) with λ1=δE[Z1] where E[Z1] can be computed by equation (1). The conditional expectations in equation (7) can be computed by equation (4) by letting 𝐔(j) be the (j−1)×n matrix obtained by including from the n-dimensional identity matrix the first j−1 rows, and 𝐛(j) is the j−1 first elements of 𝐳. Since calculations of the joint probability in equations (5)–(7) can be computationally expensive we introduce in our examples two alternative approaches, a sliding window and a multivariate normal approximation.

Fig 2a shows the emerged point pattern of one simulation of the SSLM where the small blue panel showcases the discretization used in the analysis. Fig 2b illustrates how the two-point spatial cumulant captures the spatial aggregation in the distribution of agents, with the theoretical prediction matching well with the empirically observed pattern. While comparisons between predicted and observed cumulants such as those of Fig 2b have been published earlier [37,39], the new results of this paper are illustrated in panels c and d of Fig 2. Namely, panel c illustrates that the analytical predictions of the conditional density (equation (4)) match well with the empirically observed densities, and panel d illustrates that the likelihood approach (equation (5)) leads to accurate parameter estimates. As shown in Fig 2d, the first-order perturbation approximation leads to more accurate parameter estimates than the non-spatial mean-field approximation, especially for the spatial scale parameter ε about which the mean-field model is completely uninformative. Fig 2d indicates that a single spatial snapshot, summarized through the moments considered here, does not contain sufficient information to estimate some of the raw model parameters. This non-identifiability is structural rather than practical (e.g., to leading order, m and A+ enter the model dynamics mostly through r=A+−m), and is reflected in the relatively small reduction in uncertainty from prior to posterior distributions. Furthermore, strong posterior correlations between several raw model parameters suggest limited parameter identifiability (see S1 File). We note that while equation (5) is exact and thus does not depend on the ordering of the grid cells, equations (1)–(3) are approximations and hence the likelihood function may depend on the ordering. We show in the S1 File that different orderings, however, lead to very similar likelihood profiles, and thus the method is robust with respect to the ordering.

Case study two: Time-series data on a single species

We next expand the first case study to demonstrate how the general framework of equations (1)–(4) can be applied to time-series data. We assume that in addition to collecting the count data yt1,i at time t1, the researcher returned to the same study area at time t2=t1+Δt and collected the count data yt2,i. We consider two scenarios, which we call the marked and the unmarked agents. In the case where the researcher marked all agents during the first survey, the data involves direct information about the transition, i.e., how many agents were born and died between the two surveys. We model the number of new agents by y+,i~ Poisson(δibi), where bi is the predicted per-unit-area birth rate for sample plot i over the time period between the two surveys. We model the number of dead agents by yi,− ~Bin(yt1,di), where di is the predicted probability by which an individual at plot i will die between the two surveys. In case of the unmarked individuals, there remains some uncertainty between the balance of births and deaths. For example, if one agent was seen in the first survey and two in the second survey, it may be that either none died and one was born, or that one died and two were born. Thus, in the case of unmarked individuals, the likelihood includes summation over such sources of uncertainty so that we, in other words, integrate over all possible pathways that could lead to a certain realization.

In some cases, the joint likelihood L of the data collected at times t1 and t2 consists of the product L=L1L1→2, where L1 is the likelihood of the snapshot data at t1, and L1→2 is the likelihood of the observed transition from t1 to t2. In some other cases, the likelihood may consist solely of the transition L1→2, for example if the initial condition before the snapshot t1 is unknown, or if the distribution of agents at t1 is fabricated as will be the case with the empirical data on cancer cells that we consider below. While we considered the likelihood of the snapshot data in the first case study where we assumed a known initial condition, here we focus solely on the transition and thus consider the likelihood L=L1→2.

To predict the birth (bi) and death (di) rates for each grid cell i, we utilize the auxiliary model approach of Ovaskainen et al. [40], which expands each agent type into three auxiliary agent types, denoted by O, + and −. Here O are the original individuals, i.e., those who were present both in the first and the second survey, whereas + and − are respectively those individuals that appeared and disappeared between the two surveys. The time-series data (i.e., the two snapshots at t1 to t2) of the original model can then be reconstructed from a single snapshot of the auxiliary model:yt1,i=yO,i+y−,i, and yt2,i=yO,i+y+,i. The birth rate bi is predicted as the expected density of the + agents, bi=E[Z+,i]. The death rate is predicted by the ratio of the expected densities of the O and − agents, di=E[Z−,i]/(E[ZO,i]+E[Z−,i]), with the calculation of the expectations as explained below.

To calculate for an RCP model the expectations of the multivariate random variables representing the densities 𝐙=(𝐙𝐎, 𝐙+,𝐙−)T needed to compute the birth and death rates, we apply the general framework of equations (1)–(4). The index j now goes through all combinations of agent types s∈{O,+,−} and grid cells i∈I={1,…,N}, and hence n=3N. We order the combinations of agent types and grid cells j so that the indices j=1,…,N correspond to the O agents, the indices j=N+1,…,2N correspond to the + agents, and the indices j=2N+1,…,3N correspond to the − agents, each following the same ordering of the grid cells.

We condition the predictions for the case of the unmarked individuals as

E[ZO,i, Z+,i, Z−,i |ZO,k+Z+,k= zt2,k ∀k<i; ZO,k+Z−,k= zt1,k ∀k]. (8)

In other words, we assume that for predicting the transition rates bi & di through the expectations, the researcher would use full information on the observed agent densities at the first survey 𝐳t1=𝐳O+𝐳−, but information on the agent densities at the second survey 𝐳t2=𝐳O+𝐳+ only for the grid cells preceding the focal cell. The motivation for this is a similar partitioning of the joint likelihood to product of conditionals as presented in equation (5) for the case of the snapshot. In case of the marked individuals, we condition the predictions as

E[ZO,i, Z+,i, Z−,i |ZO,k=zO,k, Z+,k=z+,k, Z−,k=z−,k ∀k<i; ZO,k+Z−,k= zt1,k ∀k≥i]. (9)

Thanks to marking the individuals, the second survey provides full information of the observed densities zO,i, z+,i and z−,i, and hence for the preceding cells it is possible to condition directly on these instead of the unions. As equation (8) and (9) condition partially on unions of agent types and hence sums of two counts on each grid cells, the corresponding rows of the matrices 𝐔 have two entries that are set to ones, the remaining entries being set to zeros.

We continued the simulation from the state shown in Fig 2a for an additional Δt=1 time units, resulting in the transition illustrated in Fig 3a. The match between the theoretically predicted and empirically observed two-point spatial cumulants among the O, + and − agents (Fig 3b) confirms that the extended auxiliary model approach of Ovaskainen et al. [40] is capable of predicting the spatiotemporal cumulants needed to construct the conditional predictions (Fig 3c). The time-series data results in much sharper estimates of the model parameters (Fig 3d), especially in the case of the marked individuals. This is expected, as the data now contains direct information about the birth and mortality rates, as well as their variation with population density. Compared to the first case study on spatial snapshot data, raw parameters are less correlated, suggesting improved parameter identifiability (see S1 File).

Fig 3. Results of the case study on time-series data on a single species.

Fig 3

a, Snapshot of the simulation at time t1=6 and t1+Δt=7, where surviving agents, i.e., of type O, are shown by black dots, new agents, i.e., of type +, by blue dots and dead agents, i.e., of type −, by grey dots. The study area used in the analysis is indicated by the red square and the blue square shows the discretization used for c-d. b, Comparison of the empirical two-point cumulants (dots) with their theoretical expectations (line) calculated from the point pattern in the study area. c, Comparison of predicted densities (horizontal axis) and observed densities (vertical axis) in grid cells of the discretized domain. The grid-cell level data have been binned to ten equally spaced bins based on the predicted values, and for each bin the mean and its standard error is shown. Predictions and observations for the case of unmarked agents are illustrated in black, and for the case of marked agents in green. Densities of surviving agents are indicated by dots and densities of new agents by triangles. d, Comparison of prior (grey) and posterior distributions for the model parameters, the latter computed either based on the non-spatial model, i.e., mean-field approximation (green) or the spatial stochastic model using multivariate normal assumption (blue) or the Binomial and Poisson assumption (yellow). Posterior distributions are shown for unmarked agents (light colors) and marked agents (dark colors). Derived parameters consist of the stationary population density q* and growth rate r. True parameter values are highlighted by the solid red lines.

Case study three: Experimental data on evolution of cancer cell populations

We demonstrate the utility of our framework to analyse empirical data using as example the evolution cancer cells (PC9 non-small lung cancer cells; see Fig 4). Our data consists of time-evolutions of drug-sensitive and drug-resistant cancer cells on experimental plates (1903 μm x 1404 μm windows of 6400 μm diameter wells in a Corning, USA 96-well plate to avoid boundary effects) with RPMI-1640 (10% Fetal Bovine Serum; 1% penicillin and streptomycin supplement) as growth medium. The experiments were conducted for three replicates of each of nine different drug concentrations (0, 0.27, 0.8, 2.5, 7.4, 22.2, 66.7, 200 and 600nM of the EGFR-inhibitor Gefitinib (Cayman, USA) per plate; homogeneously distributed) and three initial conditions (drug-resistant cells only, drug-sensitive cells only, both drug-resistant and drug-sensitive cells) (Fig 4a). The cancer cells were seeded into differential initial configurations, and their time evolution was then followed by imaging the plate every 4 hours for 92 hours and by extracting from each image the coordinates of the two types of cells (Fig 4b). The data do not enable identifying individual cancer cells and hence we will apply the framework for time-series data of unmarked individuals.

Fig 4. Schematic overview of experimental data & model structure of the cancer case study.

Fig 4

a, The dataset comprises data for 9 different drug concentrations. For each drug concentration, experiments were conducted using 3 different initial conditions: only drug-sensitive cells seeded initially, only drug-resistant cells seeded and both together. For each of the 3 initial conditions 3 replicates were produced. Each replicate was imaged every 4 hours for 92 hours in total. For our analysis we randomly assign 2 replicates to training and the remaining replicate to test. b, Images of cells were converted to spatiotemporal point pattern data with coordinates for each individual cell. From the imaging, individuals could not be tagged. c, The model includes two agent types: drug-sensitive & -resistant cells. The dynamics of cells of each type are governed by 4 processes: density-independent mortality, death-inducing intra- & interspecific competition and reproduction & dispersal of offspring. We allow dispersal of the two types to vary in their length scale. For simplicity we assume competition to occur at the same length scale for the two types of agents.

We denote by R drug-resistant and by S drug-sensitive cells (Fig 4c). We assume that the competitive effect of cancer cells for space and resources, e.g., growth factors, is encoded in the interaction matrix 𝐀=[ARRARSASRASS], where AMN denotes the total death-inducing competitive effect of cells of type N on cells of type M. Specifically, an agent of type M∈{R,S} at location x dies at rate ∑y ∈ γM∖xla−daMM(x−yla)+∑y ∈γNla−daMN(x−yla), where γM and γN denote the set of agents of type M and N≠M, aMM and aMN are the spatial kernels of intra- and interspecific competition with overall strength AMM=∫aMM(x)dx, AMN=∫aMN(x)dx, and la−d is the length scale at which any interaction occurs relative to the length scale of reproduction and dispersal of cells of type S. Additionally, we let the dynamics of the two cell types be governed by two processes: (i) reproduction and dispersal, and (ii) density-independent mortality. For a cell of type M∈{R,S} at location x, the per-unit area rate at which it reproduces and disperses offspring to the vicinity of y is given by the spatial kernel lbM−dbM(x−ylbM) with the total rate BM=∫bM(x)dx and length scale lbM relative to the length scale of reproduction and dispersal of cells of type S. Density-independent death occurs at rate mM. Hence, our model in this case study is an extension of the SSLM in the previous case studies but with agents of two types and all pairwise interactions. We fitted the model separately for each of the nine drug concentrations, leaving one replicate of each of the three initial conditions as test data and using the remaining two replicates as training data used to fit the model.

Posterior predictive simulations suggest that, despite its simplicity, the model was satisfactorily capable of capturing the dynamical behaviour of the system, with parameter values estimated from the training data generalizing also to the test data. We illustrate comparison between a single test dataset and posterior predictive simulations by visual comparison between realizations (Fig 5a and 5b), time-evolution of densities (Fig 5c), and spatial covariances in a snapshot (Fig 5d). Comparing predictive posterior data with the actual data showed greatly improved predictive performance in the posterior as compared to the prior parameterization, almost equally for the training and test data (Fig 5e and 5f showing the reduction in root mean squared error). In terms of the model’s assessment of uncertainty, we found the coverage probabilities be relatively close to the nominal values, yet indicating a level of undercoverage (Fig 5g and 5h), suggesting that the model is likely to miss some processes that generate variation in the data. As an additional validation, the S1 File demonstrates the extent by which the framework recovers the parameters from data generated by posterior predictive simulation.

Fig 5. Results of the case study on the evolution of cancer cell populations.

Fig 5

In a-b we compare empirical data with one posterior predictive simulation at 12 hours. c-d, For the example replicate marked in a-h with the blue star, we compare in c-d empirical density and spatial covariance at 12 hours with the 0.9 quantile and median of the posterior predictive simulations. e-h, Validation of the predictive performance for the 9 models (1 model per drug concentration) on training and test data at 4 time points. Each model was fitted using data on 3 initial conditions x 2 replicates. In e-f we calculated for each model and training/test dataset the ratio of mean square error from posterior to prior predictive simulations considering cancer cell density and spatial covariances. We show the median, upper and lower quartile over all 9 models. In g-h we take for each model of empirical data that lies within the 0.9 quantile of the posterior predictive simulations for cancer cell density and spatial covariance. We show the median, upper and lower quartile over all 9 models. i-l, from the posterior distribution we compare raw and derived model parameters of the two cancer cell types with increasing drug concentration. Here, we denote the cancer type by M,N∈{S,R} with N≠M. In i-j, we compare the rate of reproduction and unrestricted growth rate, in k the competitive dominance calculated as the difference of intraspecific competition and interspecific competition, and in l we compare the scaling of the length of dispersal 1/lBM where lBM is the length at which dispersal occurs for cancer cells of type M.

In terms of inference, we found that with increasing drug concentration, the reproduction rate of drug-sensitive cells decreases more than drug-resistant cells (Fig 5i). Whereas the growth rate for drug-resistant cells decreases with increasing drug concentration, for drug-sensitive cells the growth rate follows a more complex pattern (Fig 5j). This pattern is consistent with the pattern of the intra- and interspecific competition for drug-sensitive cells, which are overall less competitively dominant than drug-resistant cells (Fig 5k). We further found the length scale of dispersal decreases for both cell types with increasing drug concentration and overall disperse drug-sensitive cells more locally offspring than drug-resistant cells (Fig 5l).

Discussion

The framework presented in this paper is to our knowledge the first mathematically rigorous likelihood-based framework that applies to a broad class of ABMs. To date, fitting ABMs to data has largely relied on simulation-based approaches [28,29], typically fitted to summary statistics such as spatiotemporal patterns in the data. The method presented here overcomes the need to use extensive simulations and heuristic pattern-oriented criteria by directly tackling the agent-level processes with novel analytical machinery. Compared to recent approaches that use analytical approximations to the intractable likelihood of ABMs [32,33,41–43], our method generalizes not only to a broader class of models, i.e., continuous space, continuous time RCP models, but also to common data types and systems in stationary and transient regimes. Additionally, unlike previous attempts, applying our framework does not require the skills to perform laborious derivations, as our accompanying software automates the derivations. Since we rigorously derive the expressions for the conditional expectation of the density of agents using a perturbation expansion, as shown in the S1 File, our expression for the likelihood is guaranteed to be exact in the limit of long-range interactions.

Our examples provide a proof-of-concept for simulated snapshot and time-series data and showcase the utility of applying our method to empirical data to infer agent-level processes. While applying our method to snapshot data requires knowledge of either an initial state of the system or that the system is in equilibrium, time-series data overcomes this limitation by enabling the calculation of the likelihood of the transition between two observations. We illustrated how to apply our method to the cases of both marked and unmarked agents, the latter is the most common observational data type in many applied fields such as ecology, finance and social sciences. Compared to common spatial applications using pseudo-likelihoods, e.g., via compositional approaches [44], we showed how to construct and efficiently calculate the joint likelihood for both snapshot and time-series data. While our examples encompass only a subset of processes that can be represented as RCP models, a more exhaustive process library is presented by Cornell et al. [37]. With an experimental case study on cancer cells, we exemplified how our framework can be used to infer agent-based biological processes from empirical data. As our framework enabled computing the likelihood of the data, we could apply standard Bayesian inference for both fitting the model to the data as well as for evaluating the model fit. In this specific case study, we found that both reproductive and competitive processes occurred at local scales. This phenomenon could not have been detected by mean-field approaches that have thus far been the most common type of approach in oncological studies [45–48]. We further found that the dynamics of cell-to-cell interactions with increasing drug concentration show non-linear patterns, suggesting that not only growth factor secretion and uptake but also negative competition for space and nutrients drive the co-evolution of the cancer cell populations.

The cornerstone of our methodology is the expression of conditional agent densities, given some observed data (equation (4)). To derive the likelihood of data, this expression can be combined with an appropriate statistical distribution, the choice of which depends on the nature of the data. For the cancer case study, we assumed Poisson likelihood, which accounts for the discrete nature of count data. For the simulated case studies, we compared multivariate normal and Poisson likelihoods. We found these two to yield consistent inference, with similar median, range of values and improvement over the non-spatial model (e.g., for A+, ε, or r in Fig 3d), even if the multivariate normal likelihood does not account for the integer-valued nature of count data. This suggests that it is more important to replicate the correct mean and covariance structure than to implement the exact probability distribution. The multivariate normal likelihood is much more computationally efficient, and simpler to implement, than the Poisson likelihood, and may be more suitable when it is preferable to prioritise simplicity and efficiency over correctness. Furthermore, the multivariate normal likelihood is expected to perform well when the number of individuals per cell is large, due to the Central Limit Theorem.

Even though the cancer case study demonstrates that our framework applies to a broad class of empirical data, three challenges remain: (i) incorporation of agent-level processes that violate RCP model assumptions, (ii) scalability to large number of agent types, and (iii) analysis of data from heterogeneous spatial conditions. Regarding challenge (i), our current framework does not apply to processes that take place in discrete space and/or discrete time, or that involve agents whose behaviour is influenced by their memory. In many practical examples the Markovian assumption might suffice, e.g., if the observational scale is larger than the memory decay scale, or by accounting for the memory effect through agents switching between different types. Addressing challenge (ii), while our framework conceptually applies to an arbitrary number of agent types B, the computational costs are approximately of order O(N3B), where N is the number of grid cells in the domain, hence making it inefficient to analyze large community data. This may be approached by implementing more advanced techniques such as GPU parallelization. Finally, for challenge (iii), the current framework assumes homogeneous spatial conditions such as the homogeneously distributed growth media in our cancer cell case study. However, especially observational non-manipulative data often arises from heterogeneous environments, to which our current framework does not apply, unless the spatial structure, such as habitat patches, are directly included as agents in the current framework. A more direct implementation of environmental heterogeneity could likely be implemented as an extension of the work presented here, as the underlying mathematical tools for spatiotemporal cumulants have been established for both homogeneous and heterogeneous space [37].

In summary, our framework proposes a rigorously derived asymptotically exact tractable likelihood for a broad class of ABMs and for common data types in many applied research fields. We illustrated with both simulated and empirical examples how our method can be used to directly infer agent-level processes from empirical data, and to critically validate the fitted models. Since many systems in life-sciences [1,49,50] and other areas of application [2,3,51,52] consist of agent-level processes, we consider our framework to be a crucial and general advancement. Specifically, as our framework matches models with complex system dynamics, it allows to broaden system understanding and consequently make more reliable predictions.

Methods

Mathematical background for RCP-models

We apply the mathematical framework of Cornell et al. [37], which models discrete agents that interact with each other, e.g., through competition or reproduction and dispersal, in continuous space and continuous time. We denote the agent configuration (including their positions and marks) by γ and consider their evolution in d-dimensional space Rd where for any bounded region Λ the number of agents is assumed to remain finite. The agent configuration γ can be expressed as the disjoint union of the configurations γs where the index s denotes the marks s∈S of the agents. Thus,

γ=⨆s∈Sγs . (10)

We define the space of locally finite configurations Γ

Γ:= {γ⊂X||γ∩Λ|<∞,  for all Λ bounded},  (11)

where |·|  denotes the cardinality of a set, X is the space of real-valued positions and their marks [53]. Note that for the agent configuration of a given mark s it holds that γs⊂Rd.

We introduce the probability measure μt on Γ to describe the state of the system. The measure μ describes the probability of the system to be in a certain state at time t, given the initial state defined at some earlier time. The system can be probed by observables F, which operate on Γ and return real-numbered values. As one example of an observable, we may let F be a function which counts the number of agents of certain type within a certain domain. The state of the system can be described by the pairing of observable F and probability measure μt

⟨F,μt⟩:=∫ΓF(γ)dμt(γ). (12)

The evolution of the system through time t is defined through the change in observables as

ddt⟨F, μt⟩=⟨LF, μt⟩, (13)

where the model is specified through the Markov operator L. This Markov operator is defined by the system processes P as

L=∑p=1PLp,  (14)

where each process p describes a specific type of interaction among the agents, such as competition or reproduction.

The mathematical framework of Cornell et al. [37] allows to derive exact equations for the evolution of spatial correlation functions of RCP models. The first-order spatial correlation function ks,t(1)(x) measures the expected density of agents with mark s at location x and time t. The expected number of agents with mark s in an area Λ at time t can be computed as

E[|γs,t∩Λ|] =∫Λks,t(1)(x)dx. (15)

The second-order correlation function ks1,s2,t(2)(x1,x2) can be used to compute the product of the number of agents with mark s1 in an area Λ1 and the number of agents with mark s2 in an area Λ2 at time t as

E[|γs1,t∩Λ1||γs2,t∩Λ2|] =∫Λ1∫Λ2ks1,s2,t(2)(x1,x2)dx1dx2+δs1,s2∫Λ1∩Λ2ks1,t(1)(x)dx, (16)

where Kronecker’s delta δs1,s2equals one if s1=s2 and otherwise zero, and hence the last summand counts the self-pairs of agents for the case where the two areas Λ1 and Λ2 are not disjoint [40].

For each Markov operator L it is possible to derive a corresponding operator LΔ which describes the evolution of the spatial correlation functions k={k(l)}l=1∞ of all orders and of all mark combinations as [37]

ddtkt(η)=(LΔkt)(η),  (17)

where η denotes a finite configuration. Spatial cumulants are obtained by subtracting from the spatial correlations the products of the lower order terms. For example, the second-order cumulant is related to the moments as us1,s2,t(2)(x,y)=ks1,s2,t(2)(x,y)−ks1,t(1)(x)ks2,t(1)(y). For each Markov operator L it is possible to derive a corresponding operator QΔ which describes the evolution of the spatial cumulants u of all order and of all mark combinations as

ddtut(η)=(QΔut)(η),  (18)

where LΔ=QΔ+MΔ, and MΔ  is a non-linear operator.

We note that typically the spatial moments and cumulants form an unclosed hierarchy and thus the systems of differential equations above cannot be exactly solved. We follow the systematic perturbation expansion proposed by Cornell et al. [37] to approximate the spatial moments and cumulants. Cornell et al. [37] rescaled all spatial kernel functions as

aε(x):=εda(εx),  (19)

which makes interactions increasingly long-ranged with ε→0 but keeps their intensity (the integrals of the kernels) constant. Following this rescaling, Cornell et al. [37] showed that the fist-order spatial correlation function can be computed as

kε,s,t(1)(x)=qs,t(εx)+εdps,t(εx)+ o(εd),  (20)

where qs,t(x) is the mean-field density, ps,t(x) is its first-order correction term and the approximation error behaves as o(εd). Cornell et al. [37] further showed that the second-order cumulant follows the expansion

uε,s1s2,t(2)(x,y)=εdgs1,s2,t(εx,εy)+o(εd),  (21)

where the zeroth-order term is zero (in mean-field, there are no spatial correlations) and hence missing, and thus the leading term of the expansion gs1,s2,t(x,y) is of order εd. The perturbation expansion produces a closed system of differential equations that can be described as

ddtqt=Hq(qt),  ddtpt=Hp(qt,gt),  ddtgt=Hg(qt,pt,gt),  (22)

where the functions Hq, Hp and Hg can be derived for any RCP model using automated tools [37] and act on the S×x vectors qt,pt with entries for all marks S, and if the system is heterogeneous all locations x∈Rd, and the S×S×z matrix gt with entries of all pairs of marks S and all distances z=f(x,y) where x,y∈Rd and f is the Euclidean distance.

Derivation of the conditional expectation (equation (4))

Equation (4) is a general expression for the conditional expectation of a multivariate random variable 𝐙=(Z1,Z2, …, Zn)T, whose expectation is E[𝐙]=μ and variance-covariance matrix Σ. For any k×n matrix 𝐔 of rank k and vector 𝐛 of length k, equation (4) states that the expectation of 𝐙 conditional on 𝐔𝐙=𝐛 can be expressed as E[𝐙|𝐔𝐙=𝐛]=𝐀μ+𝐂𝐛, where 𝐂=Σ𝐔T(𝐔Σ𝐔T)−1 and 𝐀=𝐈n−𝐂𝐔 where 𝐈n denotes the n×n identity matrix. As 𝐀+𝐂𝐔=𝐈n and hence 𝐙=𝐀𝐙+𝐂𝐔𝐙,   it follows that

E[𝐙|𝐔𝐙=𝐛]=E[𝐀𝐙+𝐂𝐔𝐙|𝐔𝐙=𝐛]
=E[𝐀𝐙|𝐔𝐙=𝐛]+E[𝐂𝐔𝐙|𝐔𝐙=𝐛] (23)

The matrix 𝐀 has been constructed so that 𝐀𝐙 and 𝐔𝐙 have zero covariance: Cov(𝐀𝐙, 𝐔𝐙)=𝐀Σ𝐔T=Σ𝐔T−𝐂𝐔Σ𝐔T=Σ𝐔T−Σ𝐔T(𝐔Σ𝐔T)−1𝐔Σ𝐔T=0. If 𝐀𝐙 and 𝐔𝐙 would be independent, Eq. 4 would follow, as in that case

E[𝐀𝐙|𝐔𝐙=𝐛]+E[𝐂𝐔𝐙|𝐔𝐙=𝐛]=𝐀E[𝐙]+𝐂E[𝐔𝐙|𝐔𝐙=𝐛]=𝐀μ+𝐂𝐛=μ+𝐂(𝐛−𝐔μ). (24)

While we cannot in the general case show their independence, we still consider equation (4) to hold approximately for the following two reasons. First, zero covariance is a necessary (yet not sufficient) condition for independence. If 𝐙 would be, e.g., multivariate normally distributed, independence would follow from zero covariance. Second, as we show in the S1 File, equation (4) holds at the level of the first-order perturbation, which is the level of approximation at which we have developed the likelihood approach here. We note that while we use in our framework only the conditional expectation, it would be possible to compute also uncertainties of such predictions through Var(𝐙|𝐔𝐙=𝐛).

Efficient computation

Full conditioning of equation (4).

For large matrices 𝐔,Σ, calculating (𝐔Σ𝐔T)−1 to find 𝐂 is the most expensive computation in equation (4). Especially, in the case where we want to condition our prediction on observations of all other locations than the focal location or when computing the likelihood where we condition on iteratively less or more data points, and thus need to predict each data point separately. For example, if we wish to predict j data points we would need to compute the inverse j times. Instead, we propose two recursive strategies: (i) for computing the inverse when conditioning on one data point less via simple rank-one updates directly to (𝐔Σ𝐔T)−1 (ii) for computing the inverse when conditioning on one data point more. While (i) is needed in all our case studies (ii) is needed in the time-series case of marked individuals, as shown below. Assume we have computed the inverse of 𝐔Σ𝐔T:=𝐅 for some k×n matrix 𝐔 and want to find the inverse of 𝐔(j)Σ𝐔(j) T:=𝐒 where 𝐔(k) is the (k−j)×n matrix obtained by dropping the first j rows of 𝐔. We can partition 𝐅 and 𝐕 so that 𝐅11,𝐕11,𝐅22 and 𝐕22 are square matrices as

𝐅=[𝐅11𝐅12𝐅21𝐒=𝐅22], (25)

and

𝐅−1:=𝐕=[𝐕11𝐕12𝐕21𝐕22].  (26)

We compute 𝐅22−1 from 𝐅𝐕=𝐈, where 𝐈 denotes the identity matrix. Since

𝐅21𝐕12+𝐅22𝐕22=𝐈,  (27)
𝐅21𝐕11+𝐅22𝐕21=0,  (28)

and thus

𝐒−1=𝐅22−1=𝐕22−𝐕21𝐕11−1𝐕12. (29)

Note that we can compute 𝐂=𝐁𝐒−1, where 𝐁=Σ𝐔(j)T=(Σ𝐔T)(j) is computed by dropping the first j rows of Σ𝐔T. Next, we want to compute 𝐅−1=𝐕 in the case where we have first explicitly computed 𝐒−1=(𝐔(j)Σ𝐔(j)T)−1. We compute 𝐕 block-wise as

𝐕11=(𝐅11−𝐅12𝐒−1𝐅21)−1,  (30)
𝐕21=−𝐒−1𝐅21𝐕11,  (31)
𝐕12=−(𝐅11+𝐅12𝐕21𝐕11−1)−1𝐅12𝐒−1, (32)
𝐕22=𝐒−1+𝐕21𝐕11−1𝐕12. (33)

From 𝐅−1 we calculate 𝐂=𝐃𝐅−1 where 𝐃=Σ𝐔T=[Σ𝐔jTΣ𝐔(j)T] and 𝐔j denotes the first j rows added as first rows to 𝐔(j) to obtain 𝐔.

Sliding window approach.

When computing the joint probability using, e.g., the partitioning in equations (5)–(7) it is required to evaluate the inverse 𝐒−1:=(𝐔Σ𝐔T)−1 for every grid cell in the domain. However, if the domain is large compared to the distance at which the spatial covariance decays, then 𝐒−1 is effectively the same for a large fraction of grid cells. We can hence truncate 𝐔 and Σ to a smaller window size W and numerically calculate the inverse 𝐒W−1:=(𝐔WΣW𝐔WT)−1 once for all grid cells with the same window. Clearly, this approach is computationally advantageous in the cases where W≪N where N is the number of grid cells in the domain.

Multivariate normal approximation.

Considering the limit where the number of agents in a grid cell is large the likelihood becomes that of the multivariate normal distribution. Here the likelihood can be directly computed once from the covariance matrix without iteration through all grid cells. This is advantageous to the approach of equations (1)–(4), since there one needs to recalculate equation (4) N times and hence its calculation time scales with the discretization of the domain and the number of agent types. Specifically, in the limit of large number of agents per grid cell the multivariate random variable 𝐙=(Z1,Z2,…,Zn)T follows a multivariate normal distribution with mean E[𝐙]=μ and variance-covariance matrix Σ. The log-likelihood of observing densities 𝐳 has the closed form

logL(𝐳)∝−12[log(|Σ|)+(𝐳−μ)TΣ−1(𝐳−μ)], (34)

where |Σ| denotes the determinant of Σ. In the case of snapshot data, we can straightforwardly calculate μ and Σ as described in equation (1)–(3). In the case of time-series data, we compute the likelihood of the transition between t1 and t1+Δt. Hence, we condition our predictions on the observed densities of agents in t1. Recall that in the time-series case we let 𝐙=(𝐙O, 𝐙+,𝐙−)T where 𝐙O is the random variable representing densities of surviving agents, 𝐙+ new agents and 𝐙− dead agents, each of length N. We condition our predictions on observed densities of agents at time t1, hence on 𝐛=𝐔𝐳 with 𝐔=[𝐈N𝐎N𝐈N] consisting of N×N dimensional identity and null matrices, and the vector of observed densities 𝐳=(𝐳O,𝐳+,𝐳−)T. We construct

μ=[μOμ+μ−],  Σ=[ΣO,OΣO,+ΣO,−Σ+,OΣ+,+Σ+,−Σ−,OΣ−,+Σ−,−], (35)

which we use to compute conditional expectation and variance of 𝐙 using equation (4). In the case of unmarked agents we assume that the density of agents in t1+Δt conditional on t1 follows a multivariate normal distribution with mean 𝐒E[𝐙|𝐔𝐙=𝐛]=E[𝐙O|𝐔𝐙=𝐛]+E[𝐙+|𝐔𝐙=𝐛] and variance-covariance matrix constructed by 𝐒Var(𝐙|𝐔𝐙=𝐛)𝐒T=Var(𝐙O|𝐔𝐙=𝐛)+Var(𝐙+|𝐔𝐙=𝐛) where 𝐒=[𝐈N𝐈N𝐎N]. We note that we compute the conditional variances as var(𝐙|𝐔𝐙=𝐛)=𝐀var(𝐙)𝐀T with 𝐀=𝐈N−𝐂𝐔 and 𝐂=Σ𝐔T(𝐔Σ𝐔T)−1 (see S1 File). The conditional mean and variance-covariance matrix are then used to compute the likelihood. In the case of marked agents, we use the same approach for the conditional expectation and variance. Here, we assume that (𝐙O,𝐙+) follows a multivariate normal distribution (and not 𝐙O+𝐙+) with mean E[𝐙O,𝐙+|𝐔𝐙=𝐛] and variance Var(𝐙O,𝐙+|𝐔𝐙=𝐛).

Parameter estimation

For each model in case study one and two, we used a Bayesian approach to estimate the model parameters, where we assumed for each model parameter θ the log-normal prior distribution logθ~N(0,e2) with e=2. In case study three, we assumed for all parameters, except the scaling of the spatial kernels, log-normal prior distributions logθ~N(−1.5,e2) with e=4. For the scaling parameters of the spatial kernels, we assumed log-uniformly distributed priors on the interval [a,b] with a=log(0.1) and b=log(4) according to the dimensions of the sliding window. We used an adaptive Metropolis-Hastings algorithm to sample from the posterior distributions. We ran each of 4 chains from different random initializations for 1000 adaptive iterations and 10000 sampling iterations where we thinned the sampled parameters to every 10-th parameter combination, resulting in 1000 samples per chain. If visual inspection of the trace plots of the chains suggested that the MCMC algorithm was still in a transient phase after 1000 adaptive iterations, we continued the MCMC algorithm for 1000 additional adaptive iterations before conducting the sampling iterations. We evaluated MCMC convergence by calculating the Gelman diagnostic (for results on MCMC convergence, see S1 File).

Details of case study one

Mathematical description of the SSLM.

The model dynamics of the SSLM are defined by the linear Markov operator L as [39]

LF(γ)=∑x∈γ(m+∑y∈γ∖xa−(x−y))[F(γ∖x)−F(γ)]+∑y∈γ∫Rda+(x−y)[F(γ∪x)−F(γ)]dx, (36)

where the first part of the equation models the death events and the second part the birth events. Considering the dynamics of the SSLM in two-dimensional space, the system of differential equations that describes (at the level of first-order perturbation) the time-evolution of population density and two-point cumulant becomes [39]

ddtqt= (A+−m)qt−A−qt2,
ddtpt= −2π∫0∞kg~t(k)a~−(k)dk+(A+−m)pt−2A−qtpt, (37)
ddtg~t(k)= 2(g~t(k)[a~+(k)−m−(A−+a~−(k))qt]+qt[a~+(k)−a~−(k)qt]),

where a~ denotes the Fourier-transform of the function a. In the S1 File we show the differential equations of the auxiliary model of the SSLM, used to calculate the leading terms of the spatiotemporal cumulants.

Model simulations.

We assumed the parameter values m=1,a+(x)=2b(x) and a−(x)=b(x), where b(x) is the truncated Gaussian kernel

b(x)={C, if |x|≤3,0, if |x|>3,  (38)

with C=12π∫|x|≤3exp(−|x|2/2)dx  so that b(x) integrates to one over all space. We furthermore set the spatial scaling parameter to ε=1, and considered the dynamics of the SSLM in the domain Ω=[0,80]2, where we assumed periodic boundary conditions. We simulated the dynamics for t=6 time units, initializing the simulation with a homogeneous Poisson distribution (also called complete spatial randomness) with intensity 1. We discretized the domain into a grid with cell size 1 x 1 and collected from each grid cell data on the number of agents at the end of the simulation.

Details of case study two

For a mathematical description of the SSLM see Details of case study one and the S1 File.

Implementation of the conditional expectations.

In case study two we present how we make conditional predictions, i.e., equations (8)–(9), for marked and unmarked individuals in notations that explicitly show the conditioning in terms of the marks of agents. Here we present these conditional predictions in the notation of our framework equation (4) by explicitly defining 𝐔. In the case of unmarked individuals, we do not have data on O,+,− agents separately but rather on counts during the first and second surveys, i.e., on the sums yt1,i=yO,i+y−,i, and yt2,i=yO,i+y+,i. We compute conditional predictions for all grid cells i as

E[𝐙|𝐔(i)𝐙=𝐛(i)   ∀i∈I], (39)

where

𝐔(i)=[𝐈N𝐎N𝐈N𝐈F(i−1)𝐈F(i−1)𝐎F(i−1)].

Here 𝐈N and 𝐎N respectively denote the N-dimensional identity and zero matrix and superscript F(m) means only the first m rows of these matrices are included. Here 𝐛(i) is a vector of length N+i−1 where the first N elements are the sums of O and − agents and the last i−1 elements are the sums of O and + agents.

In other words, we assumed that for predicting the transition rates, the researcher would use full information on the agent densities at the first survey, but information on the agent densities at the second survey only for the grid cells preceding the focal cell. The motivation for this is a similar partitioning of the joint likelihood to product of conditionals as presented in equation (5) for the case of the snapshot.

In the case of marked individuals, the first survey yields data on the sum of the O and − agents, but after the second survey it is possible to count the O,+,− agents separately. When making the predictions for the expectations of the densities ZO,i, Z+,i and Z−,i for grid cell i, we assume that the cells of index smaller i have already been surveyed twice and hence we condition on their counts of O,+ and − agents. The cells with index larger i have not been surveyed twice and we condition thus on their sum of counts of O and − agents. This yields the conditioning

E[𝐙|𝐔(i)𝐙=𝐛(i)   ∀i∈I], (40)

where

𝐔(i)=[𝐈L(N−i+1)𝐎L(N−i+1)𝐈L(N−i+1)𝐈F(i−1)𝐎F(i−1)𝐎F(i−1)𝐎F(i−1)𝐈F(i−1)𝐎F(i−1)𝐎F(i−1)𝐎F(i−1)𝐈F(i−1)],

and 𝐛(i) is a vector of length N−i+1+3(i−1)=N+2i−2. Note that here the 1,…,N−i+1th element of 𝐛(i) refers to the sum of O and − agents of the first snapshot of grid cells following grid cell i−1 and the N−i+1, …,N+2i−2 th elements to observations of O,+,− agents in grid cells preceding grid cell i. Here 𝐈 and 𝐎 respectively denote the N-dimensional identity and zero matrices, and the superscripts F(m) and L(m) respectively mean that only the first or last m rows of the matrix are included.

Likelihood of transition with unknown initial condition.

Our framework is based on the leading terms of spatial and spatiotemporal cumulants of RCP models. To compute the leading terms, we either need to know the initial distribution of agents at time t0, e.g., complete spatial randomness, or that the dynamics of the system are in stationary state. If neither of these is possible, we cannot predict the conditional densities in the case of only having a single snapshot observation. However, if we have time-series data we can still model the transition between the two observation and use that information to compute the likelihood. In this case we empirically extract k(1) the one- and k(2) two-point cumulant from the data. Note that from k(1) we cannot easily separate the leading terms q and p, and thus for simplicity we set p :=0. From the empirical two-point cumulant we calculate the leading term g as g(x,y)=ε−dk(2)(ε−1x, ε−1y).

Details of case study three

Setup of cancer cell experiments.

Our experimental model comprised time-lapsed observations of drug-sensitive parental non-small lung cancer (NSCLC) PC9 (Sigma-Aldrich, USA) cells stably engineered to express fluorescent label EGFP (VectorBuilder, USA) and drug-resistant cancer cells engineered to express clinically relevant drug-resistant mutation B-RAF-V600E (Addgene, USA) stably expressing fluorescent label mCherry (VectorBuilder, USA). Engineering mutant cells were maintained in RPMI-1640 medium supplemented with 10% heat-inactivated fetal bovine serum and 1% penicillin/streptomycin containing the appropriate concentration of antibiotic selection. Experimentally, 1500 fluorescently labelled cells containing homogenously mixed three initial conditions (drug-resistant cells only, drug-sensitive cells only, co-culture containing different initial ratios of both drug-resistant and drug-sensitive cells) were plated in 96-well microplates (Corning, USA) in 100 µL of culture medium. The experiments were conducted for three technical replicates of each of nine different drug concentrations (0, 0.27, 0.8, 2.5, 7.4, 22.2, 66.7, 200 and 600nM of EGFR-inhibitor Gefitinib (Cayman, USA)). Plating of cells and drug treatment was performed using Microlab liquid handler robot (Hamilton, USA) to ensure consistency across replicates. The cancer cells were seeded into differential initial proportions and time-lapse imaging was acquired using the BioSpa live-cell analysis system (Agilent, USA) every 4 hours for 96 hours to assess cellular dynmacis and evolution under treatment. The resulting images were processed using the open-source software CellProfiler. Briefly, image processing included background subtraction, conversion to 8-bit format, contrast enhancement, and thresholding to isolate individual cells. Then, raw cell counts and coordinates of the two types of cells were extracted for each time point.

Mathematical description of the cancer cell model.

Note that the cancer cell model comprises agents of types {S,R}. The dynamics of the cancer cell model are defined by the microscopic equation

LF(γ)= ∑M,N∈{S,R}M≠N∑x∈γM(mM+∑y∈γM∖xaMM(x−y)+∑z∈γNaMN(x−z))[F(γM∖x,γN)−F(γM, γN)]+∑y∈γM∫RdbM(x−y)[F(γM∪x,γN)−F(γM,γN)]dx, (41)

where γ=(γM,γN). We apply the mathematical framework of Cornell et al. [37] to derive the system of differential equations for the leading terms of the spatial and spatiotemporal cumulants. The time-evolution of density and two-point cumulant in two-dimensional space are given by

ddtqt,S=−qt,S(mS−BS+ASSqt,S+ASRqt,R),
ddtqt,R=−qt,R(mR−BR+ARRqt,R+ARSqt,S), (42)
ddtpt,S=−2π∫0∞ka~SS(k)g~t,S,S(k)dk+2π∫0∞ka~SR(k)g~t,S,R(k)dk+(BS−mS)pt,S−2ASSpt,Sqt,S−ASR(pt,Rqt,S+pt,Sqt,R), (43)
ddtpt,R=−2π∫0∞ka~RR(k)g~t,R,R(k)dk+2π∫0∞ka~RS(k)g~t,R,S(k)dk+(BR−mR)pt,R−2ARRpt,Rqt,R−ARS(pt,Sqt,R+pt,Rqt,S),
ddtg~t,S,S(k)=−2qt,S(−b~S(k)+a~SR(k)g~t,S,R(k)+a~SS(k)qt,S)−2g~t,S,S(k)[mS−b~S(k)+(a~SS(k)+ASS)qt,S+a~SR(k)qt,R],
ddtg~t,R,R(k)=−2qt,R(−b~R(k)+a~RS(k)g~t,S,R(k)+a~RR(k)qt,R)−2g~t,R,R(k)[mR−b~R(k)+(a~RR(k)+ARR)qt,R+a~RS(k)qt,S], (44)
ddtg~t,S,R(k)=−a~RS(k)qt,R(g~t,S,S(k)+qt,S)−a~SR(k)qt,S(g~t,R,R(k)+qt,R)−g~t,S,R(k)[mS+mR−b~S(k)−b~S(k)+(a~SS(k)+ASS+ARS)qt,S+(a~RR(k)+ARR+ASR)qt,R],

The differential equations for the auxiliary model is shown in the S1 File.

Model fitting.

We fitted one model per drug concentration. Each of the nine drug concentration experiments consists of three initial conditions with three replicates each, i.e., nine datasets (Fig 4a). From those nine datasets, we randomly selected one replicate per initial condition for the test data, and the remaining six datasets were used as training data to fit the model in a Bayesian parameter estimation framework. We denote by D the dataset used in the training, consisting of Td time steps. We calculate the log-likelihood of the data as

logL=∑d=1D∑t=1Td−1∑M∈{R,S}logLt→t+1M,  (45)

where logLt→t+1M denotes the log-likelihood of the transition from t to t+1 for agents of type M. To calculate this log-likelihood, we assumed a Poisson distribution for number of new agents appearing, and the Binomial distribution for the number of existing agents surviving from t to t+1. For computational reasons we applied a sliding window approach to compute the conditional expectations in equation (8).

Prior & posterior predictive simulations.

For each of the 9 models, we sample 100 parameter vectors from the prior and posterior distributions. For all 9 replicates (6 training & 3 test data) we extract the configurations at the initial time to initialize the posterior predictive simulations from. We use the RCP-simulator of Cornell et al. [37], simulate with each 100 sampled parameter vectors from the true initial conditions of all 9 replicates for 92 hours (92 time steps saved every 4 time step) with different random seed.

Supporting information

S1 File. Section 1–2 include mathematical descriptions of the models used in the case studies.

Section 3 provides results on the effect of the ordering of grid cells on the likelihood calculation. Section 4 includes a justification for the conditional variance of agent densities. Section 5 includes results on MCMC convergence, posterior correlations and further validation tests. Section 6 presents a proof of the conditional expectation of agent density.

(PDF)

pcbi.1014786.s001.pdf (2.6MB, pdf)

Data Availability

The minimal data set and accompanying code are available at Figshare via https://figshare.com/s/899f73102e37b1a0c5d5.

Funding Statement

OO was funded by the Research Council of Finland (grant no. 336212 and 345110), and the European Research Council (ERC) under the European Union’s Horizon 2020 research and innovation programme (grant agreement No 856506: ERC-synergy project LIFEPLAN). NM was funded by the Research Council of Finland (grant no. 345110 to OO). SH was funded by the Swedish Research Council (project 2024-05621), Wenner-Gren Stiftelserna/the Wenner-Gren Foundations (WGF2022-0044), and the Kjell och Märta Beijer Foundation. DST was supported by the Research Council of Norway (grant 325628/IAR). The funders had no role in study design, data collection and analysis, decision to publish, or preparation of the manuscript.

References

  • 1.Grimm V, Railsback SF. Individual-based modeling and ecology. Princeton: Princeton University Press; 2005. doi: 10.1515/9781400850624 [DOI] [Google Scholar]
  • 2.Macy MW, Willer R. From factors to actors: computational sociology and agent-based modeling. Annu Rev Sociol. 2002;28(1):143–66. doi: 10.1146/annurev.soc.28.110601.141117 [DOI] [Google Scholar]
  • 3.LeBaron B. Agent-based computational finance. In: Tesfatsion L, Judd KL, editors. Handbook of computational economics. Elsevier; 2006. p. 1187–233. [Google Scholar]
  • 4.van Kampen NG. Stochastic processes in physics and chemistry. Amsterdam: Elsevier Science Publishers; 1992. [Google Scholar]
  • 5.McQuarrie DA. Stochastic approach to chemical kinetics. J Appl Probab. 1967;4:413–78. [Google Scholar]
  • 6.Levin SA. The problem of pattern and scale in ecology: the Robert H. MacArthur award lecture. Ecology. 1992;73:1943–67. [Google Scholar]
  • 7.Gillespie DT. A rigorous derivation of the chemical master equation. Phys A: Stat Mech Appl. 1992;188(1–3):404–25. doi: 10.1016/0378-4371(92)90283-v [DOI] [Google Scholar]
  • 8.Dieckmann U, Law R. The dynamical theory of coevolution: a derivation from stochastic ecological processes. J Math Biol. 1996;34(5–6):579–612. doi: 10.1007/BF02409751 [DOI] [PubMed] [Google Scholar]
  • 9.Bolker B, Pacala S. Using moment equations to understand stochastically driven spatial pattern formation in ecological systems. Theor Popul Biol. 1997;52(3):179–97. doi: 10.1006/tpbi.1997.1331 [DOI] [PubMed] [Google Scholar]
  • 10.Ovaskainen O, Cornell SJ. Space and stochasticity in population dynamics. Proc Natl Acad Sci U S A. 2006;103(34):12781–6. doi: 10.1073/pnas.0603994103 [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 11.Schnakenberg J. Network theory of microscopic and macroscopic behavior of master equation systems. Rev Mod Phys. 1976;48:571–85. [Google Scholar]
  • 12.Austin MP. Spatial prediction of species distribution: an interface between ecological theory and statistical modelling. Ecol Model. 2002;157:101–18. [Google Scholar]
  • 13.Ovaskainen O, Tikhonov G, Norberg A, Guillaume Blanchet F, Duan L, Dunson D, et al. How to make more out of community data? A conceptual framework and its implementation as models and software. Ecol Lett. 2017;20(5):561–76. doi: 10.1111/ele.12757 [DOI] [PubMed] [Google Scholar]
  • 14.Guisan A, Thuiller W. Predicting species distribution: offering more than simple habitat models. Ecol Lett. 2005;8(9):993–1009. doi: 10.1111/j.1461-0248.2005.00792.x [DOI] [PubMed] [Google Scholar]
  • 15.Anderson MJ, Willis TJ. Canonical analysis of principal coordinates: a useful method of constrained ordination for ecology. Ecology. 2003;84(2):511–25. doi: 10.1890/0012-9658(2003)084[0511:caopca]2.0.co;2 [DOI] [Google Scholar]
  • 16.Dolédec S, Chessel D, ter Braak CJF, Champely S. Matching species traits to environmental variables: a new three-table ordination method. Environ Ecol Stat. 1996;3:143–66. [Google Scholar]
  • 17.Niku J, Warton DI, Hui FKC, Taskinen S. Generalized linear latent variable models for multivariate count and biomass data in ecology. J Agric Biol Environ Stat. 2017;22:498–522. [Google Scholar]
  • 18.Dormann CF, et al. Biotic interactions in species distribution modelling: 10 questions to guide interpretation and avoid false conclusions. Glob Ecol Biogeogr. 2018;27:1004–16. [Google Scholar]
  • 19.Zurell D, Pollock LJ, Thuiller W. Do joint species distribution models reliably detect interspecific interactions from co‐occurrence data in homogenous environments? Ecography. 2018;41(11):1812–9. doi: 10.1111/ecog.03315 [DOI] [Google Scholar]
  • 20.Blanchet FG, Cazelles K, Gravel D. Co-occurrence is not evidence of ecological interactions. Ecol Lett. 2020;23(7):1050–63. doi: 10.1111/ele.13525 [DOI] [PubMed] [Google Scholar]
  • 21.Phillips SJ, Anderson RP, Schapire RE. Maximum entropy modeling of species geographic distributions. Ecol Model. 2006;190:231–59. [Google Scholar]
  • 22.Gatrell AC, Bailey TC, Diggle PJ, Rowlingson BS. Spatial point pattern analysis and its application in geographical epidemiology. Trans Inst Br Geogr. 1996;21:256–74. [Google Scholar]
  • 23.Kearney M, Porter W. Mechanistic niche modelling: combining physiological and spatial data to predict species’ ranges. Ecol Lett. 2009;12(4):334–50. doi: 10.1111/j.1461-0248.2008.01277.x [DOI] [PubMed] [Google Scholar]
  • 24.Kleidon A, Mooney HA. A global distribution of biodiversity inferred from climatic constraints: results from a process‐based modelling study. Glob Change Biol. 2000;6(5):507–23. doi: 10.1046/j.1365-2486.2000.00332.x [DOI] [Google Scholar]
  • 25.Sykes MT, Prentice IC, Cramer W. A bioclimatic model for the potential distributions of North European tree species under present and future climates. J Biogeogr. 1996;23:203–33. [Google Scholar]
  • 26.Reiker T, Golumbeanu M, Shattock A, Burgert L, Smith TA, Filippi S, et al. Emulator-based Bayesian optimization for efficient multi-objective calibration of an individual-based model of malaria. Nat Commun. 2021;12(1):7212. doi: 10.1038/s41467-021-27486-z [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 27.Jørgensen ACS, Ghosh A, Sturrock M, Shahrezaei V. Efficient Bayesian inference for stochastic agent-based models. PLoS Comput Biol. 2022;18(10):e1009508. doi: 10.1371/journal.pcbi.1009508 [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 28.Cranmer K, Brehmer J, Louppe G. The frontier of simulation-based inference. Proc Natl Acad Sci U S A. 2020;117(48):30055–62. doi: 10.1073/pnas.1912789117 [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 29.Grimm V, et al. Pattern-oriented modeling of agent-based complex systems: lessons from ecology. Science. 2005;310:987–91. [DOI] [PubMed] [Google Scholar]
  • 30.Grimm V, et al. A standard protocol for describing individual-based and agent-based models. Ecol Model. 2006;198:115–26. [Google Scholar]
  • 31.Vrettas MD, Opper M, Cornford D. Variational mean-field algorithm for efficient inference in large systems of stochastic differential equations. Phys Rev E Stat Nonlin Soft Matter Phys. 2015;91(1):012148. doi: 10.1103/PhysRevE.91.012148 [DOI] [PubMed] [Google Scholar]
  • 32.Fearnhead P, Giagos V, Sherlock C. Inference for reaction networks using the linear noise approximation. Biometrics. 2014;70(2):457–66. doi: 10.1111/biom.12152 [DOI] [PubMed] [Google Scholar]
  • 33.Ruttor A, Opper M. Efficient statistical inference for stochastic reaction processes. Phys Rev Lett. 2009;103(23):230601. doi: 10.1103/PhysRevLett.103.230601 [DOI] [PubMed] [Google Scholar]
  • 34.Gorin G, Vastola JJ, Fang M, Pachter L. Interpretable and tractable models of transcriptional noise for the rational design of single-molecule quantification experiments. Nat Commun. 2022;13(1):7620. doi: 10.1038/s41467-022-34857-7 [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 35.Zechner C, Ruess J, Krenn P, Pelet S, Peter M, Lygeros J, et al. Moment-based inference predicts bimodality in transient gene expression. Proc Natl Acad Sci U S A. 2012;109(21):8340–5. doi: 10.1073/pnas.1200161109 [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 36.Cseke B, Schnoerr D, Opper M, Sanguinetti G. Expectation propagation for continuous time stochastic processes. J Phys Math Theor. 2016;49:494002. [Google Scholar]
  • 37.Cornell SJ, Suprunenko YF, Finkelshtein D, Somervuo P, Ovaskainen O. A unified framework for analysis of individual-based models in ecology and beyond. Nat Commun. 2019;10(1):4716. doi: 10.1038/s41467-019-12172-y [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 38.Law R, Murrell DJ, Dieckmann U. Population growth in space and time: spatial logistic equations. Ecology. 2003;84(1):252–62. doi: 10.1890/0012-9658(2003)084[0252:pgisat]2.0.co;2 [DOI] [Google Scholar]
  • 39.Ovaskainen O, et al. A general mathematical framework for the analysis of spatiotemporal point processes. Theor Ecol. 2014;7:101–13. [Google Scholar]
  • 40.Ovaskainen O, Somervuo P, Finkelshtein D. A general mathematical method for predicting spatio-temporal correlations emerging from agent-based models. J R Soc Interface. 2020;17(171):20200655. doi: 10.1098/rsif.2020.0655 [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 41.Schnoerr D, Grima R, Sanguinetti G. Cox process representation and inference for stochastic reaction-diffusion processes. Nat Commun. 2016;7:11729. doi: 10.1038/ncomms11729 [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 42.Whitehouse M, Whiteley N, Rimella L. Consistent and fast inference in compartmental models of epidemics using Poisson Approximate Likelihoods. J R Stat Soc Ser B Stat Methodol. 2023;85:1173–203. [Google Scholar]
  • 43.Miles CE, McKinley SA, Ding F, Lehoucq RB. Inferring stochastic rates from heterogeneous snapshots of particle positions. Bull Math Biol. 2024;86(6):74. doi: 10.1007/s11538-024-01301-4 [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 44.Besag J. Spatial interaction and the statistical analysis of lattice systems. J R Stat Soc Ser B Methodol. 1974;36:192–236. [Google Scholar]
  • 45.Kaznatcheev A, Peacock J, Basanta D, Marusyk A, Scott JG. Fibroblasts and alectinib switch the evolutionary games played by non-small cell lung cancer. Nat Ecol Evol. 2019;3(3):450–6. doi: 10.1038/s41559-018-0768-z [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 46.Zhang J, Cunningham JJ, Brown JS, Gatenby RA. Integrating evolutionary dynamics into treatment of metastatic castrate-resistant prostate cancer. Nat Commun. 2017;8(1):1816. doi: 10.1038/s41467-017-01968-5 [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 47.Poels KE, Schoenfeld AJ, Makhnin A, Tobi Y, Wang Y, Frisco-Cabanos H, et al. Identification of optimal dosing schedules of dacomitinib and osimertinib for a phase I/II trial in advanced EGFR-mutant non-small cell lung cancer. Nat Commun. 2021;12(1):3697. doi: 10.1038/s41467-021-23912-4 [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 48.Farrokhian N, Maltas J, Dinh M, Durmaz A, Ellsworth P, Hitomi M, et al. Measuring competitive exclusion in non-small cell lung cancer. Sci Adv. 2022;8(26):eabm7212. doi: 10.1126/sciadv.abm7212 [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 49.Hamis S, Somervuo P, Ågren JA, Tadele DS, Kesseli J, Scott JG, et al. Spatial cumulant models enable spatially informed treatment strategies and analysis of local interactions in cancer systems. J Math Biol. 2023;86(5):68. doi: 10.1007/s00285-023-01903-x [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 50.Grimm V, Hauber ME, Berger U, Meyer KM, Railsback SF. A manifesto for Individual-based Ecology. IBE. 2025;1:e147788. doi: 10.3897/ibe.1.147788 [DOI] [Google Scholar]
  • 51.Filatova T, Verburg PH, Parker DC, Stannard CA. Spatial agent-based models for socio-ecological systems: challenges and prospects. Themat Issue Spat Agent-Based Models Socio-Ecol Syst. 2013;45:1–7. [Google Scholar]
  • 52.Bonabeau E. Agent-based modeling: methods and techniques for simulating human systems. Proc Natl Acad Sci U S A. 2002;99 Suppl 3(Suppl 3):7280–7. doi: 10.1073/pnas.082080899 [DOI] [PMC free article] [PubMed] [Google Scholar]
  • 53.Kondratiev YG, Kuna T. Harmonic analysis on configuration space I: general theory. Infin Dimens Anal Quantum Probab Relat Top. 2002;05(02):201–33. doi: 10.1142/s0219025702000833 [DOI] [Google Scholar]
PLoS Comput Biol. doi: 10.1371/journal.pcbi.1014786.r001

Decision Letter 0

Ovidiu Radulescu, Tobias Bollenbach

20 Jul 2026

PCOMPBIOL-D-26-00922

R-package agentBayes: likelihood-based statistical methods for agent-based models

PLOS Computational Biology

Dear Dr. Moser,

Thank you for submitting your manuscript to PLOS Computational Biology. After careful consideration, we feel that it has merit but does not fully meet PLOS Computational Biology's publication criteria as it currently stands. Therefore, we invite you to submit a revised version of the manuscript that addresses the points raised during the review process.

Please submit your revised manuscript by Sep 19 2026 11:59PM. If you will need more time than this to complete your revisions, please reply to this message or contact the journal office at ploscompbiol@plos.org. When you're ready to submit your revision, log on to https://www.editorialmanager.com/pcompbiol/ and select the 'Submissions Needing Revision' folder to locate your manuscript file.

Please include the following items when submitting your revised manuscript:

* A letter that responds to each point raised by the editor and reviewer(s). You should upload this letter as a separate file labeled 'Response to Reviewers'. This file does not need to include responses to formatting updates and technical items listed in the 'Journal Requirements' section below.

* A marked-up copy of your manuscript that highlights changes made to the original version. You should upload this as a separate file labeled 'Revised Manuscript with Track Changes'.

* An unmarked version of your revised paper without tracked changes. You should upload this as a separate file labeled 'Manuscript'.

If you would like to make changes to your financial disclosure, competing interests statement, or data availability statement, please make these updates within the submission form at the time of resubmission. Guidelines for resubmitting your figure files are available below the reviewer comments at the end of this letter. As the corresponding author, your ORCID iD is verified in the submission system and will appear in the published article. PLOS supports the use of ORCID, and we encourage all coauthors to register for an ORCID iD and use it as well. Please encourage your coauthors to verify their ORCID iD within the submission system before final acceptance, as unverified ORCID iDs will not appear in the published article. Only the individual author can complete the verification step; PLOS staff cannot verify ORCID iDs on behalf of authors. We look forward to receiving your revised manuscript.

Kind regards,

Ovidiu Radulescu, PhD

Academic Editor

PLOS Computational Biology

Tobias Bollenbach

Section Editor

PLOS Computational Biology

Additional Editor Comments (if provided):

Journal Requirements:

If the reviewer comments include a recommendation to cite specific previously published works, please review and evaluate these publications to determine whether they are relevant and should be cited. There is no requirement to cite these works unless the editor has indicated otherwise.

1) Please upload all main figures as separate Figure files in .tif or .eps format. For more information about how to convert and format your figure files please see our guidelines:

https://journals.plos.org/ploscompbiol/s/figures

2) Please upload a copy of Figures FIG 1, 2A-D, 3A-D, 4A-C, and 5A-L which you refer to in your text on pages 8, 12, 15, 16, and 18. Or, if the figure is no longer to be included as part of the submission please remove all reference to it within the text.

3) We have noticed that you have uploaded Supporting Information files, but you have not included a list of legends. Please add a full list of legends for your Supporting Information files after the references list.

4)Your current Financial Disclosure states, “The author(s) received no specific funding for this work". However, your funding information is Academy of Finland

336212

Otso Ovaskainen

Academy of Finland345110Otso OvaskainenHORIZON EUROPE European Research Council856506Otso OvaskainenWenner-Gren StiftelsernaWGF2022-0044Sara HamisKjell och Märta Beijers StiftelseSara HamisNorges Forskningsråd325628/IARDagim S. Tadele in the submission form that you did not receive funding. Please indicate by return email the full and correct funding information for your study and confirm the order in which funding contributions should appear. Please be sure to indicate whether the funders played any role in the study design, data collection and analysis, decision to publish, or preparation of the manuscript.

5)We have amended your Competing Interest statement to comply with journal style. We kindly ask that you double check the statement and let us know if anything is incorrect.

Reviewers' comments:

Reviewer's Responses to Questions

Comments to the Authors:

Please note here if the review is uploaded as an attachment.

Reviewer #1: The paper presents agentBayes, an R package for likelihood-based inference in agent-based models written as continuous-space and continuous-time RCP models. The key construction is an asymptotic likelihood, built from perturbative expressions for densities, variances, and spatial cumulants, then used for Bayesian parameter inference on simulated systems and cancer cell data.

There is a lot of real mathematics here. I found the work technically ambitious, and the software angle is also valuable. Automating these derivations is a serious contribution: in past work, the likelihood is derived by hand, which prevents most ABMs users from using likelihood-based methods (still, the past literature on likelihood-based inference in ABMs should be mentioned more carefully).

My recommendation is major revision.

The main issue is the way the contribution is framed. Some claims read as if the paper gives a general likelihood theory for ABMs, while I do not think the manuscript supports that. The theory applies to continuous-space, continuous-time RCP models. This is a meaningful class, and probably a large one in some fields. Still, many standard ABMs use discrete time, discrete space, and synchronous updating. These are central examples of ABMs for many readers. The manuscript should make this scope visible consistently. For instance, sentences such as “The framework presented in this paper is to our knowledge the first mathematically rigorous likelihood-based unifying statistical theory of ABMs” and “derive an asymptotically exact expression for the likelihood of ABMs” are overselling a result that has important limitations. The paper can still be very important with this narrower framing. On the same note, the case studies are useful and Figure 2 is especially important. Still, they mainly concern spatial birth-death-competition systems, and I am not convinced that these examples show representativeness for ABMs in the broad sense, i.e., they are not classical examples used for ABMs in general.

Minor concerns:

* I would like the authors to explain where the first-order approximation is expected to fail. The examples show that it works in the chosen settings. They do not give me much intuition about the edge of the method.

* The cancer cell example is interesting and gives the paper a real application. It remains an application, though. It cannot check parameter recovery, since the true parameters are unknown.

* The paper should say more about practical identifiability. I would especially worry about tradeoffs between interaction strength and interaction range. Maybe this is already well understood in the RCP literature. If so, the manuscript should point the reader there.

* The discussion of previous likelihood-based work on ABMs should be tightened. There are already papers that build likelihoods for ABMs, often in a model-specific way. The distinctive part here is the automated construction for RCP models.

Reviewer #2: The paper proposes a novel likelihood-based framework for continues time space and time agent-based models that builds upon the framework of the Reactant-Catalyst-Product (RCP) (from ref 36 by the same group). The method uses a perturbational approximation to mean and covariance of the number of particles in different plots, to derive an approximate likelihood function for agent-based models (ABMs) using Poisson or Normal statistics, enabling efficient inference of the parameters governing agent interactions. The approach is applied to two synthetic datasets and one real cancer dataset. The methodology is incorporated in the R-package agentBayes. Efficient inference for agent-based models are an important problem and this paper contributes a well presented and useful toolkit contributes to this area. Overall, the paper is well written and clear and the application to real world situation is great. Before publications, I would recommend the authors to consider these comments:

- In the introduction, please specify more clearly what is the novel contribution in this manuscript compared to prior work from the same group on RCP (ref 36), is this only the package and the new applications? It seems to me that the conditional expectation equation 4 is obtained in this paper.

- Regarding the case studies, I have the following questions: How has the prior distributions been chosen. It seems that the mode of the prior distribution is not matched with the true value in all cases (for example A+ in case study 1) and this can contribute to the bias in the posterior estimate.

- The non-spatial model performs better for some of the parameters which is puzzling, can this be explained?

- The likelihood approach used is approximative and only exact in the limit of long-range interactions. How much of the error in the estimates comes from this kind of approximation. One possibility is to compare this results with inference based on ABC using the exact simulations to quantify the effect of the approximations in the likelihood.

- Some of the remaining uncertainty in the parameters could be due to non-identifiability in the parameters so some pair plots would be good.

- Alternatively for case study one another parameter set up where epsilon is smaller and the likelihood is expected to be more exact could be performed and compared.

- As the first two case studies with simulated data are on one-species examples, authors could consider simulating the third example with some of the inferred parameters as ground truth an apply their inference framework for further validation of the their results.

- Authors discuss some of the other approaches for efficient inference of agent-based models they do not discuss use of machine-learning enhanced simulation-based inference (e.g. see https://doi.org/10.1371/journal.pcbi.1009508)

- I noticed a typo in the abstract “… in the here introduced R-package …”

**********

Have the authors made all data and (if applicable) computational code underlying the findings in their manuscript fully available?

The PLOS Data policy requires authors to make all data and code underlying the findings described in their manuscript fully available without restriction, with rare exception (please refer to the Data Availability Statement in the manuscript PDF file). The data and code should be provided as part of the manuscript or its supporting information, or deposited to a public repository. For example, in addition to summary statistics, the data points behind means, medians and variance measures should be available. If there are restrictions on publicly sharing data or code —e.g. participant privacy or use of data from a third party—those must be specified.

Reviewer #1: Yes

Reviewer #2: Yes

**********

PLOS authors have the option to publish the peer review history of their article (what does this mean?). If published, this will include your full peer review and any attached files.

If you choose “no”, your identity will remain anonymous but your review may still be made public.

Do you want your identity to be public for this peer review?  For information about this choice, including consent withdrawal, please see our Privacy Policy.

Reviewer #1: No

Reviewer #2: No

[NOTE: If reviewer comments were submitted as an attachment file, they will be attached to this email and accessible via the submission site. Please log into your account, locate the manuscript record, and check for the action link "View Attachments". If this link does not appear, there are no attachment files.]

Figure resubmission:

While revising your submission, we strongly recommend that you use PLOS’s NAAS tool (https://ngplosjournals.pagemajik.ai/artanalysis) to test your figure files. NAAS can convert your figure files to the TIFF file type and meet basic requirements (such as print size, resolution), or provide you with a report on issues that do not meet our requirements and that NAAS cannot fix.

After uploading your figures to PLOS’s NAAS tool - https://ngplosjournals.pagemajik.ai/artanalysis, NAAS will process the files provided and display the results in the "Uploaded Files" section of the page as the processing is complete. If the uploaded figures meet our requirements (or NAAS is able to fix the files to meet our requirements), the figure will be marked as "fixed" above. If NAAS is unable to fix the files, a red "failed" label will appear above. When NAAS has confirmed that the figure files meet our requirements, please download the file via the download option, and include these NAAS processed figure files when submitting your revised manuscript.

Reproducibility:

To enhance the reproducibility of your results, we recommend that authors of applicable studies deposit laboratory protocols in protocols.io, where a protocol can be assigned its own identifier (DOI) such that it can be cited independently in the future. Additionally, PLOS ONE offers an option to publish peer-reviewed clinical study protocols. Read more information on sharing protocols at https://plos.org/protocols?utm_medium=editorial-email&utm_source=authorletters&utm_campaign=protocols

PLoS Comput Biol. doi: 10.1371/journal.pcbi.1014786.r003

Decision Letter 1

Ovidiu Radulescu, Tobias Bollenbach

1 Sep 2026

Dear Mr. Moser,

We are pleased to inform you that your manuscript 'R-package agentBayes: likelihood-based statistical methods for agent-based models' has been provisionally accepted for publication in PLOS Computational Biology.

Before your manuscript can be formally accepted you will need to complete some formatting changes, which you will receive in a follow up email. A member of our team will be in touch with a set of requests.

Please note that your manuscript will not be scheduled for publication until you have made the required changes, so a swift response is appreciated.

IMPORTANT: The editorial review process is now complete. PLOS will only permit corrections to spelling, formatting or significant scientific errors from this point onwards. Requests for major changes, or any which affect the scientific understanding of your work, will cause delays to the publication date of your manuscript.

Should you, your institution's press office or the journal office choose to press release your paper, you will automatically be opted out of early publication. We ask that you notify us now if you or your institution is planning to press release the article. All press must be co-ordinated with PLOS.

Thank you again for supporting Open Access publishing; we are looking forward to publishing your work in PLOS Computational Biology.

Best regards,

Ovidiu Radulescu, PhD

Academic Editor

PLOS Computational Biology

Tobias Bollenbach

Section Editor

PLOS Computational Biology

***********************************************************

Reviewer's Responses to Questions

Comments to the Authors:

Please note here if the review is uploaded as an attachment.

Reviewer #1: The authors have addressed the main concerns raised in the previous review. I particularly appreciate the revised framing of the contribution, which now better reflects the scope of the framework and its connection to continuous-space, continuous-time RCP models. The additional validation analyses are also useful, especially the supplementary parameter recovery analysis for the cancer model, which provides further evidence that the framework can recover model parameters in a realistic application setting.

Overall, I believe the manuscript is ready for acceptance. The mathematical framework is technically strong, the methodological contribution is valuable, and the revised manuscript now presents the scope of the approach more clearly. I believe that the method proposed by the authors could be useful to the community and I would be glad to see it published.

I also appreciate the authors’ clarification regarding the applicability of the perturbation approximation. I found this point useful for understanding the limits of applicability of the framework. At the same time, in their response, the authors discuss that the framework was tested in regimes far from the mean-field limit, where the perturbation expansion is far from its asymptotic regime, and that the method was still able to recover the data-generating parameters. I find this result encouraging, although its interpretation is not immediately clear in terms of defining the practical applicability regime of the approximation. After considering both the authors’ response and the discussion now provided in the manuscript, particularly regarding the assumptions of the framework and the conditions under which it may become less accurate, I believe that this point has been adequately addressed. As such, I have no further major concerns and recommend acceptance.

Reviewer #2: Authors have revised their papers according to the comments in a satisfactory manner.

**********

Have the authors made all data and (if applicable) computational code underlying the findings in their manuscript fully available?

The PLOS Data policy requires authors to make all data and code underlying the findings described in their manuscript fully available without restriction, with rare exception (please refer to the Data Availability Statement in the manuscript PDF file). The data and code should be provided as part of the manuscript or its supporting information, or deposited to a public repository. For example, in addition to summary statistics, the data points behind means, medians and variance measures should be available. If there are restrictions on publicly sharing data or code —e.g. participant privacy or use of data from a third party—those must be specified.

Reviewer #1: Yes

Reviewer #2: Yes

**********

PLOS authors have the option to publish the peer review history of their article (what does this mean?). If published, this will include your full peer review and any attached files.

If you choose “no”, your identity will remain anonymous but your review may still be made public.

Do you want your identity to be public for this peer review?  For information about this choice, including consent withdrawal, please see our Privacy Policy.

Reviewer #1: No

Reviewer #2: No

PLoS Comput Biol. doi: 10.1371/journal.pcbi.1014786.r004

Acceptance letter

Ovidiu Radulescu, Tobias Bollenbach

PCOMPBIOL-D-26-00922R1

R-package agentBayes: likelihood-based statistical methods for agent-based models

Dear Dr Moser,

I am pleased to inform you that your manuscript has been formally accepted for publication in PLOS Computational Biology. Your manuscript is now with our production department and you will be notified of the publication date in due course.

The corresponding author will soon be receiving a typeset proof for review, to ensure errors have not been introduced during production. Please review the PDF proof of your manuscript carefully, as this is the last chance to correct any errors. Please note that major changes, or those which affect the scientific understanding of the work, will likely cause delays to the publication date of your manuscript.

Soon after your final files are uploaded, unless you have opted out, the early version of your manuscript will be published online. The date of the early version will be your article's publication date. The final article will be published to the same URL, and all versions of the paper will be accessible to readers.

For Research, Software, and Methods articles, you will receive an invoice from PLOS for your publication fee after your manuscript has reached the completed accept phase. If you receive an email requesting payment before acceptance or for any other service, this may be a phishing scheme. Learn how to identify phishing emails and protect your accounts at https://explore.plos.org/phishing.

Thank you again for supporting PLOS Computational Biology and open-access publishing. We are looking forward to publishing your work!

With kind regards,

Sharmila Kamatchi

PLOS Computational Biology | Carlyle House, Carlyle Road, Cambridge CB4 3DN | United Kingdom ploscompbiol@plos.org | Phone +44 (0) 1223-442824 | ploscompbiol.org | @PLOSCompBiol

Associated Data

    This section collects any data citations, data availability statements, or supplementary materials included in this article.

    Supplementary Materials

    S1 File. Section 1–2 include mathematical descriptions of the models used in the case studies.

    Section 3 provides results on the effect of the ordering of grid cells on the likelihood calculation. Section 4 includes a justification for the conditional variance of agent densities. Section 5 includes results on MCMC convergence, posterior correlations and further validation tests. Section 6 presents a proof of the conditional expectation of agent density.

    (PDF)

    pcbi.1014786.s001.pdf (2.6MB, pdf)
    Attachment

    Submitted filename: ResponseLetter.docx

    pcbi.1014786.s003.docx (29.6KB, docx)

    Data Availability Statement

    The minimal data set and accompanying code are available at Figshare via https://figshare.com/s/899f73102e37b1a0c5d5.


    Articles from PLOS Computational Biology are provided here courtesy of PLOS

    RESOURCES