使用 Jags 的多元贝叶斯建模 -Rjags

时间:2021-04-26 16:49:53

标签: r hierarchical-data bayesian jags rjags

The error obtained is shown here in this image and as well written below

> model<-jags.model(file=textConnection(model1), data=df,inits =inits)
Compiling model graph
   Resolving undeclared variables
Deleting model

Error in jags.model(file = textConnection(model1), data = df, inits = inits) : 
  RUNTIME ERROR:
Compilation error on line 4.
Cannot evaluate subset expression for mean_0

我分析的整个代码是

library(rjags)
library(coda)
library(matrixStats)
library(tidyverse)
library(cowplot)
library(forecast)

data1<-data[order(nrow(data):1),]
prices<-data1[,c(5,7,9,11)]
y<-data1[,c(6,8,10,12)]


model1 <-  "model  {
  for ( i  in 100 : n )  {
      p[i,] ~ dmnorm(mean_0[], Sigma_0[1:4,1:4])
      mean_0[]<-lambda_hat[,] %*% t(y[i,])+c((p[(i-1),1]),(p[(i-1),2])
       ,(p[(i-1),3]),(p[(i-1),4]))
      
  }
  lambda_hat~dwish(mat[1:4,1:4], 4)
  Sigma_0~dwish(mat[1:4,1:4],4)
  for (j in 1:4){ for (k in 1:4){  mat[j,k] <-equals(j,k)*.1 } }

}"
params <-  c("lambda_hat")
inits <-  list("lambda_hat" = diag(1,1,1,1),"Sigma_0"=var(prices[1:100,]),"mat"=diag(1,1,1,1))
df<-list(p=prices,y=y,n=(dim(y)[1]-99))

model<-jags.model(file=textConnection(model1), data=df,inits =inits)
update(mod, 10000, progress.bar = "none")

我在运行此特定行时遇到错误。

model<-jags.model(file=textConnection(model1), data=df,inits =inits)

你能帮我吗?

0 个答案:

没有答案