Skip to main content
Browse Subject Areas

Click through the PLOS taxonomy to find articles in your field.

For more information about PLOS Subject Areas, click here.

  • Loading metrics

Bayesian inference of COVID-19 spreading rates in South Africa

  • Rendani Mbuvha ,

    Roles Conceptualization, Data curation, Formal analysis, Investigation, Methodology, Visualization, Writing – original draft, Writing – review & editing

    Affiliations School of Statistics and Actuarial Science, University of Witwatersrand, Johannesburg, South Africa, Institute of Intelligent Systems, University of Johannesburg, Johannesburg, South Africa

  • Tshilidzi Marwala

    Roles Conceptualization, Supervision, Writing – review & editing

    Affiliation Institute of Intelligent Systems, University of Johannesburg, Johannesburg, South Africa


The Severe acute respiratory syndrome coronavirus 2 (SARS-CoV-2) pandemic has highlighted the need for performing accurate inference with limited data. Fundamental to the design of rapid state responses is the ability to perform epidemiological model parameter inference for localised trajectory predictions. In this work, we perform Bayesian parameter inference using Markov Chain Monte Carlo (MCMC) methods on the Susceptible-Infected-Recovered (SIR) and Susceptible-Exposed-Infected-Recovered (SEIR) epidemiological models with time-varying spreading rates for South Africa. The results find two change points in the spreading rate of COVID-19 in South Africa as inferred from the confirmed cases. The first change point coincides with state enactment of a travel ban and the resultant containment of imported infections. The second change point coincides with the start of a state-led mass screening and testing programme which has highlighted community-level disease spread that was not well represented in the initial largely traveller based and private laboratory dominated testing data. The results further suggest that due to the likely effect of the national lockdown, community level transmissions are slower than the original imported case driven spread of the disease.


The first reported case of the novel coronavirus (SARS-CoV-2) in South Africa was announced on 5 March 2020, following the initial manifestation of the virus in Wuhan China in December 2019 [13]. Due to its further spread and the severity of its associated clinical outcomes, the disease was subsequently declared a pandemic by the World Health Organisation (WHO) on 11 March 2020 [1, 2]. In South Africa, by 26 April 2020, 4546 people had been confirmed to have been infected by the coronavirus with 87 fatalities [4].

Numerous states have attempted to minimise the growth in number of COVID-19 infections [1, 5, 6]. These attempts are largely based on non-pharmaceutical interventions (NPIs) aimed at separating the infectious population from the susceptible population [1].

These initiatives aim to strategically reduce the increase in infections to a level where their healthcare systems stand a chance of minimising the number of fatalities [1]. Some of the critical indicators for policymaker response planning include projections of the infected population, estimates of health care service demand and whether current containment measures are effective [1].

As the pandemic develops in a rapid and varied manner in most countries, calibration of epidemiological models based on available data can prove to be [7]. This difficulty is further escalated by the high number of asymptomatic cases and the limited testing capacity [1, 2].

A fundamental issue when calibrating localised models is inferring parameters of compartmental models such as susceptible-infectious-recovered (SIR) and the susceptible-exposed-infectious-recovered (SEIR) that are widely used in infectious disease projections. In the view of public health policymakers, a critical aspect of projecting infections is the inference of parameters that align with the underlying trajectories in their jurisdictions. The spreading rate is a parameter of particular interest which is subject to changes due to voluntary social distancing measures and government-imposed contact bans.

The uncertainty in utilising these models is compounded by the limited data in the initial phases and the rapidly changing dynamics due to rapid public policy changes.

To address these complexities, we utilise the Bayesian Framework for the inference of epidemiological model parameters in South Africa. The Bayesian framework allows for both incorporation of prior knowledge and principled embedding of uncertainty in parameter estimation.

In this work we combine Bayesian inference with the compartmental SEIR and SIR models to infer time varying spreading rates that allow for quantification of the impact of government interventions in South Africa.


Epidemiological modelling

Compartmental models are a class of models that is widely used in epidemiology to model transitions between various stages of disease [1, 8, 9]. We now introduce the Susceptible-Exposed-Infectious-Recovered (SEIR) and the related Susceptible-Infectious-Recovered (SIR) compartmental models that have been dominant in COVID-19 modelling literature [1, 5, 6, 10].

