0
votes

I'm using the FME package to fit a prey-predator model to my data. At the moment I'm just learning and testing the code without fitting anything yet, following this example: http://strimas.com/r/lotka-volterra/

When executing the global sensitivity analyses I get an error and I can't figure out where it comes from.

When I copy paste the example above in my R session, it works. But I can't get my own code to work. I wrote my function based on another document on FME so the syntax is slightly different.

# model function
RMmodel <- function(t, y, parms) {

  #y <- c(N = 30, P = 3)

  derivs <- function(t, y, parms) {
    with(as.list(c(y, parms)), {

      dN <- r * N * (1 - N/K) - a * N * P / (1 + a*h*N)
      dP <- e * a * N * P / (1 + a*h*N) - m * P

      return(list(c(dN, dP)))
    })
  }
  return(ode(y = y, times = t, parms = parms, func = derivs))
}

# input
parameters <- c(r = 0.4, # growth rate prey
                K = 2200, # carrying capacity prey
                a = 0.14, # search rate predator
                h = 1, # handling time
                e = 1.2, # assimilation efficiency predator
                m = 0.2) # mortality rate predator
init <- c(N = 30, P = 3)
times <- seq(0, 120, by=1)

# calculate ODE
RM_result <- RMmodel(t = times, y = init, parms = parameters) # this works

# global sensitivity
par_ranges <- data.frame(min = c(0.18, 1500, 0.01, 0.01, 0.01, 0.01),
                         max = c(0.25, 3500, 2, 2, 2, 2),
                         row.names = c("r", "K", "a", "h", "e", "m"))

RM_glob_sens <- sensRange(func = RMmodel, parms = parameters,
                          dist = "grid",
                          sensvar = c("N", "P"), parRange = par_ranges,
                          num = 20, t = times)

When I run the above code I get the following error:

Error in ode(y = y, times = t, parms = parms, func = derivs) : 
  argument "parms" is missing, with no default 

I tried the following things: adjusted the argument name in the model to "pars" instead of "parms"; added the initial state within the model function; changed the object name of "parameters" to "pars"; changed the order within sensRange(); put the parameters directly in sensRange through c(a = , ...).

I am clearly missing someting but I can't find it for the life of me. Anyone a suggestion?

1

1 Answers

0
votes

A requirement of sensRange() is that the first argument of func is parms (see documentation). Change the order of the input arguments in RMmodel and derivs so that parms is the first argument and your code will work.