I have to leave again so I'll make this brief while hopefully still being informative. the R code and STAN code associated with this recent experiment is at the bottom of the email.
A) I really just implemented and ran what Ben suggested originally but, if someone could check my code, it's appreciated because I haven't read the manual fully so I don't know yet when order matters and when it doesn't. Amazing manual by the way. Whoever wrote that should e-mail R-core and ask them if they'll pay he/she to document R similarly !!!!
B) I ran a similar scenario set to what I ran earlier in terms of sets of triplets of parameters ( each triplet only varies in beta values ) and then as I go down, I keep decreasing lambda to see how that effects
the beta estimates.
C) The results are better. The estimates of beta don't get totally whacky like they did in the earlier experiment but for lambda ( which of course used to be rho. we just changed notation somewhere along the way ) above 0.9, the beta estimates are still not very good. I put the beta estimate at the top of each triplet and gave it a "review" so that it's not necessary to re-run all the code. I set.seed(123) at the top
if the code before running each scenario but there's some randomness of course going on in STAN so the results won't be the same. It seems that below lambda = 0.9, the estimates pretty much
remain as good as they're going to get for the most part. In my other run where I explicitly code lambda(1-rho), the improvement seemed to be less spikey and more gradual. Not sure if that means
anything.
D) I don't claim to be an HMC expert but I'm trying to think about something that my understanding is not 100 percent clear on so hear me out if you don't mind. Lennart says that the log posterior goes to
infinity as rho goes to 1. I'm not clear on how he knows that but, assuming it's true: could the problem then correspond to the example on pages 30-31 of "Probabilistic Inference Using Markov Chain Monte Carlo
Methods" by Radford Neal. If someone could take a look at that discussion and the picture in c). The density is spiking up in one place and the values of A in that place are all very low so MCMC sampling will
be problematic. I don''t know enough about HMC ( atleast yet. as time permits, I'm going back over then DUANE paper for the 38th time ) yet to say anything with confidence but maybe the problem has something to do with that which I think is what Lennart was saying ?
So, given D) is true ( which it may not be ), I have two thoughts/ideas:
1) restrict rho to be uniform(0,0.95). only problem with that is you leave out cases where rho really is greater than that.
2) use the prior that lennart suggested to force the posterior density to be zero when rho gets near 1.0.
Thanks for any other comments/suggestions/wisdom. I'm still getting my brain immersed in HMC yes, the trajectory stopping thing is currently beyond me but I still have to go back and see where the actual
posterior density is involved in HMC. I think it's only involved because it's the gradient of the posterior that's in the differential equations that simulate states of parameters. but if that's the case, that's so different from regular metropolis where the actual posterior atleast gets plugged into on the top and bottom in the acceptance step. The metropolis argument makes perfect sense to me. In HMC, the metrpolis type
acceptance is used the actual posterior isn't even involved in the acceptance step !!!!!! and this continues to confuse me in terms of how one can just use multivariate normals ( I understand that the normals are conditional but that the conditionals are just the marginals because of independence of the two energies in the expression for the hamiltonian. I just don't understand why one don't plug into the posterior
like would be done in a regular metropolis step. that has something to do with sampling from the differential equations rather than from the density itself but I'm working on it ) but I'm getting it slowly.
So my point is that D) is all guess work.I'll be out the rest of the day so no immediate replies. And no should try to explain HMC to me. I keep reading and reading and reading and when I get to the point where I can't understand it any better, I'll ask someone on the list. Not that I wouldn't appreciate an explanation but I'd rather get one when I'm done making my own attempts. Thanks for reading this and any comments about A-D and 1) and 2).
# R CODE FOR BEN'S SUGGESTION
#==================================================================================================
library("rstan");
set.seed(123)
T <- 200;
x <- rnorm(T,0,1);
#=========================================
# NOT OKAY : 0.2
#=========================================
#beta <- 1.0;
#lambda <- 0.95
#sigma <- 1.0
#=========================================
# NOT OKAY : 1.5
#=========================================
#beta <- 2.6;
#lambda <- 0.95
#sigma <- 1.0
#=========================================
# NOT OKAY : -0.1
#=========================================
#beta <- 0.5;
#lambda <- 0.95
#sigma <- 1.0
#====================================
# NOT OKAY: 0.6
#====================================
#beta <- 1.0;
#lambda <- 0.90
#sigma <- 1.0
#====================================
# NOT GREAT : 1.8
#========================================
#beta <- 2.6;
#lambda <- 0.90
#sigma <- 1.0
#========================================
# NOT SO GOOD : 0.2
#========================================
#beta <- 0.5;
#lambda <- 0.90
#sigma <- 1.0
#========================================
#NOT BAD: 0.8
#=========================================
#beta <- 1.0;
#lambda <- 0.85
#sigma <- 1.0
#=========================================
#SO SO : 2.0
#=========================================
#beta <- 2.6;
#lambda <- 0.85
#sigma <- 1.0
#=========================================
#SO SO : 0.3
#=========================================
#beta <- 0.5;
#lambda <- 0.85
#sigma <- 1.0
#====================================
# SO SO: 0.7
#====================================
#beta <- 1.0;
#lambda <- 0.80
#sigma <- 1.0
#====================================
# DECENT: 2.2
#====================================
#beta <- 2.6;
#lambda <- 0.80
#sigma <- 1.0
#====================================
#SO SO : 0.3
#====================================
#beta <- 0.5;
#lambda <- 0.80
#sigma <- 1.0
#====================================
# OKAY: 0.8
#====================================
#beta <- 1.0;
#lambda <- 0.75
#sigma <- 1.0
#====================================
# GOOD: 2.7
#====================================
#beta <- 2.6;
#lambda <- 0.75
#sigma <- 1.
#====================================
# STILL SO SO : 0.3
#====================================
#beta <- 0.5;
#lambda <- 0.75
#sigma <- 1.0
#====================================
# OKAY: 0.8
#====================================
#beta <- 1.0;
#lambda <- 0.70
#sigma <- 1.0
#====================================
# GOOD: 2.4
#====================================
#beta <- 2.6;
#lambda <- 0.70
#sigma <- 1.0
#====================================
# GOOD: 0.4
#====================================
#beta <- 0.5;
#lambda <- 0.70
#sigma <- 1.0
#===========================================
y <- rep(NA,T);
y[1] <- rnorm(1,beta * (1 - lambda) * x[1],sigma);
for (t in 2:T)
y[t] <- rnorm(1, beta * (1 - lambda) * x[t] + lambda * y[t-1], sigma);
fit <- stan(file="koyck_gen.stan", data=c("T","y","x"), iter=1000, chains=4);
print(fit)
#=========================================================================================
# STAN CODE
#===============================================================================================================================================
data {
int<lower=0> T; // number of time points
real y[T]; // output at time t
real x[T]; // predictor for time t
}
parameters {
real beta1mlambda; // equals beta * (1-lambda)
real <lower=0, upper=1> lambda; // lag
real <lower=0> sigma; // noise scale
}
model {
beta1mlambda ~ cauchy(0,5);
lambda ~ uniform(0,1);
sigma ~ cauchy(0,5);
y[1] ~ normal(beta1mlambda * x[1], sigma);
for (t in 2:T)
y[t] ~ normal( beta1mlambda * x[t] + lambda * y[t-1],sigma);
}
generated quantities {
real beta;
beta <- beta1mlambda / (1 - lambda);