data { int<lower=0> N; // num country-years int<lower=1> K; // num ind predictors int<lower=1> J; // num countries int<lower=1> L; // num country predictors int<lower=1,upper=J> cid[N]; // country id matrix[N,K] x; // individual predictors matrix[J,L] u; // country predictors vector[N] y; // outcomes}
parameters { matrix[K,J] z; cholesky_factor_corr[K] L_Omega; // prior correlation vector<lower=0, upper=pi()/2>[K] tau_unif; matrix[L,K] gamma; // country-level coeffs vector<lower=0>[J] sigma_y; // heteroscedastic error scale}
transformed parameters { matrix[J,K] beta; vector<lower=0>[K] tau; // prior scale for (k in 1:K) tau[k] = 2.5 * tan(tau_unif[k]); beta = u * gamma + (diag_pre_multiply(tau, L_Omega) * z)';}
model { to_vector(z) ~ normal(0,1); L_Omega ~ lkj_corr_cholesky(2); to_vector(gamma) ~ normal(0, 5); y ~ normal(rows_dot_product(beta[cid], x), sigma_y[cid]);}
generated quantities { vector[N] y_hat; corr_matrix[K] Omega; Omega = multiply_lower_tri_self_transpose(L_Omega); y_hat = rows_dot_product(beta[cid], x);}
y ~ normal(beta[cid] .* x, sigma_y[cid]);No matches for:vector ~ normal(matrix, vector)
beta = u * gamma + (diag_pre_multiply(tau, L_Omega) * z)';
data { int<lower=0> N; // num country-years int<lower=1> J; // num countries int<lower=1> K; // num predictors int<lower=1> L; // num country predictors real y[N]; // outcome matrix[N,K] X; // predictors (not incl intercept) int<lower=1, upper=17> cid[N]; // country matrix[J,2] U; // country predictors (incl intercept)}
parameters { matrix[K+1,J] z; cholesky_factor_corr[K+1] L_Rho; real g0; vector[K] g; vector<lower=0>[J] sigma_y; real<lower=0> sigma_b0; vector<lower=0>[K] sigma_b; vector[L] G0;}
transformed parameters{ matrix[J, K+1] b_temp; vector[K+1] sigma_b_temp; // vector[J] b0; // country intercepts matrix[J,K] b; // country parameters matrix[5,K+1] Rho; sigma_b_temp[1] = sigma_b0; sigma_b_temp[2:K+1] = sigma_b; b_temp = (diag_pre_multiply(sigma_b_temp, L_Rho) * z)'; b0 = col(b_temp, 1); for (k in 1:K) b[,k] = b_temp[,k+1]; Rho = L_Rho * L_Rho' ;}
model { vector[N] mu; vector[N] B0; matrix[N,K] B; L_Rho ~ lkj_corr_cholesky(2); sigma_y ~ cauchy(0, 2); sigma_b ~ cauchy(0, 2); g0 ~ normal(U * G0, 10); g ~ normal(0, 5); G0 ~ normal(0, 10); to_vector(z) ~ normal(0, 1); for (n in 1:N){ B0[n] = g0 + b0[cid[n]]; } for (n in 1:N){ for (k in 1:K){ B[n,k] = g[k] + b[cid[n],k]; } } for (n in 1:N){ mu[n] = B0[n] + B[n] * X[n]'; } y ~ normal(mu, sigma_y[cid]);}y[i] = a[j] + b[jk]X[ik]a[j] ~ N(g[a0] + g[a1] u[j], sigma^2[a])b[jk] ~ N(g[bk0] + g[bk1] u[j], sigma^2[bk])
b[jk] ~ N(g[bk], sigma^2[bk])
data { int<lower=0> N; // num country-years int<lower=1> K; // num ind predictors int<lower=1> J; // num countries int<lower=1> L; // num country predictors int<lower=1,upper=J> cid[N]; // country id matrix[N,K] X; // individual predictors matrix[J,L] R; // country predictors vector[N] y; // outcomes}
parameters { matrix[K,J] z; cholesky_factor_corr[K] L_Omega; // prior correlation vector<lower=0, upper=pi()/2>[K] tau_unif; vector[L] g0; // country-level coeffs vector[K-1] g; vector<lower=0>[J] sigma_y; // heteroscedastic error scale}
transformed parameters { matrix[J,K] beta; matrix[J,K] beta_temp; vector<lower=0>[K] tau; // prior scale for (k in 1:K) tau[k] = 2.5 * tan(tau_unif[k]); beta_temp = (diag_pre_multiply(tau, L_Omega) * z)'; beta[,1] = R * g0 + beta_temp[,1]; for (k in 2:K) beta[,k] = g[k-1] + beta_temp[,k];}
model { to_vector(z) ~ normal(0,1); L_Omega ~ lkj_corr_cholesky(2); g0 ~ normal(0,5); g ~ normal(0,5); y ~ normal(rows_dot_product(beta[cid], X), sigma_y[cid]);}
generated quantities { vector[N] y_hat; corr_matrix[K] Omega; Omega = multiply_lower_tri_self_transpose(L_Omega); y_hat = rows_dot_product(beta[cid], X);}