File Exchange

image thumbnail

COVID-19 Modeling

version 3.4.2 (4.06 MB) by Joshua McGee
This model was created based off of fitVirus. This is a data-driven model that obtains up to date data and predicts the spread of COVID-19.

571 Downloads

Updated 03 Apr 2020

View License

Created to track the simulate the spread of Coronavirus (COVID-19). Case data is obtained over the web and fitted to a logistic model to predict epidemic spread over time.

To operate load the folder containing the script COVID19Modelingv2 and type the following code in the command prompt: COVID19Modelingv2("country").
example: COVID19Modelingv2("US"). Multiple countries can be analyzed at the same time by placing them in a list: COVID19Modelingv2("US","Italy").

The model was created by Milan Batista (fitVirus). The model is a data-driven model that fits epidemic data to a logistic curve. The goal of the model is to make local predictions about the viral spread and epidemic duration. The model can be used to provide accurate approximations in certain situations. "The regression convergence may fail for a pure initial guess or small data set. Therefore the method does not apply to the early stages of an epidemic. Also, results are useless if the regression statistic does not meet minimum criteria, say R^2 > 0.8, p-value < 0.05." (Milan Batista)

DISCLAIMER: Model will fail in certain situations. A rigorous statistical analysis should be performed on all results. The model fails when additional epidemic stages (not described by logistic function) are encountered. Use at your own discretion.

See for more info: https://www.researchgate.net/publication/339912313_Forecasting_of_final_COVID-19_epidemic_size_200320

Data is stored online and is provided via JHU CSSE from various sources including:
"The World Health Organization (WHO), DXY.cn. Pneumonia. 2020, BNO News,
National Health Commission of the People? Republic of China (NHC),
China CDC (CCDC), Hong Kong Department of Health, Macau Government, Taiwan CDC, US CDC, Government of Canada, Australia Government Department of Health, European Centre for Disease Prevention and Control (ECDC) and Ministry of Health Singapore (MOH)"

On the figure, the epidemic rate is plotted with a blue line (cases/day). Blue dots are the actual infection rate (cases/day). Region colors separate epidemic transition phases:
red - fast growth phase
yellow - transition to steady-state phase
green - ending phase

Cite As

Joshua McGee (2020). COVID-19 Modeling (https://www.mathworks.com/matlabcentral/fileexchange/74632-covid-19-modeling), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (27)

Error using livemapcovid19 (line 46)
Table variable names must be character vectors.
(MATLAB2018a)

Joshua McGee

updated

Matthew

requires optimization toolbox that is not currently stated in submission.

Ted Hanes

Here is a source for state-level data: https://covidtracking.com/data/

Joshua McGee

The original data still exists but it is no longer being updated.

Joshua McGee

Hi Kirtis,
The original data set was discontinued by the source. See "https://data.humdata.org/dataset/novel-coronavirus-2019-ncov-cases".
Unfortunately, there is nothing I can do about this. I did not originally intend for this model to provide state-level modelling. I'll let you know if I find a new data source.
Josh

I don't see the United States broken out in the input file on the web path that feeds the result variable. A prior version had a source path for result that had data for US and each state broken out. That was needed for assisting in regional planning.
when I run this version I get the following error -> Too many output arguments.
Can we get those source data by state restored to the excel file in the input path? And a confirmation that the other are seeing the same error that I am?

Excellent work. Runs great. Thanks for the hard work.

Joshua McGee

Fixed all compatibility issues (hopefully)

Ralf Elsas

Joshua McGee

Hi Suksan. This is a compatibility issue that I am still trying to resolve. The code runs fine on my version (2019b).

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;

Joshua McGee

Hi Morgan,

I'm running 2019b with no issues. There must be a compatibility issue with the importing of the data. I'll work on a more robust method.

Josh

Receiving this error, using version R2020a.

Error using COVID19Modelingv2 (line 62)
Duplicate table variable name: 'NaN'.

Joshua McGee

Hi Tsotne. I've heard from other users that this is a compatibility issue. The easiest fix would be to upgrade your MATLAB to 2019b or newer.

"Starting in R2019b, variable names and row names can include any characters, including spaces and non-ASCII characters. Also, they can start with any characters, not just letters. Variable and row names do not have to be valid MATLAB identifiers (as determined by the isvarname function). To preserve these variable names and row names, set PreserveVariableNames to true."

Thank you very much for your work. I have this particular error

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

Error in COVID19Modelingv2 (line 24)
opts.PreserveVariableNames = true;

What should I do?

Hey, everybody, I tried to see which part of the document is empty. I can't find it, could you help me? I keep getting the message:
Error using matlab.io.text.TextImportOptions/set.DataLine (line 73)
DataLine must be a positive integer.

Error in COVID19Modelingv2 (line 23)
opts.DataLine = [2,inf];

I'm using R2017b

Thanks!

Joshua McGee

Thanks Kirtis. I’ll try and reach out to the people that maintain the dataset. It’s very dynamic so hopefully it’ll be updated soon.

Hey everyone. This was working fine but it has stopped. Be advised that the update to the deaths file that this model depends upon failed for column 3/21. If someone has access to fix that column this will start working gain. Otherwise the workaround follows. Pull the files to your local folder and use readtable instead of
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-Deaths.csv&filename=time_series_2019-ncov-Deaths.csv

If you fix the empty data in 3/21 for deaths.csv on your local folder and us the following line things will work gain until the online files are fixed.
%Use local data because online data seems broke at the moment
result=readtable('time_series_2019-ncov-Confirmed.csv');
deathresult = readtable('time_series_2019-ncov-Deaths.csv');

ilPlus30 I got the same error. I believe it is some version compatibility problems. I was able to run the script for my country by making some changes to the code. For that specific problem, the solution was to change the code opts.DataLines = [2,inf]; to opts.DataLine = [2,inf]; because there is no DataLines variable in opts.

Joshua McGee

Hi iiPlus30. This is a most likely a compatibility issue with your version of MATLAB. Other users and I have not encountered this error. What version are you running?

ilPlus30

No public property DataLines exists for class matlab.io.text.DelimitedTextImportOptions.

Error in COVID19Modelingv2 (line 23)
opts.DataLines = [2,inf];

Joshua McGee

Is this working correctly for everyone?

Updates

3.4.2

-updated data

3.4.1

-image

3.4

-updated 4/1

3.3

-fixed graphs on the example tab

3.2

updated 3/31

3.1

-fixed plots in example tab

3.0

-updated

2.9

-added more examples

2.8

-updated examples

2.7

-made script executable as a function
-added examples

2.6

-bug fixes and improvements

2.5

-optimization notes

2.4.9

-bug fix

2.4.8

-image

2.4.7

-compatibility

2.4.6

-bug fixes and compatibility

2.4.5

-description

2.4.4

-name

2.4.3

-compatibility

2.4.2

-attempted to fix variable name compatibility issues

2.4.1

-name

2.4

-compatibility fixes

2.3.9

-fixed all compatibility issues

2.3.8

-bug fixes

2.3.7

-fixed predict() function courtesy of Milan Batista

2.3.6

-updated to reflect changes in database

2.3.5

-compatibility note

2.3.4

-updated compatibility

2.3.3

-added graph to visualize stability of total infected estimate (courtesy of Milan Batista)

2.3.2

-ability to run multiple country simulations simultaneously

2.3.1

-version #

2.2.212.1

-name

2.1

-description

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

Inspired by: fitVirus

Inspired: Coronavirus Tracker - Country Modeling