# Repeated linear least squares problem with large dimensions

**URL:** https://discourse.julialang.org/t/repeated-linear-least-squares-problem-with-large-dimensions/130023
**Category:** Performance
**Tags:** linear-regression
**Created:** [June 19, 2025, 11:00am UTC](https://discourse.julialang.org/t/repeated-linear-least-squares-problem-with-large-dimensions/130023 "2025-06-19T11:00:29Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [June 19, 2025, 12:21pm UTC](https://discourse.julialang.org/t/repeated-linear-least-squares-problem-with-large-dimensions/130023/4 "2025-06-19T12:21:10Z")

</div>

> [@JADekker](#):
>
> As such, I’d like to save some computational effort and recycle some work if possible. The thing that comes to mind is to compute pinv(X) and to carry out the regression as pinv(X)\*y^k. I was wondering if this is the way to go here, or if there is a better approach that I’m missing. I look forward to hearing your thoughts!

The pseudo-inverse (computed by SVD in `pinv`) is expensive, and I recently read that multiplying by the explicit `pinv` matrix is not a backwards-stable way of using the pseudo-inverse [(Liu & Barnett, 2016, and references therein)](https://doi.org/10.1016/j.jcp.2016.08.011) . The default method in Julia for least-squares problems via `β = X \ y` is column-pivoted QR, as explained in this thread: [Efficient way of doing linear regression - #33 by stevengj](https://discourse.julialang.org/t/efficient-way-of-doing-linear-regression/31232/33)

Because of this, I would tend to use `QR = qr(X, ColumnNorm())` and then do `β = QR \ y` on each step. This re-uses the efficient QR factorization and should be robust and backwards stable.

---

_[View the full topic](https://discourse.julialang.org/t/repeated-linear-least-squares-problem-with-large-dimensions/130023)._
