我正在尝试使用相机捕获站的栖息地协变量来模拟整体物种丰富度的变化R2jags
。但是,我不断收到错误消息:
"Error in jags.model(model.file, data = data, inits = init.values, n.chains = n.chains, :
RUNTIME ERROR:
Non-conforming parameters in function inprod"
我在之前的 JAGS 模型中使用了一个非常相似的函数(来查找物种丰富度),所以我不确定为什么它现在不起作用......
我已经尝试以不同的方式将 inprod 函数中的协变量格式化为数据框和矩阵,但无济于事。
变量规格:
J=length(ustations) #number of camera stations
NSite=Global.Model$BUGSoutput$sims.list$Nsite
NS=apply(NSite,2,function(x)c(mean(x)))
###What I think is causing the problem:
COV <- data.frame(as.numeric(station.cov$NDVI), as.numeric(station.cov$TRI), as.numeric(station.cov$dist2edge), as.numeric(station.cov$dogs), as.numeric(station.cov$Leopard_captures))
###but I have also tried:
COV <- cbind(station.cov$NDVI, station.cov$TRI, station.cov$dist2edge, station.cov$dogs, station.cov$Leopard_captures)
JAGS 型号:
sink("Variance_model.txt")
cat("model {
# Priors
Y ~ dnorm(0,0.001) #Mean richness
X ~ dnorm(0,0.001) #Mean variance
for (a in 1:length(COV)){
U[a] ~ dnorm(0,0.001)} #Variance covariates
# Likelihood
for (i in 1:J) {
mu[i] <- Y #Hyper-parameter for station-specific all richness
NS[i] ~ dnorm(mu[i], tau[i]) #Likelihood
tau[i] <- (1/sigma2[i])
log(sigma2[i]) <- X + inprod(U,COV[i,])
}
}
", fill=TRUE)
sink()
var.data <- list(NS = NS,
COV = COV,
J=J)
捆绑数据:
# Inits function
var.inits <- function(){list(
Y =rnorm(1),
X =rnorm(1),
U =rnorm(length(COV)))}
# Parameters to estimate
var.params <- c("Y","X","U")
# MCMC settings
nc <- 3
ni <-20000
nb <- 10000
nthin <- 10
启动 Gibbs 采样器:
jags(data=var.data,
inits=var.inits,
parameters.to.save=var.params,
model.file="Variance_model.txt",
n.chains=nc,n.iter=ni,n.burnin=nb,n.thin=nthin)
最终,我得到了错误:
Compiling model graph
Resolving undeclared variables
Allocating nodes
Deleting model
Error in jags.model(model.file, data = data, inits = init.values, n.chains = n.chains, :
RUNTIME ERROR:
Non-conforming parameters in function inprod
最后,我想计算栖息地协变量的平均值和 95% 可信区间 (BCI) 估计值,这些估计值被假设为影响特定站点(点级)物种丰富度的方差。
任何帮助将不胜感激!