为什么rstan无法识别我的变量?

时间:2020-02-24 14:21:19

标签: r rstan

我在Windows 10上使用R 3.6.2。我最近安装了rstan(这本身就很麻烦)。

Rstan似乎不认识我声明了一个变量。

我的斯坦斯坦密码:

data {
  int N;
  real Y[N];
}

parameters {
  real mu;
  real<lower=0> sigma;
}

model {
  for(i in 1:N)
   Y[i] ~ normal(mu, sigma);
  mu ~ normal(1.7,0.3);
  sigma ~ cauchy(0,1);
}

我的r代码:

#generate scenario data
N=as.integer(100)
set.seed(21)
Y=rnorm(N,1.6,0.2)
hist(Y)

# compile the model
library(rstan)
options(mc.cores=4) #set the number of CPU cores to be used for MC processing

model=stan_model("first_model.stan")

# move the data to stan and run the model
fit=sampling(model,list(N-N,Y-Y),iter=200,chains=1)

我的r代码产生错误: “ new_CppObject_xp(fields $ .module,fields $ .pointer,...)中的错误: 例外:变量不存在;处理阶段=数据初始化;变量名称= N;基本type = int(在第2行的'model336c6f43555f_first_model'中)

无法创建采样器;采样未完成”

有人知道这是为什么吗,或者如何解决此问题?如果我无法解决该练习问题,那么我什至无法在星期二开始我的作业。 :(

0 个答案:

没有答案