The Susceptible-Exposed-Infectious-Recovered Model.

The SEIR is an established epidemiological model for the projection of infectious diseases. The SEIR models the transition of individuals between four stages of a condition, namely:

  • being susceptible to the condition,
  • being infected and in incubation
  • having the condition and being infectious to others and
  • having recovered and built immunity for the disease.

The SEIR can be interpreted as a four-state Markov chain which is illustrated diagrammatically in Fig 1. The SEIR relies on solving the system of ordinary differential equations below representing the analytic trajectory of the infectious disease [1]. (1) (2) (3) (4) Where S is the susceptible population, I is the infected population, R is the recovered population and N is the total population where N = S + E + I + R. λ is the transmission rate, σ is the rate at which individuals in incubation become infectious, and μ is the recovery rate. 1/σ and 1/μ therefore, become the incubation period and contagious period respectively.

Fig 1. An Illustration of the underlying states of the Susceptible-Exposed-Infectious-Recovered Model(SEIR).

We also consider the Susceptible-Infectious-Recovered (SIR) model which is a subclass of the SEIR model that assumes direct transition from the susceptible compartment to the infected (and infectious) compartment. The SIR is represented by three coupled ordinary differential equations rather than the four in the SEIR. Fig 2 depicts the three states of the SIR model.

Fig 2. An Illustration of the underlying states of the Susceptible-Infectious-Recovered Model(SIR).

The basic reproductive number R0.

The basic reproductive number (R0) represents the mean number of additional infections created by one infectious individual in a susceptible population. According to the latest available literature, without accounting for any social distancing policies the R0 for COVID-19 is between 2 and 3.5 [2, 6, 10, 11]. R0 can be expressed in terms of λ and μ as: (5)

Extensions to the SEIR and SIR models.

We use an extended version of the SEIR and SIR models of [6] that incorporates some of the observed phenomena relating to COVID-19. First we include a delay D in becoming infected (Inew) and being reported in the confirmed case statistics, such that the confirmed reported cases CRt at some time t are in the form [6]: (6)

We further assume that the spreading rate λ is time-varying rather than constant with change points that are affected by government interventions and voluntary social distancing measures.

Bayesian parameter inference

We follow the framework of [6] to perform Bayesian inference for model parameters on the South African COVID-19 data. The Bayesian framework allows for the posterior inference of parameters which updates prior beliefs based on a data-driven likelihood. The posterior inference is governed by Bayes theorem as follows: (7)

Where P(W|D, M) is the posterior distribution of a vector of model parameters (W) given the model(M) and observed data(D), P(D|W, M) is the data likelihood and P(D) is the evidence.

The likelihood.

The Likelihood indicates the probability of observing the reported case data given the assumed model. In our study, we adopt the Student-T distribution as the Likelihood as suggested by [6]. Similar to a Gaussian likelihood, the Student-T likelihood allows for parameter updates that minimise discrepancies between the predicted and observed reported cases.


Parameter prior distributions encode some prior subject matter knowledge into parameter estimation. In the case of epidemiological model parameters, priors incorporate literature based expected values of parameters such as recovery rate(μ), spreading rate(λ), change points based on policy interventions etc.

The prior settings for the model parameters are listed in Table 1. We follow [6] by selecting LogNormal distributions for λ and σ such that the initial mean basic reproductive number is 3.2 which is consistent with literature [2, 5, 6, 10, 12]. We set a LogNormal prior for the σ such that the mean incubation period is five days. We use the history of government interventions to set priors on change points in the spreading rate. The priors on change-points include 19/03/2020 when a travel ban and school closures were announced, and 28/03/2020 when a national lockdown was enforced. We keep the priors for the Lognormal distributions of the spreading rates after the change points weakly-informative by setting the same mean as λ0 and higher variances across all change points. This has the effect of placing greater weight on the data driven likelihood. Similar to [6] we adopt weakly-informative Half-Cauchy priors for the initial conditions for the infected and exposed populations.

Table 1. Prior distribution settings for SEIR and SIR model parameters.

Markov Chain Monte Carlo (MCMC).

