0

I tried to estimate the SEIR MODEL parameter in R by using the following code .Unfortunately I couldn't get it because I get the following error :

"Error in names(parameters) <- c("beta_value", "gamma_value", "delta_value") : 'names' [3] has to be of the same length of the vector [2] .

Where am I wrong? The code used follow here.

R CODE :


seir_model = function (current_timepoint, state_values, parameters)
{
  # create state variables (local variables)
  S = state_values [1]        # susceptibles
  E = state_values [2]        # exposed
  I = state_values [3]        # infectious
  R = state_values [4]        # recovered
  
  with ( 
    as.list (parameters),     # variable names within parameters can be used 
    {
      # compute derivatives
      dS = (-beta_value * S * I)
      dE = (beta_value * S * I) - (delta_value * E)
      dI = (delta_value * E) - (gamma_value * I)
      dR = (gamma_value * I)
      
      # combine results
      results = c (dS, dE, dI, dR)
      list (results)
    }
  )
}



RSS <- function(parameters) {
  names(parameters) <- c("beta_value", "gamma_value","delta_value")
  out <- ode(y = init, times = Day, func = seir_model, parms = parameters)
  fit <- out[, 3]
  sum((Infected - fit)^2)
}


library(deSolve)
Opt_seir <- optim(c(0.5, 0.5),
             RSS,
             method = "L-BFGS-B",
             lower = c(0, 0),
             upper = c(1, 1)
Opt_seir
```
kjetil b halvorsen
  • 63,378
  • 26
  • 142
  • 467

1 Answers1

1

This line in the RSS function requires that parameters is of length 3.

names(parameters) <- c("beta_value", "gamma_value","delta_value")

But in your optimization

optim(c(0.5, 0.5),

you are giving only a vector of length 2 as starting point.

Sextus Empiricus
  • 43,080
  • 1
  • 72
  • 161