ALL Metrics
-
Views
-
Downloads
Get PDF
Get XML
Cite
Export
Track
Software Tool Article

Numerical Scheme for Compartmental Models: New Matlab Software Codes for Numerical Simulation

[version 1; peer review: 2 approved with reservations]
PUBLISHED 26 Apr 2023
Author details Author details
OPEN PEER REVIEW
REVIEWER STATUS

This article is included in the Bioinformatics gateway.

Abstract

Background: This paper presents a newly developed Matlab code for the numeri-
cal simulation of compartmental/deterministic models. It addresses modeling and
simulation issues concerning compartmental models. The code is easy to under-
stand and edit for the simulation of compartmental models. An alternative codes for
statistical software package R has been proposed for the same model. R software
is freely available for use.
Methods: We proposed a basic SEIR model for illustration purposes. Matlab and
R software codes are developed for the SEIR model which users can follow and
easily understand the computations.
Results: The two codes work on all Matlab and R versions. For models with more
compartments, we suggest using higher version of Matlab and R. Matlab works on
windows, Mac and Linux
Conclusions: New Matlab software codes purposely for numerical simulations of
classical deterministic models which can run on any version of Matlab has been
introduced in this paper. This code can be edited/modify to suit any deterministic
models and any desired output required. An alternative open source free version
has been written in R has been provided as well

Keywords

Compartmental Models, Numerical Simulation, Matlab software codes, R software codes

Introduction

With the help of a programming language that represents matrix and array mathematics directly, MATLAB combines a desktop environment tailored for iterative analysis and design processes.1 The Live Editor for writing scripts that mix code, output, and formatted text in an executable notebook is part of it.1 The Windows requirements are Windows 10 (version 20H2 or higher), Windows 11, Windows Server 2019, and Windows Server 2022. Many scientists and mathematicians choose to use this program since it can be accessed across all popular platforms, including Linux, Mac, and Windows, and because it can be used to explore, model, and analyze data.1 Matlab software has been used to run numerical simulations of compartmental models in epidemiology.211

There are several fundamental compartmental models described using differential equations. The basic ones include Susceptible - Infected (SI), Susceptible - Infected - Recovered (SIR),12,13 Susceptible - Infected - Susceptible (SIS),14 Susceptible - Infected - Recovered - Vaccinated (SIRV),15 Susceptible - Exposed - Infected - Recovered (SEIR) models.4 The purpose of this study is to make public new Matlab codes that authors have been utilising in their work to aid researchers, especially students, who rely on deterministic or compartmental modeling of epidemiology in the numerical simulation of their research projects. This well-detailed code, in our opinion, might be extremely helpful to them as many of them struggle to do the numerical simulations due to the dearth of research that specifically tackles numerical simulation of deterministic models and also to provide users more freedom for coding in Matlab. Recently, researchers have started sharing their codes and providing detailed explanation on how to use them. To provide users extra coding freedom, Guo et al.16 presented newly developed visualization framework called OpenSeesPyView, which is a Python programming-based graphical user interface (GUI) for OpenSeesPy, a prevalent finite element solver in earthquake engineering. The R package ag5Tools was written by Brown et al.17 and offers a streamlined interface for downloading and retrieving AgERA5 data. With the help of the program, time-series data for groups of geographic points may be easily extracted and converted into a format that can be employed in statistical models used in agricultural research. The Rcall interface, developed by Egert and Kreutz,18 gives users access to a large range of techniques written in MATLAB and R. The program is MATLAB-based and offers direct access to R-based tools and methodologies, such as those found on Bioconductor or CRAN. ShinyGAStool, an open source tool created by Hoffmann et al.,19 allows users to easily execute a candidate gene association analysis from a web browser using huge datasets. The remaining section are group as follows: The method section, where we demonstrate how to use the Matlab software codes. we look at the implementation, operation and discussions and limitations. The last section is the concluding section. The software section has the alternative software codes in R.

Methods

Implementation

We demonstrate how to use the matlab software codes with the SEIR compartmental model depicted in Figure 1. The population is partitioned into four (4) compartments: Susceptible, exposed, infected and recovered. Individuals are recruited into the susceptible class at a rate Ω and they die at a rate μ. The transmission rate is β and the recovery rate is γ. The rate at which exposed individuals become infectious is α and the disease-induced death rate is σ.

5e7d2a39-f9d1-481a-9dee-0531a07ed295_figure1.gif

Figure 1. Model dynamics flowchart.

The model is described by the following ordinary differential equations.

(1)
dSdt=ΩβISNμS,dEdt=βISNα+μE,dIdt=αEγ+σ+μI,dRdt=γIμR.
with initial conditions S0=S0,E0=E0,I0=I0,R0=R0.