Given that the closed-form inference of the posterior distributions on the parameters listed in Table 1 is infeasible, we make use of Markov Chain Monte Carlo to sample from the posterior. Monte Carlo methods approximate solutions to complex numerical problems by simulating a random process. MCMC uses a Markov Chain to sample from the posterior distribution, where a Markov Chain is a sequence of random variables Wt such that:

MCMC techniques have been widely used in COVID-19 parameter inference [6, 10]. In this work, we explore inference using Metropolis-Hastings (MH), Slice Sampling and No-U-Turn Sampler (NUTS).

Metropolis Hastings (MH).

MH is one of the simplest algorithms for generating a Markov Chain which converges to the correct stationary distribution. The MH generates proposed samples using a proposal distribution. A new parameter state Wt* is accepted or rejected probabilistically based on the posterior likelihood ratio: (8)

A common proposal distribution is a symmetric random walk obtained by adding Gaussian noise to a previously accepted parameter state. Random walk behaviour of such a proposal typically results in low sample acceptance rates.

Slice sampling.

Slice sampling facilitates sampling from the posterior distribution P(W|D, M) by adding an auxiliary variable u such that the joint posterior distribution becomes: (9)

Where Z = ∫P(W|D, M)dW which is a normalisation constant. Marginal samples for the parameters W can then be obtained by ignoring u samples from the joint samples. This process corresponds to sampling above the slice of the posterior density function around a predefined window. Fig 3 shows an illustration of slice sampling.

Fig 3. An illustration of slice sampling, moving from a parameter sample w(i) to w(i + 1) via auxiliary variable sample u(i + 1).

While sample acceptance is guaranteed with slice sampling, a large slice window can lead to computationally inefficient sampling while a small window can lead to poor mixing.

Hybrid Monte Carlo (HMC) and the No-U-Turn Sampler (NUTS).

Metropolis-Hastings (MH) and slice sampling tend to exhibit excessive random walk behaviour—where the next state of the Markov Chain is randomly proposed from a proposal distribution [1315]. This results in low proposal acceptance rates and small effective sample sizes.

HMC proposed by [16] reduces random walk behaviour by adding auxiliary momentum variables to the parameter space [15]. HMC creates a vector field around the current state using gradient information, which assigns the current state a trajectory towards a high probability next state [15]. The dynamical system formed by the model parameters W and the auxiliary momentum variables p is represented by the Hamiltonian H(W, p) written as follows [15, 16]: (10)

Where M(W) is the negative log-likelihood of the posterior distribution in Eq 7, also referred to as the potential energy. K(p) is the kinetic energy defined by the kernel of a Gaussian with a covariance matrix M [17]: (11)

The trajectory vector field is defined by considering the parameter space as a physical system that follows Hamiltonian Dynamics [15]. The dynamical equations governing the trajectory of the chain are then defined by Hamiltonian equations at a fictitious time t as follows [16]: (12) (13)

In practical terms, the dynamical trajectory is discretised using the leapfrog integrator. In the leapfrog integrator to reach the next point in the path, we take half a step in the momentum direction, followed by a full step in the direction of the model parameters—then ending with another half step in the momentum direction.

Due to the discretising errors arising from leapfrog integration a Metropolis acceptance step is then performed in order to accept or reject the new sample proposed by the trajectory [15, 18]. In the Metropolis step the parameters proposed by the HMC trajectory w* are accepted with the probability [16]: (14)

Algorithm 1 shows the pseudo-code for the HMC where ϵ is a discretisation stepsize. The leapfrog steps are repeated until the maximum trajectory length L is reached.

Algorithm 1: Hybrid Monte Carlo Algorithm

Data: Confirmed Cases dataset {C(t)}

Result: N Samples of model parameters W

for n ← 1 to N do


sample the auxiliary momentum variables p

 Use leapfrog steps to generate proposals for w

for t ← 1 to L do





Metropolis Update step:

 (p, w)n ← (p(L), w(L)) with probability:


The HMC algorithm has multiple parameters that require tuning for efficient sampling, such as the step size and the trajectory length. In terms of trajectory length, a trajectory length that is too short leads to random walk behaviour similar to MH. While a trajectory length that is too long results in a trajectory that inefficiently traces back.

