# Help with formula notation for multivariate model in brms vignette

I’m trying to understand the multivariate model formula implied by fit3 from the brms vignette on multivariate models. To bring everything into one place from that vignette, that model can be reproduced by running the following:

library(brms)
data("BTdata", package = "MCMCglmm")

bf_tarsus <- bf(tarsus ~ sex + (1|p|fosternest) + (1|q|dam)) +
lf(sigma ~ 0 + sex) +
skew_normal()
bf_back <- bf(back ~ s(hatchdate) + (1|p|fosternest) + (1|q|dam)) +
gaussian()

fit3 <- brm(
bf_tarsus + bf_back + set_rescor(FALSE),
data = BTdata, chains = 2, cores = 2,
)


If I’m following the narrative & syntax correctly, this model implies correlations between parameters in the tarsus and back components of the multivariate model. Specifically, the “random” effects of fosternest and dam are correlated among model components and are linked by |p| and |q|, respectively. Using the fitted coefficients and the prior summary tables,

summary(fit3)
prior_summary(fit3)


I think the formula notation should be something like*:

\begin{aligned} \text{tarsus}_i &\sim \text{SkewNormal}(\xi_i,\omega^2_i, \vartheta) \\ \xi_i &= \alpha^t + \beta^t_{\text{sex}[i]}A_i + \alpha_{\text{fosternest}[i]}^\text{t} + \alpha_{\text{dam}[i]}^\text{t} \\ \omega^2_i &= \gamma^t_{\text{sex}[i]}A_i \\ \left(\beta^t,\gamma^t\right) &\sim \text{Student}(3,0,10) \\ \vartheta &\sim \text{Normal}(0, 4) \\ \text{back}_i &\sim \text{Normal}(\mu_i,\sigma) \\ \mu_i &= \beta^b_\text{hatchdate[1]} + \sum_{k=1}^Kb_kz_{ik}+ \alpha_{\text{fosternest}[i]}^\text{b} + \alpha_{\text{dam}[i]}^\text{b} \\ \left(\beta^b_\text{hatchdate[1]},b_k,\sigma\right) &\sim \text{Student}(3,0,10) \\ \left[\begin{matrix} \alpha_{\text{fosternest}}^\text{t} \\ \alpha_{\text{fosternest}}^\text{b} \end{matrix}\right] &\sim \text{MVNormal}\left(\left[\begin{matrix} 0 \\ 0 \end{matrix}\right], \mathbf{S}_\text{fosternest}\right) \\ \left[\begin{matrix} \alpha_{\text{dam}}^\text{t} \\ \alpha_{\text{dam}}^\text{b} \end{matrix}\right] &\sim \text{MVNormal}\left(\left[\begin{matrix} 0 \\ 0 \end{matrix}\right], \mathbf{S}_\text{dam}\right) \\ \mathbf{S}_\text{fosternest} &= \left(\begin{matrix} \sigma_{\alpha_\text{fosternest}^t} & 0 \\ 0 & \sigma_{\alpha_\text{fosternest}^b} \end{matrix}\right) \mathbf{R}_\text{fosternest} \left(\begin{matrix} \sigma_{\alpha_\text{fosternest}^t} & 0 \\ 0 & \sigma_{\alpha_\text{fosternest}^b} \end{matrix}\right) \\ \mathbf{S}_\text{dam} &= \left(\begin{matrix} \sigma_{\alpha_\text{dam}^t} & 0 \\ 0 & \sigma_{\alpha_\text{dam}^b} \end{matrix}\right) \mathbf{R}_\text{dam} \left(\begin{matrix} \sigma_{\alpha_\text{dam}^t} & 0 \\ 0 & \sigma_{\alpha_\text{dam}^b} \end{matrix}\right) \\ \left(\mathbf{R}_\text{fosternest},\mathbf{R}_\text{dam}\right) &\sim \text{LKJcorr}(1) \end{aligned}

My questions:

1. Is this the correct correlation structure implied by the brms model syntax in the vignette? I’ve largely followed this example from Solomon’s Statistical Thinking Recoded.
2. How should the GAMM smooth term be expressed in the formula? I’m especially unsure about how to express (a) the population-level effect for back_shatchdate_1 that appears in the model summary table and (b) the additive term for class sds. What you see in the formula above is what I managed to (feebly) adapt from Crainiceanu et al. (2005) J Stat Soft.
3. Is there a way to adapt this model to infer the number of knots (K) for the smooth term? I’d be interested in both the brms and formula syntax to accomplish this.