STAN Priors not working as expected

I am trying to fix priors for my dataset, however any change I make, does not reflect in the output samples. To make sure priors are working as expected, I have reduced the number of samples to minimum to reduce effect from data.

Say I use the model as:

parameters {
    real<upper=0.9999> alpha[C];
    real<lower=0> k[C];
}
model {
    alpha ~ normal(-0.5,0.4);
    k ~ normal(7.5,0.5);
}

# samples_fitted = self.model.sample(num_chains=4, num_samples=2000, num_warmup=500)
samples_fitted = self.model.sample(num_chains=4, num_samples=1, num_warmup=1)
df_fit = samples_fitted.to_frame()

and take 4 samples, parameters look like this: (I draw 4 samples and take the mean)

  • k.1 2.66
  • k.2 2.24
  • k.3 1.75
  • k.4 0.82
  • alpha.1 0.59
  • alpha.2 0.60
  • alpha.3 0.57
  • alpha.4 0.60

Say now I update the model as:

model {
    alpha ~ normal(0.5,0.4);
    k ~ normal(0.2,0.1);
} 

the samples are now:

  • k.1 1.41
  • k.2 2.35
  • k.3 0.69
  • k.4 1.64
  • alpha.1 0.51
  • alpha.2 0.65
  • alpha.3 0.49
  • alpha.4 0.34

which are about similar to before and make me wonder if the prior is having any effect.

Any clarity on this would be really helpful!

Thank you!

The priors probably have an impact but not if you just look at the first iteration. For the first iteration Stan starts from the initialization which is by default uniform between -2 and 2 on the transformed scale. In your case, you want to give Stan enough time in warm-up to find the typical set and then look at the samples after warmup.

1 Like

@stijn Thank you for sharing! I have been debugging with wrong understanding.

1 Like