Hello all,
I’m trying to estimate a simple duration model with random effects. When I look at the pairs() plots, the parameters themselves are uncorrelated, but I find one parameter to be highly correlated with lp__. The draws for this parameter have low effective sample size and seem to be not very well behaved.
So my question is: what induces correlation between a model parameter and the log posterior? How do you re-parameterize to reduce this correlation? Is that even the right goal?
Here is a snippet of R-code to simulate from the model:
c = exp(rnorm(5, sd = .1))
lambda = rnorm(N, sd = 1)
R_1 = lambda * c[1] - rnorm(N) > 0
R_2 = (lambda * c[2] - rnorm(N) > 0)*R_1
R_3 = (lambda * c[3] - rnorm(N) > 0)*R_2
R_4 = (lambda * c[4] - rnorm(N) > 0)*R_3
R_5 = (lambda * c[5] - rnorm(N) > 0)*R_4
I constrain the c parameters to be positive to set the sign of the latent variable. Now when I try to estimate the model in RStan, I get poor draws for c[1] and c[2] but decent draws for c[3], c[4], and c[5]. c[1] and c[2] are negatively correlated in the posterior, which I suspect to be the source of the problem. However, I haven’t been able to reparameterize the model in such a way that improves performance. Any help would be much appreciated.
Here is the stan program I wrote:
data {
int<lower = 1> N;
int<lower = 0, upper = N> R_1[N];
int<lower = 0, upper = N> R_2_N;
int<lower = 0, upper = N> R_2_ind[R_2_N];
int<lower = 0, upper = 1> R_2_[R_2_N];
int<lower = 0, upper = N> R_3_N;
int<lower = 0, upper = N> R_3_ind[R_3_N];
int<lower = 0, upper = 1> R_3_[R_3_N];
int<lower = 0, upper = N> R_4_N;
int<lower = 0, upper = N> R_4_ind[R_4_N];
int<lower = 0, upper = 1> R_4_[R_4_N];
int<lower = 0, upper = N> R_5_N;
int<lower = 0, upper = N> R_5_ind[R_5_N];
int<lower = 0, upper = 1> R_5_[R_5_N];
}
parameters {
vector[N] lambda;
vector[5] l_c;
}
transformed parameters {
vector<lower = 0>[5] c = exp(l_c);
}
model {
lambda ~ normal(0,1);
l_c ~ normal(0,1);
R_1 ~ bernoulli(
Phi_approx(
lambda * c[1]
));
R_2_ ~
bernoulli(
Phi_approx(
lambda[R_2_ind] * c[2]
));
R_3_ ~
bernoulli(
Phi_approx(
lambda[R_3_ind] * c[3]
));
R_4_ ~
bernoulli(
Phi_approx(
lambda[R_4_ind] * c[4]
));
R_5_ ~
bernoulli(
Phi_approx(
lambda[R_5_ind] * c[5]
));
}
The data objects in the stan program can be generated from the simulated draws using this snippet of R-code:
R_2_ind = which(R_1 == 1)
R_2_N = length(R_2_ind)
R_2_ = R_2[R_2_ind]
R_3_ind = which(R_2 == 1)
R_3_N = length(R_3_ind)
R_3_ = R_3[R_3_ind]
R_4_ind = which(R_3 == 1)
R_4_N = length(R_4_ind)
R_4_ = R_4[R_4_ind]
R_5_ind = which(R_4 == 1)
R_5_N = length(R_5_ind)
R_5_ = R_5[R_5_ind]