# What does the vars argument actually do in the Metropolis sampler

**URL:** https://discourse.pymc.io/t/what-does-the-vars-argument-actually-do-in-the-metropolis-sampler/2107
**Category:** Questions
**Created:** [October 27, 2018, 2:50am UTC](https://discourse.pymc.io/t/what-does-the-vars-argument-actually-do-in-the-metropolis-sampler/2107 "2018-10-27T02:50:57Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![RavinKumar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ravinkumar/32/958_2.png) [@RavinKumar](https://discourse.pymc.io/u/RavinKumar)
#### Post date: [October 27, 2018, 2:50am UTC](https://discourse.pymc.io/t/what-does-the-vars-argument-actually-do-in-the-metropolis-sampler/2107/1 "2018-10-27T02:50:57Z")

</div>

The documentation says

> - **vars** ( _list_ ) – List of variables for sampler

but is the intended effect when sampling? Or more bluntly put what’s the point of the argument and what’s it used for?

[https://docs.pymc.io/api/inference.html#module-pymc3.step\_methods.metropolis](https://docs.pymc.io/api/inference.html#module-pymc3.step_methods.metropolis)

P.S. I’m going for a really screwy inference run on purpose 🙂

**Example**  
[https://github.com/arviz-devs/arviz\_resources/blob/experiment/plots/WhatDoesVarsDo.ipynb](https://github.com/arviz-devs/arviz_resources/blob/experiment/plots/WhatDoesVarsDo.ipynb)

---

<div class="post-metadata">

### Author: ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)
#### Post date: [October 27, 2018, 3:27pm UTC](https://discourse.pymc.io/t/what-does-the-vars-argument-actually-do-in-the-metropolis-sampler/2107/2 "2018-10-27T15:27:58Z")

</div>

That’s for specifying the variable you want the sampler to sample. After you initialize a model, you can do `model.free_vars` which gives you a list of free parameters in your model. And then you can specify different sampler to sample different vars. For example see: [https://docs.pymc.io/notebooks/sampling\_compound\_step.html](https://docs.pymc.io/notebooks/sampling_compound_step.html)

---

<div class="post-metadata">

### Author: ![RavinKumar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ravinkumar/32/958_2.png) [@RavinKumar](https://discourse.pymc.io/u/RavinKumar)
#### Post date: [October 27, 2018, 10:44pm UTC](https://discourse.pymc.io/t/what-does-the-vars-argument-actually-do-in-the-metropolis-sampler/2107/3 "2018-10-27T22:44:07Z")

</div>

Thanks jungpenlao,

In the notebook then I specified `vars=(mu,)` but the sample seems to still be sampling the distribution of `sd`? My understanding is that pymc3 would only be sampling for value of mu but It looks like I’m mistaken

---

<div class="post-metadata">

### Author: ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)
#### Post date: [October 28, 2018, 1:52am UTC](https://discourse.pymc.io/t/what-does-the-vars-argument-actually-do-in-the-metropolis-sampler/2107/4 "2018-10-28T01:52:09Z")

</div>

usually we passed `vars=[mu]` to it (not sure if it makes any differences tho)

---

<div class="post-metadata">

### Author: ![RavinKumar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ravinkumar/32/958_2.png) [@RavinKumar](https://discourse.pymc.io/u/RavinKumar)
#### Post date: [October 28, 2018, 2:23am UTC](https://discourse.pymc.io/t/what-does-the-vars-argument-actually-do-in-the-metropolis-sampler/2107/5 "2018-10-28T02:23:20Z")

</div>

Made the change but still confused. Also read the doc you sent but too dense to figure out what it means in reference to my confusion ☹

With `vars` specified still looks like ‘sd’ is still sampled. If I understand correctly only `mu` should be sampled? Or does the step argument in my case mean that ‘mu’ is sampled first?

Below is the graph from the notebook where I’m seeing 2 chains for both `mu` and `sd` leading to my confusion

Thank you for the help

 ![39%20PM](https://canada1.discourse-cdn.com/flex036/uploads/pymc3/original/2X/4/4ec2ded640e9ce8cbc68e3bbcfdd9513111a715e.png)

---

<div class="post-metadata">

### Author: ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)
#### Post date: [October 28, 2018, 2:59pm UTC](https://discourse.pymc.io/t/what-does-the-vars-argument-actually-do-in-the-metropolis-sampler/2107/6 "2018-10-28T14:59:23Z")

</div>

Oh I see your confusion, all free parameters will be sampled or approximated, the var arg is to specify which sampler (eg metropolis) sample what (eg mu), otherwise it will be assigned automatically.

---

<div class="post-metadata">

### Author: ![RavinKumar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ravinkumar/32/958_2.png) [@RavinKumar](https://discourse.pymc.io/u/RavinKumar)
#### Post date: [October 28, 2018, 3:06pm UTC](https://discourse.pymc.io/t/what-does-the-vars-argument-actually-do-in-the-metropolis-sampler/2107/7 "2018-10-28T15:06:21Z")

</div>

Ah ok that makes sense, So in this cause I could have `mu` sampled by MetropolisHastings and `sd` sampled by NUTS, for example

---

<div class="post-metadata">

### Author: ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)
#### Post date: [October 28, 2018, 3:18pm UTC](https://discourse.pymc.io/t/what-does-the-vars-argument-actually-do-in-the-metropolis-sampler/2107/8 "2018-10-28T15:18:38Z")

</div>

Exactly.

---

<div class="post-metadata">

### Author: ![RavinKumar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ravinkumar/32/958_2.png) [@RavinKumar](https://discourse.pymc.io/u/RavinKumar)
#### Post date: [October 28, 2018, 6:29pm UTC](https://discourse.pymc.io/t/what-does-the-vars-argument-actually-do-in-the-metropolis-sampler/2107/9 "2018-10-28T18:29:05Z")

</div>

Thank you!
