我想基于估计的复制数( R0 )来估计攻击率( AR )(被感染的人口比例)(次要病例数)在感染期间由易感人群中的单个感染者产生的。)
S = exp(-R0(1-S)), S 流行病后烧伤的剩余易感人群比例。
并假设感染后终身免疫, AR = 1-S。
我在MonthYear,city的.csv表中有 R0 ,并希望为每个MonthYear / city计算 AR 。
我试过了:
library(rootSolve)
f<- function(y,x){Tab$AR=1-(y-exp(-x*(1-y)))}
x=Tab$R0
solve(f)
错误讯息:
Error in as.vector(x, mode) :
cannot coerce type 'closure' to vector of type 'any'
然后我试了
R0.vec = Tab$R0
AR.vec = numeric(length(R0.vec))
for(ii in 1:length(AR.vec)){
AR.vec[ii] = 1 -optimize(f=function(S){(S-exp(-R0.vec[ii]*(1-S)))},interval=c(0,1))$minimum
}
AR.fun.vec = approxfun(R0.vec,AR.vec)
错误讯息:
There were 50 or more warnings (use warnings() to see the first 50)
Warning messages:
1: In optimize(f = function(S) { ... : NA/Inf replaced by maximum positive value
2: In optimize(f = function(S) { ... : NA/Inf replaced by maximum positive value
3: In optimize(f = function(S) { ... : NA/Inf replaced by maximum positive value
我希望得到关于此的任何建议来获取我的 ARs ,因为这对我来说都是新的。 提前谢谢!
答案 0 :(得分:0)
ANSWER感谢Karline Soetaert博士 `
Sfun <- function(x, R0) return(x - exp(-R0*(1-x)))
require(rootSolve)
R0vec <- R0
result <- rep(0,times=length(R0vec))
for (i in 1:length(R0vec))
result[i] <- multiroot(f = Sfun, start = 0, positive = TRUE, R0 =
R0vec[i])$root
AR <- 1-result
Print(AR)`