eval(替代(expr),数据,enclos = parent.frame())中的错误:找不到对象“ a”,此错误表示什么?

时间:2019-06-06 16:59:26

标签: r

我正在使用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).

0 个答案:

没有答案