# How to use zerocorr() while creating a formula?

**URL:** <https://discourse.julialang.org/t/how-to-use-zerocorr-while-creating-a-formula/54458>\
**Category:** New to Julia\
**Created:** [February 2, 2021, 1:40pm UTC](https://discourse.julialang.org/t/how-to-use-zerocorr-while-creating-a-formula/54458 "2021-02-02T13:40:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lisovyk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lisovyk/32/21505_2.png) [@lisovyk](https://discourse.julialang.org/u/lisovyk)\
**Post date:** [February 2, 2021, 1:40pm UTC](https://discourse.julialang.org/t/how-to-use-zerocorr-while-creating-a-formula/54458/1 "2021-02-02T13:40:23Z")

</div>

I’m passing variables to put into formula in Julia from R. The way I construct formula is such:

```julia
effects = Symbol.(["asd","sdf","dfg"])
effects = :(+$(effects...))
dep_var = Symbol("depend_var")

julia> fm = @eval @formula($(dep_var) ~ $(effects))
Formula: depend_var ~ asd + sdf + dfg

```

The question is, how can I use `zerocorr()` with such variables?  
If I’m passing it like this - `@eval @formula($(var1) ~ zerocorr($(var2)))`, it does not create a right formula, zerocorr() is not interpreted as a call but is passed literally from what I understand.

---

<div class="post-metadata">

**Author:** ![dave.f.kleinschmidt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dave.f.kleinschmidt/32/55_2.png) [@dave.f.kleinschmidt](https://discourse.julialang.org/u/dave.f.kleinschmidt)\
**Post date:** [February 20, 2021, 8:02pm UTC](https://discourse.julialang.org/t/how-to-use-zerocorr-while-creating-a-formula/54458/2 "2021-02-20T20:02:22Z")

</div>

First, while that works, it’s not the recommended way to create a formula programmatically; instead, it’s recommended to use `sum(term.(effects))`. EDIT: here’s the section in the StatsModels.jl docs on this: [Modeling tabular data · StatsModels.jl](https://juliastats.org/StatsModels.jl/stable/formula/#Constructing-a-formula-programmatically-1)

Second, that probably won’t work with `zerocorr` right now, because it’s not (easily) possible to create RE terms at run time. [Programmatically Creating RE Terms · Issue #462 · JuliaStats/MixedModels.jl · GitHub](https://github.com/JuliaStats/MixedModels.jl/issues/462)

Third, keep in mind that `zerocorr` only makes sense for random effects where there’s more than one random term (intercept and one or more slopes). I don’t know what `var2` is supposed to be in your example above, but if it’s not something like `:(1 + a | g)` then `zerocorr` wouldn’t make any sense anyway…
