# Structured multivariate regression

**URL:** https://discourse.julialang.org/t/structured-multivariate-regression/133954
**Category:** Statistics
**Tags:** question, linear-regression
**Created:** [November 18, 2025, 9:31am UTC](https://discourse.julialang.org/t/structured-multivariate-regression/133954 "2025-11-18T09:31:27Z")
**Posts on this page:** 3
**Page:** 1

<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 18, 2025, 9:31am UTC](https://discourse.julialang.org/t/structured-multivariate-regression/133954/1 "2025-11-18T09:31:27Z")

</div>

I have a **multivariate linear model** which imposes the specific structure for each **vector** observation \mathbf{y}\_i

\mathbf{y}\_i = \mathbf{b}\_0 + \begin{bmatrix} X\_{1,i} & 0 & X\_{c,i} \\ 0 & X\_{2,i} & X\_{c,i} \\ X\_{1,i} & X\_{2,i} & X\_{c,i} \end{bmatrix} \cdot \begin{bmatrix} B\_1 & B\_2 & B\_c \end{bmatrix} + \varepsilon\_i

where the B\_1, B\_2 have size m \times 3 and the B\_c is n \times 1, so each \mathbf{y}\_i has length 7. \varepsilon\_i is a 7-dimensional IID multivariate normal with variance \Sigma.

I am looking for a Julia package that would allow me to estimate \mathbf{b}\_0, B\_1, B\_2, B\_c, \Sigma without manually building the design matrix. Or, if that cannot be avoided, allowing me to build a design matrix using a 3-dimensional array.

---

<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 19, 2025, 1:52pm UTC](https://discourse.julialang.org/t/structured-multivariate-regression/133954/2 "2025-11-19T13:52:34Z")

</div>

Chickened out from the matrix algebra and fed the problem to a nonlinear least squares solver using trust regions (TrustRegionMethods.jl) which finds a solution for \mathbf{b}\_0, B\_1, B\_2, B\_C with 3 evaluations, then I estimate \Sigma from the residuals \varepsilon\_i. The cost is AD, but I only need this to initialize something much more costly, so it is OK.

---

<div class="post-metadata">

### Author: ![PharmCat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pharmcat/32/6953_2.png) [@PharmCat](https://discourse.julialang.org/u/PharmCat)
#### Post date: [November 21, 2025, 12:41pm UTC](https://discourse.julialang.org/t/structured-multivariate-regression/133954/3 "2025-11-21T12:41:46Z")

</div>

Mmm… I think it can be transformed to one-dimensional representation and solved with MixedModels.jl or Metida.jl with repeated effect.
