r - eval(substitute(expr), data, enclos = parent.frame()) 中的错误:找不到对象'a',这个错误意味着什么?
问题描述
我正在使用 deBInfer 包进行贝叶斯推理,但出现错误
eval(substitute(expr), data, enclos = parent.frame()) 中的错误:找不到对象“a”,
为什么即使我没有使用任何名为 a 的变量也会出现此错误?
#SolvingODE
library(deSolve)
sir_model <- function (time, y, parms) {
with(as.list(c(y, parms)), {
ds=-b*s*i
di=b*s*i-a*i
dr=a*i
list(c(ds,di,dr))
})
}
y <- c(s=254,i=7,r=0)
parms <- c(b=0.0178,a=2.73)
times <- seq(0, 5, 0.25)
out <- ode(y, times, sir_model, parms, method="lsoda")
#CalculatingNewInfective
NewInf=matrix(1:21,nrow=21,ncol=1)
for (q in 1:21){
NewInf[
q]=parms[1]*out[q,2]*out[q,3]
}
#loadingData
dat<-read.csv(file.choose(), header=TRUE)
plot(dat$t, dat$NewInf_data, ylim=c(0, max(dat$t,dat$NewInf_data)))
points(dat$t, dat$NewInf_data, col="red")
parms["sdlog.A"]= 0.05
#Likelihood
sir_obs_model = function(data,sim.data, samp){
llik.NewInf <- sum(dlnorm(data$NewInf_data, meanlog = log(sim.data[,"NewInf"] + 1e-6),
sdlog = samp[["sdlog.A"]], log = TRUE))
llik = llik.NewInf
return(llik)
}
#ParameterEstimation
library(deBInfer)
b <- debinfer_par(name = "b", var.type = "de", fixed = FALSE,
value = 0.0178, prior = "norm", hypers = list(mean = 0, sd = 1),
prop.var = 0.0001, samp.type="rw")
sdlog.A <- debinfer_par(name = "sdlog.A", var.type = "obs", fixed = FALSE,
value = 0.05, prior = "lnorm", hypers = list(meanlog = 0, sdlog = 1),
prop.var = c(3,4), samp.type = "rw-unif")
s <- debinfer_par(name = "s", var.type = "init", fixed = TRUE, value = y["s"])
i <- debinfer_par(name = "i", var.type = "init", fixed = TRUE, value = y["i"])
r <- debinfer_par(name = "r", var.type = "init", fixed = TRUE, value = y['r'])
mcmc.pars= setup_debinfer(b, sdlog.A, s, i, r)
#usingMCMC
mcmc_samples <- de_mcmc(N = iter, data = dat, de.model = sir_model,
obs.model = sir_obs_model, all.params = mcmc.pars,
Tmax = max(dat$t), data.times = dat$t, cnt = 500,
plot = FALSE, verbose.mcmc = FALSE, solver = "ode")
plot(mcmc_samples).
解决方案
推荐阅读
- pyspark - Pyspark - Kafka 流的每个数据批次的平均值
- bash - bash:前缀后减去常数
- sass - 如何在 Bootstrap 4 中覆盖 .alert-[style]?
- image - 在包装器中随机放置和调整大小的图像
- python-3.x - 在子进程打开的长进程中获取 pid
- visual-studio - Visual Studio 不突出显示 JavaScript/TypeScript 中的匹配大括号
- angular - 引导表中带有异步数据数组的 Angular2 动画
- html - 使用 PHPMailser 的联系表格不起作用
- php - PHP usort 二维数组不起作用(按整数排序)
- javascript - Angularjs承诺等待结果