2

因此,我一直在研究这段代码一段时间,为人群运行危险模型,而对于我的一个初始参数,它无法弄清楚如何修复它。这是给我带来问题的代码区域。我在 Notebook++ 中编码,在 R 中运行,它在 WinBUGS 中打开以运行它。Hz.Scale 是我正在努力解决的参数,并且出现了错误。

# Define model - Model 02 = hazard
if(detect.fun=="hazard"){
sink(paste(top.dir,model.name,sep="/"))
cat("
model{
    # Priors
    psi ~ dunif(0,1)                # Data augmentation parameter
    #hz.scale ~ dgamma(0.1,0.1)     # Scale parameter for hazard distribution (sigma) #ORIGINAL CODE
    hz.scale ~ dgamma(0,10)     # Scale parameter for hazard distribution (sigma) #change the parameters to test if it really runs
    hz.shape ~ dunif(0.001,1000)    # Shape parameter for hazard distribution (b in green & yellow book)
    lambda ~ dunif(0,20)            # Expectation for cluster size

    # Likelihood
    ## Construct conditional detection probability (log(p[g])) and Pr(x) (pi[g]) for each bin (g)
    for(g in 1:nD){
        # Hazard model:
        cloglog(p[g]) <- hz.scale*log(hz.shape) - hz.scale*log(midpt[g])    # Kery and Royle 2016 page 507
        # Probability of x in each interval
        pi[g] <- delta[g]/B
    }#g

    for(i in 1:(nclus+nz)){
        z[i] ~ dbern(psi)               # Real observation or augmented?
        dclass[i] ~ dcat(pi[])          # population distribution of distance class
        mu[i] <- z[i] * p[dclass[i]]    # p depends on distance class
        y[i] ~ dbern(mu[i])             # Observed or not?
        clsz[i] ~ dpois(lambda)         # Poisson process for cluster size
    }#i

    # Derived quantities
    num.clusters <- sum(z[])    # Number of clusters
    back.lambda <- lambda+1     # Back-transformed lambda (minimum is 1)
    total.pop <- num.clusters*back.lambda


}#model
",fill=TRUE)#cat
sink()

# Inits function and parameters to save
inits <- function(){list(psi=runif(1),z=y,hz.shape=runif(1,40,200),hz.scale=rgamma(1,0.1,0.1),lambda=runif(1,0,10))}
params <- c("hz.scale","hz.shape","num.clusters","back.lambda","total.pop")
}# hazard
# hazard
4

0 回答 0