# Transform vector of parameters with TransformVariables.jl

**URL:** <https://discourse.julialang.org/t/transform-vector-of-parameters-with-transformvariables-jl/17923>\
**Category:** Statistics\
**Created:** [November 23, 2018, 7:22pm UTC](https://discourse.julialang.org/t/transform-vector-of-parameters-with-transformvariables-jl/17923 "2018-11-23T19:22:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jkbest2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jkbest2/32/7350_2.png) [@jkbest2](https://discourse.julialang.org/u/jkbest2)\
**Post date:** [November 23, 2018, 7:22pm UTC](https://discourse.julialang.org/t/transform-vector-of-parameters-with-transformvariables-jl/17923/1 "2018-11-23T19:22:52Z")

</div>

I am trying to set up a log-posterior for MCMC sampling using `DynamicHMC.jl`. I have two unconstrained parameters, and then a vector of parameters that must be negative. Using `TransformVariables.jl`, I declare

```julia
problem_transformation(p::DerisoProblem) =
    as((logit_h = asℝ, K = asℝ, (F = Array, nrow(p.catch_df) - 1)))

```

How can I declare each element of `F` `asℝ₋`?

My naive attempt

```julia
problem_transformation(p::DerisoProblem) =
    as((logit_h = asℝ, K = asℝ, (F = asℝ₋.(Array, nrow(p.catch_df) - 1))))

```

fails when I try to create a `TransformedLogDensity`

```julia
julia> P = TransformedLogDensity(problem_transformation(derisoproblem), derisoproblem)
ERROR: MethodError: no method matching (::TransformVariables.ShiftedExp{false,Float64})(::Type{Array}, ::Int64)
Closest candidates are:
  ShiftedExp(::Any) at /home/jkbest/.julia/packages/TransformVariables/I4viB/src/utilities.jl:51
Stacktrace:
 [1] _broadcast_getindex_evalf at ./broadcast.jl:574 [inlined]
 [2] _broadcast_getindex at ./broadcast.jl:557 [inlined]
 [3] getindex at ./broadcast.jl:507 [inlined]
 [4] copy at ./broadcast.jl:758 [inlined]
 [5] materialize at ./broadcast.jl:748 [inlined]
 [6] problem_transformation(::DerisoProblem{DataFrame,DataFrame}) at ./REPL[211]:1
 [7] top-level scope at none:0

```

Thanks!

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [November 23, 2018, 7:44pm UTC](https://discourse.julialang.org/t/transform-vector-of-parameters-with-transformvariables-jl/17923/2 "2018-11-23T19:44:21Z")

</div>

> [@jkbest2](#):
>
> ```julia
> as((logit_h = asℝ, K = asℝ, (F = Array, nrow(p.catch_df) - 1)))
> 
> ```

Eg an MWE (replacing the variables)

```julia
julia> using TransformVariables

julia> t = as((logit_h = asℝ, K = asℝ, F = as(Array, asℝ₋, 4)));

julia> dimension(t)
6

julia> t(zeros(dimension(t)))
(logit_h = 0.0, K = 0.0, F = [-1.0, -1.0, -1.0, -1.0])

```

Sorry, that part of the manual is WIP. And suggestions for syntax are most welcome.

---

<div class="post-metadata">

**Author:** ![jkbest2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jkbest2/32/7350_2.png) [@jkbest2](https://discourse.julialang.org/u/jkbest2)\
**Post date:** [November 23, 2018, 7:55pm UTC](https://discourse.julialang.org/t/transform-vector-of-parameters-with-transformvariables-jl/17923/3 "2018-11-23T19:55:04Z")

</div>

Thank you!

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [November 24, 2018, 11:01am UTC](https://discourse.julialang.org/t/transform-vector-of-parameters-with-transformvariables-jl/17923/4 "2018-11-24T11:01:04Z")

</div>

Added a bit more detailed docs:

[https://tpapp.github.io/TransformVariables.jl/dev/#The-as-constructor-and-aggregations-1](https://tpapp.github.io/TransformVariables.jl/dev/#The-as-constructor-and-aggregations-1)

Thanks for calling attention to this. If you need help with any package of mine, especially DynamicHMC & friends, please feel free to ping me on this forum.
