问题是用变化的变量模拟方程。所有变量都是固定的,期望使用小写s和Treat_date。这是错误消息:
Error in checkFunc(Func2, times, y, rho) : The number of derivatives
returned by func() (202) must equal the length of the initial
conditions vector (2)
我曾尝试过四处走动,但老实说我不知道自己在做什么
seasonal_SI <- function (t, y, parameters) {
S <- y[1]
I <- y[2]
with(as.list(parameters), {
julian_date <- t %% 365
v <- ifelse(julian_date >= treat_date &
julian_date < (treat_date + 10) &
treatment, 0.9, v)
beta <- beta0 + s*beta0*sin(2*pi*(julian_date)/365)
dSdt <- b*(1-c*(S+I))*(S+rho*I)-d*S-beta*S*I
dIdt <- beta*S*I-(d+v)*I
res <- c(dSdt, dIdt)
list(res)
})
}
initials <- c(S=99, I=1)
params <- c(b=.5, c=.01, beta0=5e-3, v=.05, rho=.3, treatment=TRUE,
s=as.numeric(seq(from=0, to=1, by=.01)),
treat_date=as.numeric(seq(from=0, to=355, length.out=101)))
t <- 0:1
library("deSolve")
lsoda(y=initials, times=t, parms=params, func=seasonal_SI)
我希望它运行并返回图形。
答案 0 :(得分:0)
我同意前面的评论,您可以考虑使用参数列表。但是,您也可以考虑使用强制函数或事件机制。
您可以在deSolve中找到帮助页面:
?强制 ?事件
和此处的简短教程:https://tpetzoldt.github.io/deSolve-forcing/deSolve-forcing.html