Two-Host SI model and varying parameters in R

Issue

This Content is from Stack Overflow. Question asked by Sprawk48

I’m currently working on a two-host epidemiological SI model. That is, a compartmental model with no recovery compartment.

I’m still relatively new to R, but am developing a decent understanding after mostly using MATLAB. However, the thing I am having issues with finding any helpful resources on is how to vary two different input parameters so I can examine them and maybe even 3-D plot these variables or phase plot them to see if the population dies off.

So, more specifically I want to produce results when varying mu between 0 and 1, and alpha between 0 and 1, I could just “plug and play” but I want to be able to show a more dynamic result and think it would be handy to have as a tool in my wheel-house.

Anyway, here is the code I have so far:

# Here we will load the required packages for the assignment
library(deSolve) 
library(ggplot2)

# Here we  the two-host (male & female) SI model

KModel <- function(time, state, params){
  
  with(as.list(c(state, params)),{
    N <- SF+IF+SM+IM
    dSF <- r*(SF+alpha*IF)-r*N*SF-BFM*(SF*IM)/N
    dIF <- (BFM*(SF*IM)/N)-r*N*IF-mu*IF
    dSM <- r*(SF+alpha*IF)-r*N*SM-BMF*(SM*IF)/N
    dIM <- (BMF*(SM*IF)/N)-r*N*IM-mu*IM
    
    return(list(c(dSF, dIF, dSM, dIM)))
  })
}
# here are the initial parameters

r = 0.2
BFM = 1.2
BMF = 1
mu = 0
alpha = 0

params<-c(r,BFM,BMF,mu,alpha)

initial_state<-c(SF=0.49 ,IF=0.01, SM=0.49,IM=0.01)

times<-0:60
# Here we use ode() to numerically solve the system
out1<-ode(y=initial_state, times=times, func=KModel, parms=params, method="ode23")
out<-as.data.frame(out1)
plot(out1)

So, I think I have a pretty good “skeleton” for solving any single solution for a compartmental model, however Like I mentioned I’d like to be able to vary two of the parameters to examine specific scenarios.

Thanks!



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?