我想估计 13 个组的树冠覆盖的中位数以及 5、25、75 和 95 个百分位数(记录为 20 个中有或没有植被的点数)和总共 223 个样本。我之前发布了这个假设是 beta 分布,但这是不正确的。这是一份过期的手稿,这是遗失的最后一篇。如果有人可以帮助我完成(直到代码工作),我将不胜感激。我想我已经接近了,它只需要一些调整——我想。
(我进行了编辑以修复两个反对票,但我不确定有什么不清楚的地方)。
非常感谢!
下面是我的模型声明,R 代码和数据。照原样,我得到的错误是
model(model.file, data = data, inits = init.values, n.chains = n.chains, :
RUNTIME ERROR:
Compilation error on line 16.
Subset out of range: re[14]
但请注意,我删除了下面的空格,错误是指可能性陈述。
model{
# priors
for (i in 1:13){
alpha[i] ~ dunif(0, 1)
re[i] ~ dnorm(0, 0.001)
}
#likelihood
for (i in 1:223) {
canopy[i] ~ dbin(p[i], 20)
logit(p[i]) <- alpha[site[i]] + re[i]
}
median <- 1/(1+exp(alpha[site[i]]))
t4est1_100 <- step(median[1]-median[4])
t5est1_10 <- step(median[3]-median[4])
t6est10_100 <- step(median[2]-median[3])
}
R代码:
cover <- read.csv("f:\\brazil\\canopy2.csv", header=T)
library(R2jags)
library(rjags)
setwd("f://brazil")
site <- frag$site
canopy <- frag$canopy*20
N <- length(frag$site)
jags.data <- list("site", "canopy")
jags.params <- c("median", "test100MF","test100MT","test100fc","test100fa",
"test100gv","test100hm","test100mc", "test100ca","test100ct", "test10MF",
"test10MT", "test10fc","test10fa", "test10gv", "test10hm", "test10mc", "test10ca",
"test10ct", "test1MF", "test1MT", "test1fc", "test1fa", "test1gv", "test1hm",
"test1mc", "test1ca", "test1ct", "t1est1_con","t2est10_con","t3est100_con",
"t4est1_100","t5est1_10","t6est10_100")
#inits1 <- list(a=0, sd=0)
#inits2 <- list(a=100, sd=50)
#jags.inits <- list(inits1, inits2)
jags.inits <- function() {
list(alpha = 0, re=0)}
jagsfit2 <- jags(data=jags.data, inits=jags.inits, jags.params,
n.iter=1000000, n.burnin=20000, model.file="fragmodelbinom.txt")
my.coda <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), class = "data.frame",
row.names = c(NA, -227L))