# Fixing parameter values in the transformed parameters block

**URL:** <https://discourse.mc-stan.org/t/fixing-parameter-values-in-the-transformed-parameters-block/13638>\
**Category:** Modeling\
**Created:** [March 10, 2020, 3:58pm UTC](https://discourse.mc-stan.org/t/fixing-parameter-values-in-the-transformed-parameters-block/13638 "2020-03-10T15:58:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![taromakino](https://avatars.discourse-cdn.com/v4/letter/t/ecc23a/32.png) [@taromakino](https://discourse.mc-stan.org/u/taromakino)\
**Post date:** [March 10, 2020, 3:58pm UTC](https://discourse.mc-stan.org/t/fixing-parameter-values-in-the-transformed-parameters-block/13638/1 "2020-03-10T15:58:39Z")

</div>

Suppose I have three parameter vectors A, B and C. I would like to know whether it is equivalent to (1) have A be length N - 1, or (2) define A\_ and set A[1] = 0 in the transformed parameters block (code shown below). The latter has the advantage of simplifying my code, but I’ve tried both approaches and am getting different results. Am I correct to expect the results to be the same?

Option (1)

```stan
parameters {
    real A[N - 1];
    real B[N];
    real C[N];
}
model {
    for (n in 1:N) {
        if (n == 1) {
            X[n] ~ normal(B[n] + C[n], 1);
        }
        else {
            X[n] ~ normal(A[n - 1] + B[n] + C[n], 1);
        }
    }
}

```

Option (2)

```stan
parameters {
    real A_[N];
    real B[N];
    real C[N];
}
transformed parameters {
    real A[N] = A_;
    A[1] = 0;
}
model {
    X ~ normal(A + B + C, 1)
}

```

---

<div class="post-metadata">

**Author:** ![Max\_Mantei](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/max_mantei/32/7912_2.png) [@Max\_Mantei](https://discourse.mc-stan.org/u/Max_Mantei)\
**Post date:** [March 10, 2020, 4:52pm UTC](https://discourse.mc-stan.org/t/fixing-parameter-values-in-the-transformed-parameters-block/13638/2 "2020-03-10T16:52:07Z")

</div>

Hey! Welcome to the Stan forum!

I’d do something that’s a bit of a combination of the two.

```stan
parameters {
    real A_[N-1];
    real B[N];
    real C[N];
}
transformed parameters {
    real A[N];
    A[1] = 0;
    A[2:N] = A_;
}
model {
    // Idk if you meant to write real...
    // I suppose you meant something like "normal"?
    // ...it'S probably just an example...

    //for (n in 1:N) {
    // X[n] ~ real(A[n] + B[n] + C[n], 1); 
    //}

    // ...but remember that you can vecorize a lot of ~ calls:
    X ~ normal(A + B + C, 1)
}

```

Hope this get’s you what you need!

Cheers!  
Max

---

<div class="post-metadata">

**Author:** ![taromakino](https://avatars.discourse-cdn.com/v4/letter/t/ecc23a/32.png) [@taromakino](https://discourse.mc-stan.org/u/taromakino)\
**Post date:** [March 10, 2020, 5:11pm UTC](https://discourse.mc-stan.org/t/fixing-parameter-values-in-the-transformed-parameters-block/13638/3 "2020-03-10T17:11:08Z")

</div>

Hi Max, thanks for your help. I’ll switch to your version, but for the sake of my understanding, in the Option (2) that I wrote, am I using (the possibly nonzero) A\_[1] during inference?

---

<div class="post-metadata">

**Author:** ![Max\_Mantei](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/max_mantei/32/7912_2.png) [@Max\_Mantei](https://discourse.mc-stan.org/u/Max_Mantei)\
**Post date:** [March 10, 2020, 5:30pm UTC](https://discourse.mc-stan.org/t/fixing-parameter-values-in-the-transformed-parameters-block/13638/4 "2020-03-10T17:30:05Z")

</div>

Yes. Lets say N=6, then `A_` is length 5 and `A` is length 6. Then, `A[1] = 0`, `A[2] = A_[1]` and `A[3] = A_[2]`, … `A[6] = A_[5]`.

Or `A[2:N] = A_[1:(N-1)]`, so all the `A_` are used.

**EDIT: Whoops, I misread your post! Sorry! No, you are not “using” it “in” your model, but it’s still present. Like adding an unrestricted Uniform r.v. to your model. This is probably why your results are different.**

---

<div class="post-metadata">

**Author:** ![Max\_Mantei](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/max_mantei/32/7912_2.png) [@Max\_Mantei](https://discourse.mc-stan.org/u/Max_Mantei)\
**Post date:** [March 10, 2020, 5:39pm UTC](https://discourse.mc-stan.org/t/fixing-parameter-values-in-the-transformed-parameters-block/13638/6 "2020-03-10T17:39:29Z")

</div>

Sorry! I misread your question.

Everything in `parameters` is “in” your model, just not explicitly. Implicitly every parameter gets an \text{Uniform}(-\infty,+\infty) lpdf assigned, which is added to the `target` (the log-prob accumulator). So, “unused” parameters are still _implicitly_ in your model.
