I’m trying to write a function to generate data. This is my model:
and this is my stan code:
functions {
matrix parc_rng(int S, vector pre_test) {
int N = cols(pre_test);
matrix[S, N] out; // holds prior predictive draws
for (s in 1:S) {
real mu ;
vector[N] a_std;
real<lower=0> sigma_a;
real<lower=0> gamma;
real<lower=0> sigma;
vector[N] a_std;
vector[N] a;
vector[N] theta;
mu = normal_rng(700,75);
sigma_a = normal_rng(0,100)
gamma = normal_rng(0.5,1);
sigma = gamma_rng(2,8);
for(n in 1:N){
a_std[n] = normal_rng(0,1);
a[n] = mu + sigma_a * a_std[n];
theta[n] = a[n] + gamma*pre_test[n];
out[s, n] = normal_rng(theta[n], sigma)
}
return out;
}
}
This is the error that I get when I try to expose the function to R:
library(rstan)
expose_stan_functions('parcc_rng.stan')
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
require unconstrained. found range constraint.
error in 'model_parcc_rng' at line 8, column 28
-------------------------------------------------
6: real mu ;
7: vector[N] a_std;
8: real<lower=0> sigma_a;
^
9: real<lower=0> gamma;
-------------------------------------------------
Error in stanc(file = stanmodel, allow_undefined = TRUE, obfuscate_model_name = FALSE) :
failed to parse Stan model 'parcc_rng' due to the above error.
If I’m understanding this correctly the problem is that I’m setting a lower bound for some of my parameters. Is that correct? If so, how can I fix my problem?
Thanks!