mardi 28 juillet 2020

How can I condition the parameter values in an ODE function? (deSolve, if-else)

I'm trying to create values conditioned for some parameters given the initial values of states. For example, if D state is D >= 60, the S value will be S=1800. Otherwise, if D state is D <60 the S value will be S=4800. I used function if-else into the ode function (AedesIbag_model). When I run ode with D=70 if-else doesn't switch S parameter value. So I have not achieved to do that this works well. I apologize if my English is not very good. Thank you for any help.

AedesIbag_model<-function(t, state, parameters) {
  with(as.list(c(state, parameters)), {
    dL = R*theta*S - mu_L*L - gamma_L*L - mu_w*L  
    dP = gamma_L*L - mu_P*P  - gamma_P*P - mu_w*P   
    dA = gamma_P*P - mu_A*A 
    dD = beta - alpha*D 
    if (D >= 60) { 
      S = 1800
      } else if (D < 60) {
        S = 4800
        } else if (D >= 10) {
          mu_w = 0.1
          } else if (D < 60) {
            mu_w = 0.1*100
          }
    
    return(list(c(dL, dP, dA, dD)))
  })
}

parameters  <- list(R = 0.24, theta = 10, S = 0,
                gamma_L = 0.2088, gamma_P = 0.384,
                beta = 10, mu_L = 0.0105, mu_P = 0.01041,
                mu_A = 0.091, mu_w = 0.1, alpha = 10
                )
state      <- c(L = 100, P = 60, A = 10, D = 70)
times       <- seq(0, 100, by = 0.1)

out_1 <- ode(y = state, times = times, func = AedesIbag_model, parms = parameters)
parameters

when I run my model. the parameters conditioned don't change the values. Look!!!

> parameters
$R
[1] 0.24

$theta
[1] 10

$S
[1] 0   #S value doesn't change

$gamma_L
[1] 0.2088

$gamma_P
[1] 0.384

$beta
[1] 10

$mu_L
[1] 0.0105

$mu_P
[1] 0.01041

$mu_A
[1] 0.091

$mu_w
[1] 0        #S value doesn't change

$alpha
[1] 10

I apologize if my English is not very good. Thank you for any help.

Aucun commentaire:

Enregistrer un commentaire