# Efficient way of doing linear regression

**URL:** https://discourse.julialang.org/t/efficient-way-of-doing-linear-regression/31232
**Category:** Performance
**Tags:** regression
**Created:** [November 18, 2019, 5:21pm UTC](https://discourse.julialang.org/t/efficient-way-of-doing-linear-regression/31232 "2019-11-18T17:21:15Z")
**Posts on this page:** 5
**Page:** 3

<div class="post-metadata">

### Author: ![Juan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juan/32/7657_2.png) [@Juan](https://discourse.julialang.org/u/Juan)
#### Post date: [August 12, 2020, 11:26pm UTC](https://discourse.julialang.org/t/efficient-way-of-doing-linear-regression/31232/42 "2020-08-12T23:26:33Z")

</div>

Related to your question:

> [@GLM is slow on large datasets. Using OnlineStats for regressions? MixedModels?](https://discourse.julialang.org/t/glm-is-slow-on-large-datasets-using-onlinestats-for-regressions-mixedmodels/17695):
>
> Hello. I’m planning to move from R to Julia and doing some tests about how to properly deal with large datasets and do simple tasks like regressions or survival analysis. I’ve done a benchmark with R (microbenchmark) for the regressions. N ← 3000 x1 ← rep(1:N, N) x2 ← rep(1:N, each = N) x3 ← sqrt(rep(1:N^2)) x1x2 ← x1x2 gg ← rep(1:5, each=N^2/5) y ← 1-2x1+3x2+0.5x1x2+rnorm(N^2)+x3\*rnorm(N^2) dat ← data.frame(y,x1,x2,x1x2,x3, gg) dat2 ← cbind(1,x1,x2,x1x2,x3,gg) lm(y ~ x1 + x2 + x1…

---

<div class="post-metadata">

### Author: ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)
#### Post date: [August 14, 2020, 8:28pm UTC](https://discourse.julialang.org/t/efficient-way-of-doing-linear-regression/31232/43 "2020-08-14T20:28:13Z")

</div>

If anyone is interested, i have implemented a faster and also numerically stable method for underdetermined linear systems in this post:

> [@Grassmann.jl A\\b 3x faster than Julia's StaticArrays.jl](https://discourse.julialang.org/t/grassmann-jl-a-b-3x-faster-than-julias-staticarrays-jl/41451/35):
>
> This was because of a special explicit case for dimensions 1 and 2 and 3, which are now accounted for in Grassmann.jl also. Also, support has been added for Moore-Penrose inverses for underdetermined and overdetermined linear systems. For underdetermined cases, the exterior product algorithm works ~20x faster than the SMatrix algorithm, and it is numerically stable. For overdetermined equations, the method used is based on the traditional normal equations, and this is prone to more numerical i…

---

<div class="post-metadata">

### Author: ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)
#### Post date: [August 17, 2020, 6:58pm UTC](https://discourse.julialang.org/t/efficient-way-of-doing-linear-regression/31232/44 "2020-08-17T18:58:52Z")

</div>

Just to mention that I wrote a simple package to do what I was searching for when I found this thread, which was a very simple interface to do simple fits of 2D data:

[https://github.com/m3g/EasyFit](https://github.com/m3g/EasyFit)

---

<div class="post-metadata">

### Author: ![st1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/st1/32/26929_2.png) [@st1](https://discourse.julialang.org/u/st1)
#### Post date: [November 18, 2021, 9:49pm UTC](https://discourse.julialang.org/t/efficient-way-of-doing-linear-regression/31232/45 "2021-11-18T21:49:56Z")

</div>

I also needed basic linear regression, a bit beyond X \ y, and didn’t want the full GLM dependency chain, so I tried to incorporate the various suggestions from this thread in a very simple, minimal-dependency package, see [https://github.com/st--/LinearRegression.jl](https://github.com/st--/LinearRegression.jl) - in case anyone else who stumbles across this thread may find it useful!

I also put links to various packages for more fancy versions of linear regression (generalized, ridge, sparse, bayesian, online, …) into the readme.🙂

---

<div class="post-metadata">

### Author: ![lawless-m](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lawless-m/32/30869_2.png) [@lawless-m](https://discourse.julialang.org/u/lawless-m)
#### Post date: [February 7, 2022, 9:35am UTC](https://discourse.julialang.org/t/efficient-way-of-doing-linear-regression/31232/46 "2022-02-07T09:35:17Z")

</div>

great stuff, I just walked the same path

[Previous page](https://discourse.julialang.org/t/efficient-way-of-doing-linear-regression/31232.md?page=2)
