# How can I tell Julia what are the parameters in a linear model?

**URL:** <https://discourse.julialang.org/t/how-can-i-tell-julia-what-are-the-parameters-in-a-linear-model/87692>\
**Category:** Statistics\
**Tags:** regression, fit, curve-fitting, glm, linear-regression\
**Created:** [September 23, 2022, 11:27am UTC](https://discourse.julialang.org/t/how-can-i-tell-julia-what-are-the-parameters-in-a-linear-model/87692 "2022-09-23T11:27:06Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [September 26, 2022, 5:24pm UTC](https://discourse.julialang.org/t/how-can-i-tell-julia-what-are-the-parameters-in-a-linear-model/87692/15 "2022-09-26T17:24:11Z")

</div>

There are many performance improvements to be had before changing the algorithm. In particular, you want to “capture” the variables used in the optimization inside a `let` block.

Also, never do `df.z` in performant code, since `DataFrame`s are type-unstable. Always work on the vector directly.

```julia
julia> z = df.z; x = df.x; y = df.y;

julia> g = let x = x, y = y, z = z 
           β -> begin 
                   x₀ = β[3]; y₀ = β[4]
                   ẑ = β[1]*(x .- x₀).^2 + β[2]*(y .- y₀).^2 
                   return sum((z - ẑ).^2)
           end
       end;

```

---

_[View the full topic](https://discourse.julialang.org/t/how-can-i-tell-julia-what-are-the-parameters-in-a-linear-model/87692)._
