The following is my code script:
library(ggplot2)
library(deSolve)
model <- function(times, state, parameters) {
dS <- parameters["r_max"] * (1 - state["S"]/parameters["K"]) *
state["S"] - parameters["c"] * state["S"]
return(list(c(dS))) }
parameters <- c(r_max = 0.5, K = 200, c = 0.2)
init_state <- c(S = 1)
solution <- ode(y= init_state, times = times, func = model, parms = parameters)
ggplot(as.data.frame(solution), aes(x = time, y = S)) + xlab("t") +
ylab("S(t)") + geom_line(size = 1.1)
Everything works fine except I get the following message when I try to run:
Error in checkInput(y, times, func, rtol, atol, jacfunc, tcrit, hmin, :
object 'times' not found
How might I fix this?