File Exchange

image thumbnail

fitVirusCV19v3 (COVID-19 SIR Model)

version 3.2.4 (2.96 MB) by Joshua McGee
Estimation of coronavirus COVID-19 epidemic evaluation by the SIR model, Code receives and plots most recent data from HDX.

810 Downloads

Updated 03 Apr 2020

View License

This code will retrieve recent data from the HDX and attempt to fit it to a SIR model using structure created by Milan Batista (https://www.mathworks.com/matlabcentral/fileexchange/74658-fitviruscovid19?s_tid=prof_contriblnk). The model is data-driven, so its forecast is as good as data are. Also, it is assumed that the model is a reasonable description of the one-stage epidemic.

Results are saved in structure res (see function fiVirusCV19 header). Optionally the results may be printed by:

fitVirusCV19v3(“Italy",'prn','on')

The plot may be enabled or disabled via (default is on):
fitVirusCV19v3(“Italy",'plt','off')

A more detailed description can be found in:
https://www.researchgate.net/publication/339311383_Estimation_of_the_final_size_of_the_coronavirus_epidemic_by_the_SIR_model
Examples can be found in:
https://www.researchgate.net/publication/339912313_Forecasting_of_final_COVID-19_epidemic_size_200318

Cite As

Joshua McGee (2020). fitVirusCV19v3 (COVID-19 SIR Model) (https://www.mathworks.com/matlabcentral/fileexchange/74676-fitviruscv19v3-covid-19-sir-model), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (46)

Hi, Mr. Joshua! I succes run the it, but failed ( error ) to get some plot such as United Arab Emirates, Guam, New Caledonia.
On the otherhands the results for Turkey and Russia is good but the date axis for Turkey in case/day graph is unusual, the fit result of Russia show the large number of C_end.
Would you mind to explain these factors?
I am begging you.
Best regards!

vitto66

I am sorry, I just saw a similar question put on 30 march without reply

Roy CHEN

Hi, Mr. Joshua! It's very impresive work you done here!
I am from Hongkong( born in Taiwan). If I may ask, could you make update for my country Hongkong and Taiwan, please?
Your work will help us.
And please give the update for the exmaples (maybe) every week? ( If you can't )
Thank you very much for your kindness!

Thank you very much, Mr. Joshua McGee for updating my country Japan and the others!
Sorry to asking you a basic question. How can I install this model source?P.S. I used to use Python for my analytic.
I try to use it to see the other countries such as Russia, Vietnam, Turkey.
If you can tell me or update it for me, it would be great.
Thank you very much again! GBU

dong gretch

please give link of latest version

Joshua McGee

Hi Riel,
Thanks for reporting this bug. It should be fixed now. Please download the latest version.
Josh

Riel Aljama

Good morning Joshua,
I was able to run the your code now.
but I am having problem with some country, particularly Philippines

fitVirusCV19v3('Philippines','prn','on')
Fail to obtain parameters.
ini: beta = 0.682172 gamma = 0.454782 N = 8016.47 I0 = 0.00515606
calc: beta = 0.0543995 gamma = -0.219728 N = 25201.8 I0 = 0.000941286
Unrecognized function or variable 'plt'.

Error in fitVirusCV19v3>plotData (line 781)
if plt

Error in fitVirusCV19v3 (line 294)
plotData(C,date0,country)

Joshua McGee

Done!

Hi Mr Joshua McGee!
Thank you very much for all of these.
Could you do me a favor to add example case in Japan, my country?
Also if it is not trouble you, could you add Singapore and Australia too ?
Thank you very much. GBU

Joshua McGee

Hi Clarke! Thanks for your kind words. I'll work on incorporating per capita testing into my next iteration of the model.
Josh

Hi Joshua, thank you very much for all this work. I'm wondering if you think increasing per capita COVID-19 testing rates here in the US (compared to other nations) will affect your total infected forecast?

Joshua McGee

Hi Marco, this code requires 2019b or greater.

Marco

Hi Joshua, this seems great. I am trying to run it but I get an error ... It seems like detectImportOptions is missing, so I am a bit stuck.
I am running on R2016a so it may be a bit dated.
Thanks for any tip
Marco

>> fitVirusCV19v3("Italy")
'lambertw' requires Symbolic Math Toolbox.

Error in fitVirusCV19v3>calcEndPoint (line 628)
lambertw(-beta*(1 - c0)*exp(-beta/gamma)/gamma);

Error in fitVirusCV19v3>calcClim (line 601)
res = calcEndPoint(beta,gamma,I0/N)*N;

Error in fitVirusCV19v3 (line 306)
Clim = calcClim(b);

Unfortunately, I don't have access to Symbolic Math Toolbox, and it's not listed as required to run the code. Any thoughts or suggestions?

Joshua McGee

added Indonesia to examples

Joshua McGee

Will do Anton.

Anton Yess

Hi Joshua,
Would you mind making on examples tab for Indonesia? Thx.

Error using fitVirusCV19v3 (line 152)
Table variable names must be character vectors.
I'm using 2018 version of MATLAB..

Joshua McGee

-updated, attempted again to fix compatibility issues with older MATLAB versions

Joshua McGee

Will do. I’ll update later today.

St Se

Could you update the 'examples' graphs every couple of days maybe? Several countries approach the tipping point soon. Thanks

Joshua McGee

I’ll look into this.

on R2019b there is the following error:

at = fitVirusCV19v3("Austria");
Error using odearguments (line 21)
When the first argument to ode45 is a function handle, the tspan argument must have at least two elements.

Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);

Error in fitVirusCV19v3 (line 327)
[t,Ca] = ode45(@(t,y) odeFun(t,y,b), tspan, I0);

Thanks
Giovanni B.

Joshua McGee

It is fully functional for 2019b and up.

Joshua McGee

Yes this is a compatibility issue. I’m working on a workaround.

Hi! Cool model.
I keep geting:

Error using fitVirusCV19v3 (line 149)
'01_22_20' is not a valid variable name.

Error in run (line 1)
it = fitVirusCV19v3("Italy");

Any suggestions?

Joshua McGee

Hi Tosaporn, I’m working on a fix that will accommodate most MATLAB users. This is compatible with 2019b and up.

Hi Joshua,
I tried the code, it showed Error , Can you please explain?
at = fitVirusCV19v3("Austria");
Error using fitVirusCV19v3 (line 152)
'01_22_20' is not a valid table variable name.
See the documentation for isvarname or
matlab.lang.makeValidName for more information.

Joshua McGee

Hi Giuseppe,
The database was probably experiencing too much traffic at the time. Wait a little while and try again.
Josh

Leon Burger

Hi, these are my results on R2019a; any work around. Want to run scenario for South Africa, but using Italty as a test case.

Error using readContentFromWebService (line 46)
The server returned the status 403 with message "FORBIDDEN" in response to the request to URL
https://proxy.hxlstandard.org/api/data-preview.csv?url=https%3A%2F%2Fraw.githubusercontent.com%2FCSSEGISandData%2FCOVID-19%2Fmaster%2Fcsse_covid_19_data%2Fcsse_covid_19_time_series%2Ftime_series_19-covid-Confirmed.csv&filename=time_series_2019-ncov-Confirmed.csv&options=table.

Error in webread (line 125)
[varargout{1:nargout}] = readContentFromWebService(connection, options);

Error in fitVirusCV19v3 (line 124)
result=webread('https://proxy.hxlstandard.org/api/data-preview.csv?url=https%3A%2F%2Fraw.githubusercontent.com%2FCSSEGISandData%2FCOVID-19%2Fmaster%2Fcsse_covid_19_data%2Fcsse_covid_19_time_series%2Ftime_series_19-covid-Confirmed.csv&filename=time_series_2019-ncov-Confirmed.csv','options','table');

Joshua McGee

Hi Riel,
Thanks for your patience. Please try again now. I converted the variable name dates to datenum format.
Josh

Riel Aljama

Hi, these are the result

Error using fitVirusCV19v3 (line 148)
'22-Jan-2020' is not a valid variable name.

Joshua McGee

Hi please try again now.

Riel Aljama

Good Day!
I keep on getting this error :( (using 2018a)

Error using fitVirusCV19v3 (line 148)
'Province/State' is not a valid variable name.

Joshua McGee

All compatibility issues should now be fixed

Joshua McGee

This is a compatibility issue. What version are you running?

any ideas on why I would get this error:

Unrecognized property 'PreserveVariableNames' for class
'matlab.io.text.DelimitedTextImportOptions'.

Error in fitVirusCV19v3 (line 128)
opts.PreserveVariableNames = true;

St Se

Very nice to see the graphs being updated.

St Se

Suksan,
I had the same problem. Matlab 2019.b with mex installed.

excellent work, but when I run the code it gives me this error:
Unrecognized property 'PreserveVariableNames' for class
'matlab.io.text.DelimitedTextImportOptions'.
Error in fitVirusCV19v3 (line 132)
opts.PreserveVariableNames = true;

buldus2

excellent work, but when I run the code it gives me this error: Error using fitVirusCV19v3 (line 170)
Duplicate table variable name: 'NaN'.

any suggestion?

Updates

3.2.4

-improved initial parameter approximation (courtesy of Milan Batista)

3.2.3

-updated examples

3.2.2

-updated with data from 4/2

3.2.1

-image

3.2

-updated 4/1

3.1.9

-bug fixes

3.1.8

-updated 3/31 8:40 PM EST

3.1.7

-updated aesthetics of examples

3.1.6

-updated examples

3.1.5

-updated plots for today (3/30)

3.1.4

-bug fix

3.1.3

-updated examples

3.1.2

-image

3.1.1

-compatibility notes

3.1

-updated examples

3.0

-updated plots and fixed small bug

2.9

-added death rate to example

2.8

-updated examples

2.7

-added ability to disable plot and created a live script to tabulate the R0 values of each country

2.6

-added Indonesia

2.5

-bug fixes and compatibility

2.3

-compatibility

2.2

-attempted to fix additional variable name Compatability issues

2.1

-compatibility

2.0.9

-fixed all compatibility issues

2.0.8

-bug fixes

2.0.7

-image

2.0.6

-description

2.0.5

-updated date ticks

2.0.4

-new data source (updated database)

2.0.3

-description

2.0.2

-updated compatibility

2.0.1

-updated description

2.0

-applied updates courtesy of Milan Batista (RMSE correction, automatic parameter selection)

1.0.4

-name change

1.0.3

-added tags

1.0.2

-fixed live script

1.0.1

-added live script to generate plots

MATLAB Release Compatibility
Created with R2019b
Compatible with R2019b to any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: fitVirusCOVID19