# Transformed parameters with target +=

**URL:** <https://discourse.mc-stan.org/t/transformed-parameters-with-target/7256>\
**Category:** Modeling\
**Tags:** techniques\
**Created:** [January 11, 2019, 10:31am UTC](https://discourse.mc-stan.org/t/transformed-parameters-with-target/7256 "2019-01-11T10:31:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tpapp](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/tpapp/32/1240_2.png) [@tpapp](https://discourse.mc-stan.org/u/tpapp)\
**Post date:** [January 11, 2019, 10:31am UTC](https://discourse.mc-stan.org/t/transformed-parameters-with-target/7256/1 "2019-01-11T10:31:32Z")

</div>

I am fitting a model where, conceptually, the following is happening: a parameter `A` needs to be transformed to `B` via a transformation that is _data-dependent_. I only care about `B`, and the transformation is a necessity to avoid rejecting parameter values (unconstrained `B` makes no sense in my application).

The transformation involves vectors, and is somewhat complex (about 20 lines of Stan code). It also needs to be done about 1500 times, and I would like to record the `b`s. Finally, of course it involves a _Jacobian correction, which is the part of the problem._

Ideally, I would encode it in the `transformed parameters` block, which would make sure the `b`s are recorded. But I get

```julia
Sampling statements (~) and increment_log_prob() are
only allowed in the model block or lp functions.

```

However, if I encode in in a function with an `_lp` name, it compiles.

I am asking to check that the `target +=` statement is executed in a function called in the `transformed parameters` block.

Cf [#889](https://github.com/stan-dev/stan/issues/889) which is about this, but was closed (without resolution).

---

<div class="post-metadata">

**Author:** ![Matthijs](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/matthijs/32/718_2.png) [@Matthijs](https://discourse.mc-stan.org/u/Matthijs)\
**Post date:** [January 11, 2019, 11:58am UTC](https://discourse.mc-stan.org/t/transformed-parameters-with-target/7256/2 "2019-01-11T11:58:36Z")

</div>

It should be executed. I believe the `_lp` functions were originally included precisely for this use-case.

This also relates the following issue: [https://github.com/stan-dev/stan/issues/2662](https://github.com/stan-dev/stan/issues/2662) . I am unsure whether the distinction between the transformed parameters and model blocks is a useful one in the first place.
