The SIR model is a simple mathematical model used to describe how infectious diseases spread in a population.

NiladriKarmakar7 6 views 4 slides Oct 24, 2025
Slide 1
Slide 1 of 4
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4

About This Presentation

sir model


Slide Content

Problem Description
•Susceptible, Infected Recovered (SIR) model of Corona virus (Covid-19) of real data of
Singapore, rate of infection (β) and rate of recovery (γ) and analyse the SIR dynamics.
(Data of Zika virus was not available)
Methodology
The SIR model consists of three compartments: susceptible (S), infected (I), and recovered (R).
The changes are described by the following differential equations:
(N=S+I+R is the total population)
S0 =N−I0 −R0 : Initial susceptible population.
During the early stages of the outbreak, when I is small compared to I, the term -γI can be
negligible, and the infected population can grow approximately exponentially.
Solving the differential equations over a specified time interval. Iterating through variable
Parameters different combinations of β and γ values, simulating the dynamics for each
combination.
Computed the logarithm of the infected individuals I to analyse the growth rate with time, fitting a
linear regression model to the log of infected individuals over time to determine the slope which
represents the growth rate of the infected population, which shows how changes in β and γ affect
the epidemic dynamics. Plotting the number of infected individuals over time for each parameter
combination and plots of the log of infected individuals with regression lines to visualise the
growth rates. After running simulations and analysing the results by the slope of the log of
infected population.
Results and Discussion

Fig: Confirmed, Recovered, Infected and deaths of whole dataset
Fig: Exponential fit for the confirmed covid 19 cases
Fig: Number of Infected population

Fig: Log of Infected population (Black line depicts first 50 days)
Results and Discussion
Gamma was 1/14 days (recovery rate of covid-19)
For the first 50 days beta (rate of infection) was coming out to be 0.189.
During the initial phase of an outbreak, the infected population tends to grow exponentially, as
indicated by a positive slope in the log of the infected graph.
Taking the natural logarithm of the infected population I allows us to linearise the growth phase:
log(I)≈log(I0)+rt
where r is the growth rate (the slope of the line in the log plot), and I0 is the initial number of
infected individuals.
The slope of the log-infected graph directly reflects the transmission rate β. Higher β values lead
to steeper slopes, indicating faster growth of infections resulting in a steeper slope in the log of
infected individuals.
Increasing γ (recovery rate) results in a decrease in the number of infected individuals over time,
flattening the curve and decreasing the slope. A higher recovery rate means infected individuals
are removed from the infectious pool more quickly, reducing the overall number of active
infections at any given time.
Reference:
Susceptible, Infected Recovered (SIR) model of Covid-19 in Singapore in Python
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
data=pd.read_excel("Covid-19 SG.xlsx")  # Covid-19 data of Singapore (1020 days)
new_data=data[["Date","Daily Confirmed","Cumulative Confirmed","Daily
Discharged","Cumulative Discharged","Daily Deaths","Cumulative Deaths"]]
new_data_cleaned=new_data.dropna()      # Removing the rows with null values (710 days left)

sg_data['Infected'] = sg_data['Confirmed']-sg_data['Recovered']-sg_data['Deaths']  # Adding
Infected data to the dataframe
sg_data['Date']=pd.to_datetime(sg_data['Date'])
# Plotting Confirmed,Deaths,Recovered and Infected '#
plt.figure(figsize=(12,7))
ax = plt.gca()
sg_data.plot(x ='Date', y='Confirmed', color='blue', kind = 'line',ax=ax)
sg_data.plot(x ='Date', y='Deaths', color='red', kind = 'line',ax=ax)
sg_data.plot(x ='Date', y='Recovered', color='green', kind = 'line',ax=ax)
sg_data.plot(x ='Date', y='Infected', color='black', kind = 'line',ax=ax)
plt.legend(['confirmed', 'deaths','recovered','infected'], loc='upper left')
plt.rcParams['figure.facecolor'] = 'xkcd:white'
dict_style_title = {'fontsize':20,'fontweight' : 'bold','color' : 'black','verticalalignment': 'baseline'}
plt.title('Singapore', fontdict = dict_style_title)
plt.show()
# Fitting graph for the confirmed cases
from scipy.optimize import curve_fit
import datetime as dt
def exp_func(x, a, b, c):
    return a * np.exp(-b * x) + c
#   return a * np.log(b * x) + c
x = sg_data[['Date']]
x = np.array(x['Date'].map(dt.datetime.toordinal), dtype=float) #transform your data in a numpy
array of floats
x_scale = x - x[0]
y = sg_data[['Confirmed']]
y = np.array(y['Confirmed'], dtype=float) #so the curve_fit can work
popt, pcov = curve_fit(exp_func, x_scale, y, p0= (0,0,0))
plt.figure(figsize=(15, 5))
plt.subplot()
plt.plot(x_scale, y, 'ko', label="Original Confirmed Cases")
plt.plot(x_scale, exp_func(x_scale, *popt), 'r-', label="Fitted Curve")
plt.legend()
plt.title('Actual Trend of Confirmed Cases')
plt.show()
#Caclulating beta for early cases (first 50)
first_fifty = np.arange(0, 50)
log_infected_early = np.log(early_infected)
coeffs = np.polyfit(t[early_phase], lxog_infected_early, 1)
t = np.arange(1, len(data))
plt.figure()
plt.plot(t, np.log(infected), 'b', linewidth=1)
plt.plot(t[early_phase], log_infected_early, 'black', linewidth=2, linestyle='-')
plt.xlabel('Time (days)')
plt.ylabel('log(I)')
plt.xlim([0, 500])
plt.ylim([0, 15])
slope = coeffs[0]
n = N / S[0]
beta_estimated = n * (slope + 0.07)