# How to set priors for fixed parameters in Stan?

**URL:** <https://discourse.mc-stan.org/t/how-to-set-priors-for-fixed-parameters-in-stan/22436>\
**Category:** Modeling\
**Created:** [May 12, 2021, 5:14am UTC](https://discourse.mc-stan.org/t/how-to-set-priors-for-fixed-parameters-in-stan/22436 "2021-05-12T05:14:57Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![diyinhaitang](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@diyinhaitang](https://discourse.mc-stan.org/u/diyinhaitang)\
**Post date:** [May 12, 2021, 5:14am UTC](https://discourse.mc-stan.org/t/how-to-set-priors-for-fixed-parameters-in-stan/22436/1 "2021-05-12T05:14:57Z")

</div>

Recently, I’ve been working on estimating mixed logit model. However, as a parameter the intercepts are fixed.

1. I’m wondering how to set the priors for fixed parameters?
2. Also, if fixed parameters are set priors, the estimated posterior for the fixed parameters follow a distribution. In this aspect, what is the difference between fixed parameters and random coefficients, since both of them have posteriors that follow some distributions?

---

<div class="post-metadata">

**Author:** ![stemangiola](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/stemangiola/32/260_2.png) [@stemangiola](https://discourse.mc-stan.org/u/stemangiola)\
**Post date:** [May 12, 2021, 8:24am UTC](https://discourse.mc-stan.org/t/how-to-set-priors-for-fixed-parameters-in-stan/22436/2 "2021-05-12T08:24:31Z")

</div>

Hello,

parameters cannot be fixed by definition, and they would not need priors anyway. Can you make an example?

---

<div class="post-metadata">

**Author:** ![diyinhaitang](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@diyinhaitang](https://discourse.mc-stan.org/u/diyinhaitang)\
**Post date:** [May 12, 2021, 12:43pm UTC](https://discourse.mc-stan.org/t/how-to-set-priors-for-fixed-parameters-in-stan/22436/3 "2021-05-12T12:43:31Z")

</div>

For example, assume that the model is y=\beta\_0+\beta\_1 x\_1+\beta\_2 x2+\varepsilon. The intercept \beta\_0 is assumed to be a fixed parameter, but the parameters \beta\_1 and \beta\_2 are assumed as random coefficients. In this case, how to set priors for \beta\_0?

If the prior for \beta\_0 is assumed to follow normal distribution with a large variance, is the estimated posterior mean of \beta\_0 regarded as the point estimate of \beta\_0 ?

My biggest concern is that in Bayesian methods there are no fixed parameters because all parameters to be estimated have posteriors. In this case, how can we interpret and estimate fixed parameters?

---

<div class="post-metadata">

**Author:** ![caesoma](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/caesoma/32/19767_2.png) [@caesoma](https://discourse.mc-stan.org/u/caesoma)\
**Post date:** [May 12, 2021, 1:52pm UTC](https://discourse.mc-stan.org/t/how-to-set-priors-for-fixed-parameters-in-stan/22436/4 "2021-05-12T13:52:21Z")

</div>

If a model parameter (I’m going to call if _coefficient_ in this context to avoid confusion with the Stan block definitions) is fixed putting a prior on it will not change the results (the prior probability p(\beta\_0) will be constant whatever the values of the other coefficients since \beta\_0 is constant), so it serves no actual purpose.

As @stemangiola mentioned, from a Stan perspective it is not possible to fix a variable in the `parameter` block, because by definition parameters listed there are allowed to change in value. If you want to use a fixed coefficient you can load it into the `data` block in Stan, and there’s no need to specify a prior for that.

---

<div class="post-metadata">

**Author:** ![hhau](https://avatars.discourse-cdn.com/v4/letter/h/2bfe46/32.png) [@hhau](https://discourse.mc-stan.org/u/hhau)\
**Post date:** [May 12, 2021, 2:00pm UTC](https://discourse.mc-stan.org/t/how-to-set-priors-for-fixed-parameters-in-stan/22436/5 "2021-05-12T14:00:20Z")

</div>

I think ‘fixed’ here is being used in according to definition (1) in [Why I don’t use the term “fixed and random effects” | Statistical Modeling, Causal Inference, and Social Science](https://statmodeling.stat.columbia.edu/2005/01/25/why_i_dont_use/).

> [@diyinhaitang](#):
>
> In this aspect, what is the difference between fixed parameters and random coefficients, since both of them have posteriors that follow some distributions?

There is no difference.

> [@diyinhaitang](#):
>
> My biggest concern is that in Bayesian methods there are no fixed parameters because all parameters to be estimated have posteriors. In this case, how can we interpret and estimate fixed parameters?

This is akin to the fact that the MLE of the intercept term in a frequentist mixed-model has a sampling distribution associated with it.

---

<div class="post-metadata">

**Author:** ![diyinhaitang](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@diyinhaitang](https://discourse.mc-stan.org/u/diyinhaitang)\
**Post date:** [May 12, 2021, 2:04pm UTC](https://discourse.mc-stan.org/t/how-to-set-priors-for-fixed-parameters-in-stan/22436/6 "2021-05-12T14:04:36Z")

</div>

The book, “Discrete Choice Methods with Simulation”, 2nd ed., by Kenneth E. Train, says something about estimating fixed coefficients using bayesian methods. See page 308, section 12.7.3, “Fixed coefficients for some variables”. It set priors for fixed variables.

Also, if we set the prior for a fixed coefficient as a constant (a value between 0 and 1), we implicitly assume that the prior is a uniform probability density.

---

<div class="post-metadata">

**Author:** ![caesoma](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/caesoma/32/19767_2.png) [@caesoma](https://discourse.mc-stan.org/u/caesoma)\
**Post date:** [May 12, 2021, 2:08pm UTC](https://discourse.mc-stan.org/t/how-to-set-priors-for-fixed-parameters-in-stan/22436/7 "2021-05-12T14:08:26Z")

</div>

I think you need to clarify to us what you mean by fixed effects. If you mean what @hhau described, which distinguishes “fixed” and “random” effects, or if you actually mean a coefficient that is fixed, as seemed to be the case from your model description, and as we initially understood.

I am not familiar with that book, so I’m not sure what is the context or their exact description, but I’m sure you’ll be able to clarify this point to us.

---

<div class="post-metadata">

**Author:** ![diyinhaitang](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@diyinhaitang](https://discourse.mc-stan.org/u/diyinhaitang)\
**Post date:** [May 12, 2021, 2:16pm UTC](https://discourse.mc-stan.org/t/how-to-set-priors-for-fixed-parameters-in-stan/22436/8 "2021-05-12T14:16:06Z")

</div>

Assume that we are the God, and we create a model with true values of all coefficients known to us. We know that the value of one of the coefficients is fixed, \beta\_0. In this case, we generate fake data using the model. And then we estimate the coefficients using the generated data to see if the coefficients estimates are close enough to their true values, which we know.

That is, the true value of \beta\_0 is fixed, which is set by us. How can we estimate it using Stan? How to treat this fixed coefficient?

What I mean is the coefficient is fixed in its true value, which we create it and we should know.

---

<div class="post-metadata">

**Author:** ![diyinhaitang](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@diyinhaitang](https://discourse.mc-stan.org/u/diyinhaitang)\
**Post date:** [May 12, 2021, 2:18pm UTC](https://discourse.mc-stan.org/t/how-to-set-priors-for-fixed-parameters-in-stan/22436/9 "2021-05-12T14:18:07Z")

</div>

I’ll take a look at the book you recommended, thank you for giving me this information!

---

<div class="post-metadata">

**Author:** ![caesoma](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/caesoma/32/19767_2.png) [@caesoma](https://discourse.mc-stan.org/u/caesoma)\
**Post date:** [May 12, 2021, 2:40pm UTC](https://discourse.mc-stan.org/t/how-to-set-priors-for-fixed-parameters-in-stan/22436/10 "2021-05-12T14:40:30Z")

</div>

> [@diyinhaitang](#):
>
> We know that the value of one of the coefficients is fixed, \beta\_0

Ok, I understand what you are saying (although you don’t really need “the God” to do this, 10 lines of Python should do it). And from what I understand it’s neither of the options from all of our replies, but a more philosophical question that comes up often when you are doing bayesian statistics.

The short answer is: in bayesian inference, we never worry about what the “one true value” of the parameter really is because what you will get is a distribution (the posterior), and that’s a good thing.  
You can always compute a point estimate from it (the mean, median, or MAP estimate) that is more similar to that of frequentist approaches, that throw out the rest of the information available from the posterior.

However, it is important not to mistake point estimates for certainty, and especially “truth”. Whether bayesian or frequentist they are an approximation, and even in a simulation setting where the true value is known there is never guarantee that the inference method will recover that true value – that is true even with an exact method like least squares, because even if all assumptions hold the noise is random.

---

<div class="post-metadata">

**Author:** ![diyinhaitang](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@diyinhaitang](https://discourse.mc-stan.org/u/diyinhaitang)\
**Post date:** [May 12, 2021, 2:50pm UTC](https://discourse.mc-stan.org/t/how-to-set-priors-for-fixed-parameters-in-stan/22436/11 "2021-05-12T14:50:18Z")

</div>

Thanks for your explanation. Now it’s clear to me that even if the true value of a coefficient is a constant, we can still set a vague prior for it and estimate its posterior, from which we can obtain its point estimate if we like. Thanks!

---

<div class="post-metadata">

**Author:** ![caesoma](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/caesoma/32/19767_2.png) [@caesoma](https://discourse.mc-stan.org/u/caesoma)\
**Post date:** [May 12, 2021, 2:54pm UTC](https://discourse.mc-stan.org/t/how-to-set-priors-for-fixed-parameters-in-stan/22436/12 "2021-05-12T14:54:56Z")

</div>

That’s right. In the best case scenario – if your model is well posed and the data is very informative – you will start with a vague prior and the posterior will be very precise around the “true” value.
