May I ask how to fix a parameter value in Stan without modifying stan file?

So suppose in a stan file there are 4 parameters to sample: a,b,c,d

But I want to see what happen to the other three pars when I fix a = 0.

I googled that and got to know we can set the prior for a ~ N(0,0.001).

But is there any way to fix the parameter ‘a’ without changing the stan file itself?

Thanks in advance!

This should work:

data{
  int which_fixed ;
  real fixed_value ;
  … // other data
}
parameters{
  vector[4] abcd ;
  … // other parameters 
}
model {
  abcd[1] ~ … // prior for a
  abcd[2] ~ … // prior for b
  … // c & d priors too
  vector[4] abcd_with_fixed = abcd ;
  abcd_with_fixed[ which_fixed ] = fixed_value ;
  … // other model structure 
}
…

You’ll still get samples for the fixed parameter that represent samples from the prior, but everything else will reflect a posterior conditional on that parameter being fixed at the supplied value.

1 Like