'fixed_param = TRUE' option When Implementing Prior Predictive Checks

Hello,
I’m trying to implement ‘prior predictive checks’. And I got an error message saying this:
“Must use algorithm=“Fixed_param” for model that has no parameters.”

stan_mod3 <- sampling(Prior_Predictive, 
                  data = d3, chains = 4,
                  control = list(max_treedepth = 15,
                                 adapt_delta = 0.8),
                  iter = 4000)

SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 1).
[1] "Error in sampler$call_sampler(args_list[[i]]) : "                      
"  Must use algorithm=\"Fixed_param\" for model that has no parameters."
[1] "error occurred during calling the sampler; sampling not done"


When I added ‘fixed_param = TRUE’ option, I got this error message: 
       "passing unknown arguments: fixed_param."

stan_mod3 <- sampling(Prior_Predictive, 
                  data = d3, chains = 4,
                  control = list(max_treedepth = 15,
                                 adapt_delta = 0.8),
                  iter = 4000,
                  fixed_param = TRUE)

Now I have had the following error message:
Error in checkForRemoteErrors(val) :
4 nodes produced errors; first error: passing unknown arguments: fixed_param.

Here’s Stan codes I used:

data {
  int<lower=1> n_days;            
  real mu_start;                  
  real mu_finish;                 
  int y1_n;                     
  int y2_n;
  int y3_n;
  int y4_n;
  int y5_n;
  real y1_values[y1_n];       
  real y2_values[y2_n];       
  real y3_values[y3_n];       
  real y4_values[y4_n];       
  real y5_values[y5_n];       
  int y1_days[y1_n];          
  int y2_days[y2_n]; 
  int y3_days[y3_n]; 
  int y4_days[y4_n]; 
  int y5_days[y5_n]; 
  real y1_se[y1_n];             
  real y2_se[y2_n];           
  real y3_se[y3_n];           
  real y4_se[y4_n];           
  real y5_se[y5_n]; 
}
generated quantities {
  vector<lower = 0>[n_days] mu; 
  real d[5];
  real<lower = 0> sigma;
  mu[1] = normal_rng(mu_start, 0.01);          
  sigma = normal_rng(0.5, 0.5);                  
  mu[n_days] = normal_rng(mu_finish, 0.01);
  d[5] = normal_rng(0, 7.5);                      
  vector[n_days] y_sim;
    for(i in 1:n_days) {
     for(j in 1:5) {
     y_sim[i] = normal_rng(mu[i] + d[j], sigma);
  }
 }
}

Any help would be appreciated.

The error message said:

Must use algorithm="Fixed_param" for model that has no parameters.

So you should use algorithm = "Fixed_param" in your sampling() call

1 Like

As an alternative:
If you wrote the model with the model block already you can also wrap the likelihood part. I am now assuming the same structure as in your generated quantities

data {
[...]
int <lower=0, upper=1> priorOnly;
}

parameter {
[...]
}

model {
[...]
if(!priorOnly) {
    y_sim[i] = normal(mu[i] + d[j], sigma);
}
[...]
}

generated quantities {
[...]
}

The if statement will bypass the likelihood function and you will just get the output given your priors. This is also how brms is handling it which means you can also run with the same code the posterior checks.

Hello,

Thanks very much for replying. I have replaced ‘fixed_param = TRUE’ with ‘algorithm = Fixed_param.’

But I got the following error message:
Chain 1: Exception: normal_rng: Location parameter is nan, but must be finite! (in ‘string’, line 37, column 5 to column 48)

I think I might have missed something in defining ‘y_sim’ here. I was wondering if you could take a look at my Stan code. Anything you could provide will be the starting point that I get to learn about use of prior predictive checks.

data {
int<lower=1> n_days;
real mu_start;
real mu_finish;
int y1_n;
int y2_n;
int y3_n;
int y4_n;
int y5_n;
real y1_values[y1_n];
real y2_values[y2_n];
real y3_values[y3_n];
real y4_values[y4_n];
real y5_values[y5_n];
int y1_days[y1_n];
int y2_days[y2_n];
int y3_days[y3_n];
int y4_days[y4_n];
int y5_days[y5_n];
real y1_se[y1_n];
real y2_se[y2_n];
real y3_se[y3_n];
real y4_se[y4_n];
real y5_se[y5_n];
}

generated quantities {
vector<lower = 0>[n_days] mu;
real d[5];
real<lower = 0> sigma;
mu[1] = normal_rng(mu_start, 0.01);
sigma = normal_rng(0.5, 0.5);
mu[n_days] = normal_rng(mu_finish, 0.01);
d[5] = normal_rng(0, 7.5);
vector[n_days] y_sim;
for(i in 1:n_days) {
for(j in 1:5) {
y_sim[i] = normal_rng(mu[i] + d[j], sigma);
}
}
}

Many thanks,
Young

Thanks you so much for your input. Due to my limited Stan knowledge and Bayesian analysis, I’ll have to take more time to apply what you suggested. Anyway, I’ll definitely give it a try. Thanks.

Good luck!
BTW.: You can also edit your posts with code blocks by adding ```stan (3 times `) at the beginning and 3 backticks at the end of your code.

1 Like