0

i implemented the SIR model with Python, and the result seems correct:

import scipy.integrate
import numpy
import matplotlib.pyplot as plt

def SIR_model(y,t,N,beta,gamma):
    S,I,R=y
    dS_dt=-beta*S*I/N
    dI_dt=beta*S*I/N-gamma*I
    dR_dt=gamma*I
    return([dS_dt,dI_dt,dR_dt])

N=1000
I0=1
R0=0.0
S0=N-I0-R0
beta=0.2
gamma=0.1

t=numpy.linspace(0,160,160)

sol=scipy.integrate.odeint(SIR_model,[S0,I0,R0],t,args=(N, beta,gamma))
sol=numpy.array(sol)

plt.figure(figsize=[6,4])
plt.plot(t,sol[:,0],label="S(t)")
plt.plot(t,sol[:,1],label="I(t)")
plt.plot(t,sol[:,2],label="R(t)")
plt.grid()
plt.legend()
plt.xlabel("Time")
plt.ylabel("Number")
plt.title("SIR model")
plt.show()

Now i want to fit real data with the model ( https://github.com/pcm-dpc/COVID-19 ). I know N0, S0, I0, R0, and i need to find the best values for beta and gamma. In my previous projects i fitted data on well defined functions (i knew the analytical expression), but now i don't know how to do that with the results of the integrated system. I usually use the Numpy curve_fit function:

popt, pcov = curve_fit(f, x_list, y_list, sigma=y_err)

What is the best approach to do this? There was a nice project on github few days ago, but now the author deleted it.

alcor
  • 515
  • 1
  • 8
  • 21
  • The COVID-19 data are not data for an infectious disease but for some kind of genetic condition that was traced like an infection. Thus you will get very poor fits. Also, even if it was a virus infection, you need to very carefully examine what `I` actually means, that is, people in the infectious phase, which to the most part are asymptomatic and thus not counted in any statistic. The onset of disease symptoms, if any, which is traced in the best (back-dated) case statistics, is caused by secondary bacterial infections which happens when the body starts to fight the initial viral infection. – Lutz Lehmann Jun 10 '20 at 09:24
  • See http://adventuresinpython.blogspot.com/2012/08/fitting-differential-equation-system-to.html for a completed fitting example for ODE solutions. This code is not the most simple solution for this problem, especially the reconstruction of the sample values. – Lutz Lehmann Jun 10 '20 at 10:19
  • See also on this site https://stackoverflow.com/q/34422410/3088138, https://stackoverflow.com/q/53767265/3088138, https://stackoverflow.com/q/16223283/3088138. – Lutz Lehmann Jun 10 '20 at 10:29

0 Answers0