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

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