Thank you for the clearification - shortly after I posted this I found the following posts:
Which both suggested the approach you suggested.
If I use make_stancode() I get the following:
two_source_model_ar()
#> alpha ~ ar * (max_alpha - min_alpha) + min_alpha
#> ar ~ 1
#> d15n ~ dn * tp - l1 + n1 * ar + n2 * (1 - ar)
#> ar ~ 1
#> tp ~ 1
#> dn ~ 1
two_source_priors_ar()
#> prior class coef group resp dpar nlpar lb ub
#> beta(a, b) b alpha ar 0 1
#> beta(a, b) b d15n ar 0 1
#> normal(dn, dn_sigma) b d15n dn <NA> <NA>
#> uniform(tp_lb, tp_ub) b d15n tp tp_lb tp_ub
#> uniform(sigma_lb, sigma_ub) sigma alpha <NA> sigma_ub
#> uniform(sigma_lb, sigma_ub) sigma d15n <NA> sigma_ub
#> tag source
#> user
#> user
#> user
#> user
#> user
#> user
make_stancode(two_source_model_ar(), data = test,
priors = two_source_priors_ar())
#> // generated with brms 2.23.0
#> functions {
#> }
#> data {
#> int<lower=1> N; // total number of observations
#> int<lower=1> N_alpha; // number of observations
#> vector[N_alpha] Y_alpha; // response variable
#> int<lower=1> K_alpha_ar; // number of population-level effects
#> matrix[N_alpha, K_alpha_ar] X_alpha_ar; // population-level design matrix
#> // covariates for non-linear functions
#> vector[N_alpha] C_alpha_1;
#> vector[N_alpha] C_alpha_2;
#> int<lower=1> N_d15n; // number of observations
#> vector[N_d15n] Y_d15n; // response variable
#> int<lower=1> K_d15n_ar; // number of population-level effects
#> matrix[N_d15n, K_d15n_ar] X_d15n_ar; // population-level design matrix
#> int<lower=1> K_d15n_tp; // number of population-level effects
#> matrix[N_d15n, K_d15n_tp] X_d15n_tp; // population-level design matrix
#> int<lower=1> K_d15n_dn; // number of population-level effects
#> matrix[N_d15n, K_d15n_dn] X_d15n_dn; // population-level design matrix
#> // covariates for non-linear functions
#> vector[N_d15n] C_d15n_1;
#> vector[N_d15n] C_d15n_2;
#> vector[N_d15n] C_d15n_3;
#> int<lower=1> nresp; // number of responses
#> int nrescor; // number of residual correlations
#> int prior_only; // should the likelihood be ignored?
#> }
#> transformed data {
#> array[N] vector[nresp] Y; // response array
#> for (n in 1:N) {
#> Y[n] = transpose([Y_alpha[n], Y_d15n[n]]);
#> }
#> }
#> parameters {
#> vector[K_alpha_ar] b_alpha_ar; // regression coefficients
#> real<lower=0> sigma_alpha; // dispersion parameter
#> vector[K_d15n_ar] b_d15n_ar; // regression coefficients
#> vector[K_d15n_tp] b_d15n_tp; // regression coefficients
#> vector[K_d15n_dn] b_d15n_dn; // regression coefficients
#> real<lower=0> sigma_d15n; // dispersion parameter
#> cholesky_factor_corr[nresp] Lrescor; // parameters for multivariate linear models
#> }
#> transformed parameters {
#> // prior contributions to the log posterior
#> real lprior = 0;
#> lprior += student_t_lpdf(sigma_alpha | 3, 0, 2.5)
#> - 1 * student_t_lccdf(0 | 3, 0, 2.5);
#> lprior += student_t_lpdf(sigma_d15n | 3, 0, 2.5)
#> - 1 * student_t_lccdf(0 | 3, 0, 2.5);
#> lprior += lkj_corr_cholesky_lpdf(Lrescor | 1);
#> }
#> model {
#> // likelihood including constants
#> if (!prior_only) {
#> // initialize linear predictor term
#> vector[N_alpha] nlp_alpha_ar = rep_vector(0.0, N_alpha);
#> // initialize non-linear predictor term
#> vector[N_alpha] mu_alpha;
#> // initialize linear predictor term
#> vector[N_d15n] nlp_d15n_ar = rep_vector(0.0, N_d15n);
#> // initialize linear predictor term
#> vector[N_d15n] nlp_d15n_tp = rep_vector(0.0, N_d15n);
#> // initialize linear predictor term
#> vector[N_d15n] nlp_d15n_dn = rep_vector(0.0, N_d15n);
#> // initialize non-linear predictor term
#> vector[N_d15n] mu_d15n;
#> // multivariate predictor array
#> array[N] vector[nresp] Mu;
#> vector[nresp] sigma = transpose([sigma_alpha, sigma_d15n]);
#> // cholesky factor of residual covariance matrix
#> matrix[nresp, nresp] LSigma = diag_pre_multiply(sigma, Lrescor);
#> nlp_alpha_ar += X_alpha_ar * b_alpha_ar;
#> nlp_d15n_ar += X_d15n_ar * b_d15n_ar;
#> nlp_d15n_tp += X_d15n_tp * b_d15n_tp;
#> nlp_d15n_dn += X_d15n_dn * b_d15n_dn;
#> for (n in 1:N_alpha) {
#> // compute non-linear predictor values
#> mu_alpha[n] = (nlp_alpha_ar[n] * (C_alpha_1[n] - C_alpha_2[n]) + C_alpha_2[n]);
#> }
#> for (n in 1:N_d15n) {
#> // compute non-linear predictor values
#> mu_d15n[n] = (nlp_d15n_dn[n] * nlp_d15n_tp[n] - C_d15n_1[n] + C_d15n_2[n] * nlp_d15n_ar[n] + C_d15n_3[n] * (1 - nlp_d15n_ar[n]));
#> }
#> // combine univariate parameters
#> for (n in 1:N) {
#> Mu[n] = transpose([mu_alpha[n], mu_d15n[n]]);
#> }
#> target += multi_normal_cholesky_lpdf(Y | Mu, LSigma);
#> }
#> // priors including constants
#> target += lprior;
#> }
#> generated quantities {
#> // residual correlations
#> corr_matrix[nresp] Rescor = multiply_lower_tri_self_transpose(Lrescor);
#> vector<lower=-1,upper=1>[nrescor] rescor;
#> // extract upper diagonal of correlation matrix
#> for (k in 1:nresp) {
#> for (j in 1:(k - 1)) {
#> rescor[choose(k - 1, 2) + j] = Rescor[j, k];
#> }
#> }
#> }
Created on 2025-11-24 with reprex v2.1.1
Would I want to modify for instance K_d15n_ar in data to K_alpha_ar and then the same in priorsfound in themodel` section of the Stan code?