R Code

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

# Parameters (gamma, beta, R0)

gamma <- 0.0455331


beta <- 0.0561215
R0 <- 1.23254

# Initial conditions
N <- 43851044 # Total population
I <- 837555 # Initial infected individuals
R <- 0 # Initial recovered individuals
S <- N - I - R # Initial susceptible individuals
T <- 0 # Initial treated individuals

# Treatment-specific parameters
treatment_rate <- 0.1 # Rate at which infected individuals initiate
treatment
recovery_rate_treated <- 0.08 # Faster recovery rate for treated
individuals
infectiousness_reduction <- 0.5 # Reduction in infectiousness for
treated individuals

# Simulation time
days <- 561

# Containers for storing compartment values over time


S_values <- numeric(days)
I_values <- numeric(days)
R_values <- numeric(days)
T_values <- numeric(days)

# Model simulation
for (day in 1:days) {
# Model equations
dS <- -beta * S * I / N
dI <- beta * S * I / N - gamma * I
dR <- gamma * I
dT <- treatment_rate * I - recovery_rate_treated * T

# Update compartments
S <- S + dS
I <- I + dI
R <- R + dR
T <- T + dT

# Adjust for reduced infectiousness in treated individuals


dI <- dI * (1 - infectiousness_reduction)

# Store compartment values for plotting


S_values[day] <- S
I_values[day] <- I
R_values[day] <- R
T_values[day] <- T
}

# Display values after 561 days


cat("Susceptible after 561 days:", S, "\n")
cat("Infected after 561 days:", I, "\n")
cat("Recovered after 561 days:", R, "\n")
cat("Treated after 561 days:", T, "\n")

# Plotting the compartments over time


time <- 1:days
matplot(time, cbind(S_values, I_values, R_values, T_values), type =
"l",
xlab = "Time (days)", ylab = "Population",
col = c("blue", "red", "green", "purple"),
lty = 1, lwd = 2,
main = "SIR Model with Treatment Dynamics")
legend("topright", legend = c("Susceptible", "Infected",
"Recovered", "Treated"),
col = c("blue", "red", "green", "purple"), lty = 1, lwd = 2)

You might also like