Glad it finally fit for you, but there are problems with this
from a Stan perspective. First, you could use some indentation and
spacing around operators so that it's more readable.
These two:
real<lower=0> phi; //variance
...
phi~uniform(0,100000);
are not compatible. You really should be declaring
real<lower=0, upper=1000000> phi;
because Stan requires every variable meeting the constraints
to have a finite log density (2000000 meets your constraint
but has 0 log density because of the bounds on the uniform).
But then you'll get initializations around 500,000 because
you've said the values are equally likely to be anywhere
between 0 and 1M. Is that what you intended? If not,
we recommend actually using priors that do express what
you know ahead of time about phi.
You can also just get rid of the uniform(...) and use
an improper prior. Then you initialize around 1 because
that's the center of the exp() transform to get values
to be positive.
For efficiency, don't duplicate calculations:
sk[1]=(Y[2*i-1]-yhat[1])^2;
sk[2]=(Y[2*i]-yhat[2])^2;
Fk[1]=Y[2*i-1]-yhat[1];
Fk[2]=Y[2*i]-yhat[2];
Instead, you can vectorize the definition of sk as
Fk[1] = Y[2*i-1] - yhat[1];
Fk[2] = Y[2*i] - yhat[2];
sk[1] = square(Fk[1])
sk[2] = square(Fk[2]);
or
Fk[1:2] = Y[(2 * i - 1):(2 * i)] - yhat[1:2];
sk[1:2] = square(Fk[1:2]);
Also later,
V[4, 4] = V[3, 3];
You never want to compute inverses, so instead of
u= D'*inverse(V)*Fk;
it's much more stable to write
D' / V * Fk;
where D' / V =def= D' * inverse(V). Same with later calc.
We have a quad form, but you're inverting, so you can't use that.
We should probably have an inverse quad form, and also a more
general multiply_self_transpose---as is, we don't have the inverse
quad form and only have multiply_self_transpose for triangular
matrices.
- Bob
> On Mar 23, 2017, at 5:17 PM, Jaron <
arbe...@umn.edu> wrote:
>
> For those not familiar with bayesian generalized method of moments (GMM), the basic idea is really simple:
> 1) construct estimating equations u for parameters of interest theta
> we are interested in solving u=0 to obtain estimates of theta
> 2) then the sample mean U = 1/N * sum(u_1,....,u_N) will be asymptotically normal with mean 0 and covariance which is consistently estimated by Sigma_hat (formula is given in Yin's paper).
> 3) Apply a normal likelihood function to U (with mean 0 and covariance Sigma_hat) and flat priors for theta, then use MCMC to estimate the posterior distribution for all parameters of interest
>
> Yin's 2009 paper proposed the Bayesian GMM which I am trying to fit in STAN. Essentially the model I'm trying to fit is a Bayesian anlog to the frequentist GEE model using an indepdence working correlation structure. I simulated some simple data which consists of N 2-person families, thus we do not have independent subjects since the response (Y) will be correlated within each family. However, GMM can be used to conduct valid inference on the mean parameters despite the fact that our working independent correlation structure is wrong.
>
> I attached some simple simulated data and my current .stan file. Lastly, here is my R code to fit the model in Rstan:
> library(rstan)
> load("GEE1data1.RData")
> data=list(Y=simdata$Y,X1=simdata$X1,N=length(table(simdata$famID)),N2=100.0)
> fit = stan(file = "stan_GEE1_ind.stan",data = data, cores = 1, chains = 1, iter = 10)
>
> However the model fails to fit. Specifically, it appears the main problem is with the final line in my .stan file where i attempt to define the multivariate normal likelihood from step (3):
> target += -0.5*U'*inverse(Sigma)*U;
You really don't want to implement this this way.
You can do U' / Sigma * U, and it should be more stable.
>
> Any help getting this model to fit would be greatly appreciated!! I will note that I was unable to get this model to fit in JAGS, and I'm now trying to decide if it's possible to fit bayesian GMM models in STAN.
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
stan-users+...@googlegroups.com.
> To post to this group, send email to
stan-...@googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.
> <stan_GEE1_ind.stan><GEE1data1.RData>