Hello!
I am a complete beginner in Stan and Bayesian Regressions generally. With my setup, the chains do not converge. I have 9993 observations and it takes 4-5 days, in the end without the chain convergence. Could anyone help me out to reproduce the example or suggest any kind of solution? I post the correlation matrix of the data for the reproduction and the setup.
Here is my code:
data {
int<lower=0> N;
int<lower=0> NW;// dimension of exogenous covariates
int<lower=0> NZ; // dimension of instruments
vector[N] y; //outcome vector
vector[N] x; //endogenous variable
matrix[N, NW] w; // exogenous variable
matrix[N, NZ] z; // instruments
vector<lower=0, upper=1>[NZ] beta_z;
}
transformed data {
matrix[N, 2] Y;
Y[,1] = y;
Y[,2] = x;
}
parameters {
real<lower=0, upper=1> beta_x;
vector[2] beta_null;
matrix[NW, 2] beta_w;
vector[NZ] alpha_z;
cov_matrix[2] Omega;
}
transformed parameters {
matrix[N,2] mu;
mu[, 1] = beta_null[1] + beta_x * x + z *beta_x * beta_z + w * beta_w[, 1];
mu[, 2] = beta_null[2] + z * alpha_z + w * beta_w[, 2];
}
model {
//priors
beta_x ~ normal(0,1);
beta_null[1] ~ normal(0,1);
alpha_z ~ normal(0,1);
to_vector(beta_w) ~ normal(0, 1);
to_vector(Omega) ~ student_t(4,0,1);
for(n in 1:N) {
Y[n] ~ multi_student_t(4, mu[n],Omega);
}
}
stanoutput <- stan( file = āstanfileā, data = data, chains = 3)
###Data
N <- 9993
NW <- 5
NZ <- 4
y x w1 w2 w3 w4 w5 z1 z2
y 1.00000000 0.26396795 -0.2997271676 0.16760224 -0.012144523 0.31854680 0.30474905 0.038845574 0.01789145
x 0.26396795 1.00000000 0.1186446230 0.02934843 0.034378885 -0.20605879 -0.19810733 0.038781732 -0.04644700
w1 -0.29972717 0.11864462 1.0000000000 -0.04055944 -0.004459172 -0.14316250 -0.14501490 -0.007953769 -0.01566073
w2 0.16760224 0.02934843 -0.0405594401 1.00000000 -0.011347410 0.28869093 0.27350731 0.032998922 0.07557924
w3 -0.01214452 0.03437889 -0.0044591721 -0.01134741 1.000000000 -0.10056156 -0.09746229 -0.020801965 -0.00978715
w4 0.31854680 -0.20605879 -0.1431624999 0.28869093 -0.100561555 1.00000000 0.98289808 0.045713043 0.10861771
w5 0.30474905 -0.19810733 -0.1450149042 0.27350731 -0.097462286 0.98289808 1.00000000 0.044450397 0.11435677
z1 0.03884557 0.03878173 -0.0079537692 0.03299892 -0.020801965 0.04571304 0.04445040 1.000000000 0.33073711
z2 0.01789145 -0.04644700 -0.0156607270 0.07557924 -0.009787150 0.10861771 0.11435677 0.330737114 1.00000000
z3 -0.01022041 -0.07328704 -0.0164752663 0.05923491 0.009410119 0.12644242 0.13301806 0.157859773 0.47729682
z4 -0.03086815 -0.08324394 -0.0003506437 0.06839972 0.022309498 0.09969438 0.10391898 0.088635791 0.26799469
z3 z4
y -0.010220408 -0.0308681490
x -0.073287038 -0.0832439448
w1 -0.016475266 -0.0003506437
w2 0.059234909 0.0683997177
w3 0.009410119 0.0223094982
w4 0.126442424 0.0996943837
w5 0.133018062 0.1039189775
z1 0.157859773 0.0886357909
z2 0.477296821 0.2679946914
z3 1.000000000 0.5614843413
z4 0.561484341 1.0000000000