For the purposes of the simulations, the following parameter values are chosen and is given in Table 1. The initial conditions chosen are S0=1000,E0=0,I0=1,R0=0

Table 1. Parameter values and description.

ParameterDescriptionValueSource
ΩRecruitment29.082
βTransmission rate0.92
αinfectiousness of the exposed individuals0.3assumed
μnatural rate of death0.4252912 ×1042
γRecovery rate of infected individuals0.1assumed
σDisease-induced death rate0.003286assumed

Once you have your model and parameter values clearly defined, you can then open the matlab editor window which is shown in Figure 2. Input or copy the codes and paste at the new script.

5e7d2a39-f9d1-481a-9dee-0531a07ed295_figure2.gif

Figure 2. Matlab Editor window.

The numerical Matlab software codes used for model (1) functiontSEIR=SEIRMODELΩβμσαγNS0E0I0R0MaxTime

Operation

if nargin==0

Ω=20;β=0.3;μ=0.00004252912;α=0.3;σ=0.003286;γ=0.1;

S0=1000;E0=0;I0=1;R0=0.0;

MaxTime=120; % The MaxTime stands for the duration of the simulation

end

S=S0;E=E0;I=I0;R=R0; N=S+E+I+R;

% The main iteration

options=odeset(’RelTol’,1e-5);

tpop=ode45@Diff260MaxTimeSEIRoptionsΩγβμσαN;

S=pop:1;E=pop:2;I=pop:3;R=pop:4;

% plots the graphs with scaled colours

figure(1)

Y=plot(t,S,’b.’);

legend(Y,’Susceptible’)

xlabel’Time (days)’

ylabel’S(t)’

figure(2)

T=plot(t,E,’.g’);

legend(T,’Exposed’)

xlabel’Time (days)’

ylabel’E(t)’

figure(3)

f=plot(t,I,’.m’);

legend(f,’Infected’)

xlabel’Time (days)’

ylabel’I(t)’

figure(4)

h=plot(t,R,’.g’);

legend(h,’Recovered’)

xlabel’Time (days)’

ylabel’R(t)’

% calculates the differential rates used in the integration.

functiondpop=Diff26tpopparameterΩ=parameter1;γ=parameter2;β=parameter3;μ=parameter4;σ=parameter5;α=parameter6;N=parameter7;S=pop1;E=pop2;I=pop3;R=pop4;dpop=zeros41;%Thesearethesystem1sequationsdpop1=ΩβIS./NμS;dpop2=βIS./Nα+μE;dpop3=αEγ+μ+σ.I;dpop4=γIμR;

Upon running the codes, some of the simulation results are shown in Figures 36.

5e7d2a39-f9d1-481a-9dee-0531a07ed295_figure3.gif

Figure 3. Exposed compartment.

5e7d2a39-f9d1-481a-9dee-0531a07ed295_figure4.gif

Figure 4. Infected Compartment.

5e7d2a39-f9d1-481a-9dee-0531a07ed295_figure5.gif

Figure 5. Recovered Compartment.

5e7d2a39-f9d1-481a-9dee-0531a07ed295_figure6.gif

Figure 6. Susceptible compartment.

Discussion

In Figures 36, are reported, the numerical solutions of system (1) for a period of 120 days. These codes can be modified for any compartmental models. The ‘figure’ command produces the output given in Figures 36. The steps or procedures listed in the codes have to be followed carefully in order not to encounter errors. The parameters can be represented with letters for instance Ω can be written in the codes as Omega as Matlab doesn’t recognize the parameters listed in the code. The code written in the editor window can be seen in Figure 7. The SEIR model is extended, and an alternative software, R codes has been provided at the appendix section. Using the same initial conditions and parameter values given in Table 1, the output figures for the R code are given by Figures 810. Users who cannot afford Matlab software can freely use the R software codes for the numerical simulation. The two software codes gives the same output results.

5e7d2a39-f9d1-481a-9dee-0531a07ed295_figure7.gif

Figure 7. Matlab software codes in editor window.

5e7d2a39-f9d1-481a-9dee-0531a07ed295_figure8.gif

Figure 8. Susceptible compartment using R.

5e7d2a39-f9d1-481a-9dee-0531a07ed295_figure9.gif

Figure 9. Exposed compartment using R.

5e7d2a39-f9d1-481a-9dee-0531a07ed295_figure10.gif

Figure 10. Infected compartment using R.

Limitations

MATLAB can disable some advanced graphics rendering features by switching to software OpenGL by ignoring extra legend entries.

