Hi,
when i try to fit the model, i run into the following error
Error in new_CppObject_xp(fields$.module, fields$.pointer, …) :
Exception: variable does not exist; processing stage=data initialization; variable name=y; base type=vector_d (in ‘model19fd8e7e221_stan_19fd887c257’ at line 3)
failed to create the sampler; sampling not done
could anyone explain why this occurs?
Many thanks,
CJ
data {
int<lower=0> n;
vector[n] y;
real post_exp;
}
transformed data{
real a;
real<lower=0> b;
a = (1-mean(y))*n;
b=1;
}
parameters {
real mu;
}
model {
mu ~ normal(a, b);
y ~ normal(mu, 1);
}
stimulating data
set.seed(100)
n=100
true_mu = 1
post_exp = rnorm(n=n, mean=true_mu, sd=1)
fitting the model
library(rstan)
options(mc.cores = parallel::detectCores())
data = list(n=n, post_exp=post_exp, a=13, b=1)
fit <- sampling(normal, data=data, chains=4, iter=2000, warmup=1000)