The stepsize is also a critical parameter for sampling, small stepsizes are computationally inefficient leading to correlated samples and poor mixing while large stepsizes compound discretisation errors leading to low acceptance rates. Tuning these parameters requires multiple time consuming trial runs.

NUTS automates the tuning of the leapfrog stepsize and trajectory length. In NUTS the stepsize is tuned during an initial burn-in phase by targeting particular levels of sample acceptance. The trajectory length is tuned by iteratively adding steps until either the chain starts to trace back (U-turn) or the Hamiltonian explodes (becomes infinite).

We use the samplers described above to calibrate the SEIR and SIR models on daily new cases and cumulative cases data for South Africa up to and including 20 April 2020 provided by Johns Hopkins University’s Center for Systems Science and Engineering(CSSE) [3].


SIR and SEIR model parameter inference was performed using confirmed cases data up to and including 20 April 2020 and MCMC samplers described in the methodology section. Each of the samplers are run such that 5000 samples are drawn with 1000 burn-in and tuning steps. We use leave-one-out(LOO) cross-validation error of [19] to evaluate the goodness of fit of each model.

Table 2 shows the LOO validation errors of the various models. It can be seen that the SIR model with two change points as the best model fit with the lowest mean LOO of 448.00. The SEIR model with two change points showed a mean LOO of 459.94. We note that [6] similarly finds that the SIR model displayed superior goodness of fit to the SEIR on German data.

Table 2. Leave-one out (LOO) statistics comparing SEIR and SIR models with different number of change points.

We now further present detailed results of the SIR and SEIR models with inference using NUTS, the trace plots from these models indicating stationarity in the sampling chains are provided in S2 and S5 Figs. The trace plots for the SIR and SEIR models using MH are provided in S3 and S6 Figs, while similar trace plots for slice sampling are provided in S4 and S7 Figs. The trace plots largely indicate that the NUTS sampler displays greater agreement between parallel chains thus lower rhat values.

Posterior parameter distributions

Fig 4 shows the posterior distributions of the SIR model parameters. The parameter estimates are λ0 ≈ 0.495 (CI[0.41, 0.564]), λ1 ≈ 0.099 (CI[0.065, 0.145]), λ2 ≈ 0.197 (CI[0.134, 0.264]), μ ≈ 0.151 (CI[0.09, 0.205]) and reporting delay (D) ≈ 6.848 (CI[5.178, 8.165]). This corresponds to R0 values of 3.278 (CI[2.715, 3.73]), 0.655 (CI[0.430, 0.960]) and 1.304 (CI[0.887, 1.7748]) at the respective change points. S1 Fig further shows the joint posterior distributions of λt and μ at each of the change points.

Fig 4. Posterior parameter distributions for the SIR model with two change points.

Time-varying spread rates allow for inference of the impact of various state and societal interventions on the spreading rate. Fig 5 shows the fit and projections based on SIR models with zero, one and two change points. As can be seen from the plot the two change point model best captures the trajectory in the development of new cases relative to the zero and one change point models. The superior goodness of fit of the two change point model is also illustrated in Table 2. The fit and projections showing similar behaviour on the SEIR model with various change points are shown in Fig 6.

Fig 5. Predictions and actual data(until 20 April 2020) based on SIR models with various change points.

The top plot indicates the actual and projected new cases while the bottom plot shows the actual and projected cumulative cases.

Fig 6. Predictions and actual data(until 20 April 2020) based on SEIR models with various change points.

The top plot indicates the actual and projected new cases while the bottom plot shows the actual and projected cumulative cases.

Reporting delays, incubation and infectious period

The mean reporting delay time in days was found to be 6.848 (CI[5.178, 8.165]), literature suggests this delay includes both the incubation period and the test reporting lags. The posterior distribution incubation period from the SEIR model in Fig 7 yields a median incubation period of 4.537 days (CI[2.499, 6.787]). Thus suggesting a mean laboratory reporting delay of approximately 2.311 days. A mean recovery rate μ ≈ 0.151 implies mean infectious period of 6.620 days which is in line with related literature [2, 6, 10].

Fig 7. Posterior parameter distributions under SEIR model with two change points.

Timing and impact of interventions

