Can someone explain what this code is doing?

Viewed 23

Can someone explain what this code is doing? Like what it's setting or what the functions are doing. It is for an SIR model. Thank you

SIR <- function(time, state, parameters) {
      par <- as.list(c(state, parameters))
      with(par, {
      dS <- -beta/N * I * S
      dI <- beta/N * I * S - gamma * I
      dR <- gamma * I
     list(c(dS, dI, dR))
})
}
1 Answers

with function in R Documentation described in the following: Evaluate an R expression in an environment constructed from data, possibly modifying (a copy of) the original data. So,I think this function concatenate 'state' and 'parameters' into a vector and use as.list convert it to a list(par).The next operation is to operate on the par converted into a list.Then,the three variables of dS,dI,dR are established,But unfortunately, since I don't have the original data, I can't tell if it's an environment variable in the calculation or a column in par. Also,time is not used anywhere in the function, so I think your function may be incomplete

Related