# Getting unconstrained parameters from stanfit object?

**URL:** <https://discourse.mc-stan.org/t/getting-unconstrained-parameters-from-stanfit-object/6546>\
**Category:** Interfaces\
**Created:** [November 15, 2018, 3:14pm UTC](https://discourse.mc-stan.org/t/getting-unconstrained-parameters-from-stanfit-object/6546 "2018-11-15T15:14:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Charles\_Driver](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/charles_driver/32/6524_2.png) [@Charles\_Driver](https://discourse.mc-stan.org/u/Charles_Driver)\
**Post date:** [November 15, 2018, 3:14pm UTC](https://discourse.mc-stan.org/t/getting-unconstrained-parameters-from-stanfit-object/6546/1 "2018-11-15T15:14:12Z")

</div>

Posting out loud clears the brain, answer is:

```
cmat=as.matrix(fit)
clist=apply(cmat,1,function(x) relist(flesh = x,skeleton = fit@inits[[1]]))
ulist=lapply(clist,function(x) unconstrain_pars(fit,x))

```

Handy for generating quantities separately, with this extra step:

> `ygen = lapply(ulist, function(x) constrain_pars(sfgen,x))`

where sfgen is a stanfit object with the same parameters and data but different generated quantities / other bits.

---

<div class="post-metadata">

**Author:** ![ahartikainen](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/ahartikainen/32/321_2.png) [@ahartikainen](https://discourse.mc-stan.org/u/ahartikainen)\
**Post date:** [November 15, 2018, 3:57pm UTC](https://discourse.mc-stan.org/t/getting-unconstrained-parameters-from-stanfit-object/6546/2 "2018-11-15T15:57:41Z")

</div>

In PyStan you can. Check following test for example

> <https://github.com/stan-dev/pystan/blob/develop/pystan/tests/test_extra_compile_args.py>

But I believe you are interested about RStan

Edit. You answered already :)