R on the other hand, has a limited memory capacity which can be a problem when working with large data sets or running computationally-intensive analyses. It can be relatively slow compared to other programming languages like Matlab, C++ or Python, especially for certain types of calculations. It also has limited graphical capabilities.

Conclusion

This work seeks to introduce new matlab software codes purposely for numerical simulations of classical compartmental models which can run on any version of Matlab. The intended targets are researchers and students who uses Matlab for their analysis. This codes can be edited/modify to suit any deterministic models and any desire output required. The SEIR deterministic model was used to give a much insight about the codes. Alternatively, a deterministic SEIR codes written in R software is provided for those who wants to use freely available software. Despite the limitations of the R software, the deterministic model implemented in the R code can still be a useful tool for understanding the basic dynamics of disease transmission.

Comments on this article Comments (0)

Version 2
VERSION 2 PUBLISHED 26 Apr 2023
Comment
Author details Author details
Competing interests
Grant information
Copyright
Download
 
Export To
metrics
Views Downloads
F1000Research - -
PubMed Central
Data from PMC are received and updated monthly.
- -
Citations
CITE
how to cite this article
Okyere S, Ackora-Prah J, Bonyah E and Akwasi Adarkwa S. Numerical Scheme for Compartmental Models: New Matlab Software Codes for Numerical Simulation [version 1; peer review: 2 approved with reservations]. F1000Research 2023, 12:445 (https://doi.org/10.12688/f1000research.130458.1)
NOTE: If applicable, it is important to ensure the information in square brackets after the title is included in all citations of this article.
track
receive updates on this article
Track an article to receive email alerts on any updates to this article.

Open Peer Review

Current Reviewer Status: ?
Key to Reviewer Statuses VIEW
ApprovedThe paper is scientifically sound in its current form and only minor, if any, improvements are suggested
Approved with reservations A number of small changes, sometimes more significant revisions are required to address specific details and improve the papers academic merit.
Not approvedFundamental flaws in the paper seriously undermine the findings and conclusions
Version 1
VERSION 1
PUBLISHED 26 Apr 2023
Views
8
Cite
Reviewer Report 04 Sep 2023
Shewafera Wondimagegnhu Teklu, Department of Mathematics, Debre Berhan University, Debre Birhan, Amhara, Ethiopia 
Approved with Reservations
VIEWS 8
Comments to the Authors

Title: Numerical Scheme for Compartmental Models: New Matlab Software Codes for Numerical Simulation

The authors proposed new Matlab Software Codes for Numerical Simulation and also an alternative codes for statistical ... Continue reading
CITE
CITE
HOW TO CITE THIS REPORT
Teklu SW. Reviewer Report For: Numerical Scheme for Compartmental Models: New Matlab Software Codes for Numerical Simulation [version 1; peer review: 2 approved with reservations]. F1000Research 2023, 12:445 (https://doi.org/10.5256/f1000research.143219.r188924)
NOTE: it is important to ensure the information in square brackets after the title is included in all citations of this article.
Views
6
Cite
Reviewer Report 04 Sep 2023
Belela Samuel Kotola, Department of Mathematics, Oda Bultum University, Asebe Teferi, Oromia, Ethiopia 
Approved with Reservations
VIEWS 6
First and for most I would like to acknowledge the editor for giving me this chance for reviewing the article. Depend up on my back ground knowledge I have reviewed the article as follow.

The researcher has ... Continue reading
CITE
CITE
HOW TO CITE THIS REPORT
Kotola BS. Reviewer Report For: Numerical Scheme for Compartmental Models: New Matlab Software Codes for Numerical Simulation [version 1; peer review: 2 approved with reservations]. F1000Research 2023, 12:445 (https://doi.org/10.5256/f1000research.143219.r200352)
NOTE: it is important to ensure the information in square brackets after the title is included in all citations of this article.

Comments on this article Comments (0)

Version 2
VERSION 2 PUBLISHED 26 Apr 2023
Comment
Alongside their report, reviewers assign a status to the article:
Approved - the paper is scientifically sound in its current form and only minor, if any, improvements are suggested
Approved with reservations - A number of small changes, sometimes more significant revisions are required to address specific details and improve the papers academic merit.
Not approved - fundamental flaws in the paper seriously undermine the findings and conclusions
Sign In
If you've forgotten your password, please enter your email address below and we'll send you instructions on how to reset your password.

The email address should be the one you originally registered with F1000.

Email address not valid, please try again

You registered with F1000 via Google, so we cannot reset your password.

To sign in, please click here.

If you still need help with your Google account password, please click here.

You registered with F1000 via Facebook, so we cannot reset your password.

To sign in, please click here.

If you still need help with your Facebook account password, please click here.

Code not correct, please try again
Email us for further assistance.
Server error, please try again.