Fig 8 depicts the posterior distributions of the spreading rates and times corresponding to each change point. We observe that the first change point is on a mean date of 18 March 2020 (CI:[16/03/2020, 20/03/2020]). This date is consistent with the travel ban, school closures and social distancing recommendations. This change point resulted in a substantial decrease in the spreading rate (80%) primarily due to the reduction in imported infections.

Fig 8. Posterior distributions of the spreading rates(λt) and the corresponding distributions of the time points.

The second change point is observed on 28 March 2020 (CI:[26/03/2020, 30/03/2020]). This time point coincides with the announcement of mass screening and testing by the government on 30 March 2020. The resulting mean R0 of 1.304 implies a 60% decrease from the initial value.

The inference of parameters is dependent on the underlying testing processes that generate the confirmed case data. The effect of the mass screening and testing campaign was to change the underlying confirmed case data generating process by widening the criteria of those eligible for testing. While initial testing focused on individuals that either had exposure to known cases or travelled to known COVID-19 affected countries, mass screening and testing further introduced detection of community level transmissions which may contain undocumented contact and exposure to COVID-19 positive individuals.


We have performed Bayesian parameter inference of the SIR and SEIR models using MCMC and publicly available data as at 20 April 2020. The resulting parameter estimates fall in-line with the existing literature in-terms of mean baseline R0 (before government action), mean incubation time and mean infectious period [2, 5, 6, 10].

We find that initial government action that mainly included a travel ban, school closures and stay-home orders resulted in a mean decline of 80% in the spreading rate. Further government action through mass screening and testing campaigns resulted in a second trajectory change point. This latter change point is mainly driven by the widening of the population eligible for testing, from travellers (and their known contacts) to include the generalised community who would have probably not afforded private lab testing which dominated the initial data. This resulted in an increase of R0 to 1.304. The effect of mass screening and testing can also be seen in Fig 9 indicating a mean increase in daily tests preformed from 1639 to 4374.

Fig 9. Daily COVID-19 tests performed in South Africa.

The orange line indicates the segmented mean number of tests per day before and after the 28 March 2020 change point.

The second change point illustrates the possible existence of multiple pandemics, as suggested by [20]. Thus testing after 28 March is more indicative of community-level transmissions that were possibly not as well documented in-terms of contact tracing and isolation relative to the initial imported infection driven pandemic. This is also supported by the documented increase in public laboratory testing (relative to private) past this change point, suggesting health care access might also play a role in the detection of community-level infections [21].


We have utilised a Bayesian inference framework to infer time-varying spreading rates of COVID-19 in South Africa. The time-varying spreading rates allow us to estimate the effects of government actions on the dynamics of the pandemic.

The results indicate a decrease in the mean spreading rate of 60%, which mainly coincides with the containment of imported infections, school closures and stay at home orders.

The results also indicate the emergence of community-level infections which are increasingly being highlighted by the mass screening and testing campaign. The development of the community level transmissions (R0 ≈ 1.3041 (CI[0.887, 1.7748])) of the pandemic at the time of publication appears to be slower than that of the initial traveller based pandemic (R0 ≈ 3.278 (CI[2.715, 3.73])).

A future improvement to this work could include extensions to regional and provincial studies as current data suggests varied spreading rates both regionally and provincially. As more government interventions come to play priors on more change points might also be necessary.

Supporting information

S1 Fig. Two dimensional heat maps of the joint posterior distributions of the spreading rate(λ) and the recovery rate(μ) at various change points of the SIR model.

The high joint density areas (in yellow) indicate likely values of R0. The baseline mean R0 estimate in S1 Fig (a) is 3.278, the first change point estimate in Fig S1 Fig (b) is 0.655 while the second change point in S1 Fig (c) has resulted in a mean R0 estimate of 1.304.


S2 Fig. Shows diagnostic trace plots for the SIR model inferred using NUTS.


S3 Fig. Shows diagnostic trace plots for the SIR model inferred using MH.


S4 Fig. Shows diagnostic trace plots for the SIR model inferred using slice sampling.


S5 Fig. Shows diagnostic trace plots for the SEIR model inferred using NUTS.


S6 Fig. Shows diagnostic trace plots for the SEIR model inferred using MH.


S7 Fig. Shows diagnostic trace plots for the SEIR model inferred using slice sampling.



  1. 1. Mbuvha R, Marwala T. On Data-Driven Management of the COVID-19 Outbreak in South Africa. medRxiv. 2020;.
  2. 2. WHO. Report of the WHO-China Joint Mission on Coronavirus Disease 2019 (COVID-19); 2020. Available from:
  3. 3. Dong E, Du H, Gardner L. An interactive web-based dashboard to track COVID-19 in real time. The Lancet infectious diseases. 2020;20(5):533–534. pmid:32087114
  4. 4. Marivate V, de Waal A, Combrink H, Lebogo O, Moodley S, Mtsweni N, et al. Coronavirus disease (COVID-19) case data—South Africa; 2020. Available from:
  5. 5. Ferguson N, Laydon D, Nedjati Gilani G, Imai N, Ainslie K, Baguelin M, et al. Report 9: Impact of non-pharmaceutical interventions (NPIs) to reduce COVID19 mortality and healthcare demand; 2020.
  6. 6. Dehning J, Zierenberg J, Spitzner FP, Wibral M, Neto JP, Wilczek M, et al. Inferring COVID-19 spreading rates and potential change points for case number forecasts; 2020.
  7. 7. Song PX, Wang L, Zhou Y, He J, Zhu B, Wang F, et al. An epidemiological forecast model and software assessing interventions on COVID-19 epidemic in China; 2020.
  8. 8. Brauer F. In: Brauer F, van den Driessche P, Wu J, editors. Compartmental Models in Epidemiology. Berlin, Heidelberg: Springer Berlin Heidelberg; 2008. p. 19–79.
  9. 9. Blackwood JC, Childs LM. An introduction to compartmental modeling for the budding infectious disease modeler. Letters in Biomathematics. 2018;5(1):195–221.
  10. 10. Lourenco J, Paton R, Ghafari M, Kraemer M, Thompson C, Simmonds P, et al. Fundamental principles of epidemic spread highlight the immediate need for large-scale serological surveys to assess the stage of the SARS-CoV-2 epidemic; 2020.
  11. 11. Hellewell J, Abbott S, Gimma A, Bosse NI, Jarvis CI, Russell TW, et al. Feasibility of controlling 2019-nCoV outbreaks by isolation of cases and contacts. medRxiv. 2020;.
  12. 12. Zhou C, Yuan W, Wang J, Xu H, Jiang Y, Wang X, et al. Detecting Suspected Epidemic Cases Using Trajectory Big Data; 2020.
  13. 13. Mbuvha R, Boulkaibet I, Marwala T. Bayesian Automatic Relevance Determination for Feature Selection in Credit Default Modelling. In: International Conference on Artificial Neural Networks. Springer; 2019. p. 420–425.
  14. 14. Boulkaibet I, Marwala T, Mthembu L, Friswell MI, Adhikari S. Sampling Techniques in Bayesian Finite Element Model Updating. In: Simmermacher T, Cogan S, Horta LG, Barthorpe R, editors. Topics in Model Validation and Uncertainty Quantification, Volume 4. New York, NY: Springer New York; 2012. p. 75–83.
  15. 15. Mbuvha R, Boulkaibet I, Marwala T. Automatic Relevance Determination Bayesian Neural Networks for Credit Card Default Modelling; 2019.
  16. 16. Neal RM. Bayesian learning via stochastic dynamics. In: Advances in neural information processing systems; 1993. p. 475–482.
  17. 17. Neal RM. Bayesian learning for neural networks. vol. 118. Springer Science & Business Media; 2012.
  18. 18. Neal RM, et al. MCMC using Hamiltonian dynamics. Handbook of Markov Chain Monte Carlo. 2011;2(11):2.
  19. 19. Vehtari A, Gelman A, Gabry J. Practical Bayesian Model Evaluation Using Leave-One-out Cross-Validation and WAIC. Statistics and Computing. 2017;27(5):1413–1432.
  20. 20. Karim SA. SA’s COVID-19 Pandemic Trends and Next Steps; 2020.
  21. 21. Ministry of Health RSA. Update on COVID-19 20th April 2020;. Available from: