dealing with correlated parameters in stan

1,178 views
Skip to first unread message

Linas Mockus

unread,
Jun 5, 2015, 4:10:01 PM6/5/15
to stan-...@googlegroups.com
Hi,

Can anybody advice how to deal with correlated parameters? I found that loc_phi and scale_phi are correlated (as shown by pairs).  Is it possible to re-parametrize the model so they become uncorrelated?  The model is a random intercepts gravity model where log of GDP per capita, log of population, and log of distance are explanatory variables.

The model and trace are attached.

Thank you,
Linas
ranint.stan
FAA_ACI9_noDummies_1_AsiaCountries_NB_Bayes_2012_with_extra_140_ranint.stantracev.pdf

Bob Carpenter

unread,
Jun 8, 2015, 4:06:25 PM6/8/15
to stan-...@googlegroups.com
I don't have any experience with hierarchical gamma priors, so
don't have any suggestions. Anyone?

parameters {
vector<lower=0> [N] phi;
real<lower=0> loc_phi;
real<lower=0> scale_phi;

model {
phi ~ gamma(loc_phi, scale_phi);

...

- Bob

P.S. Tabs in code are problematic because they render differently
depending on how text editors are set up.
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.
> <ranint.stan><FAA_ACI9_noDummies_1_AsiaCountries_NB_Bayes_2012_with_extra_140_ranint.stantracev.pdf>

Andrew Gelman

unread,
Jun 8, 2015, 4:07:38 PM6/8/15
to stan-...@googlegroups.com
Generally I’m preferring lognormals or log t just cos I have better intuition for them. But I’m sure that there are settings where gamma makes sense.
A

Linas Mockus

unread,
Jun 9, 2015, 8:44:12 AM6/9/15
to stan-...@googlegroups.com
Hi,

There is no specific reason to use gamma. I just picked it to be always
positive. My question is if there are some quidelines to choose
hyperpriors. The parameter is phi (for negative binomial to be
overdispersed) and since phi is a vector it was hyperparametrized. I
don't know if this is the right approach.

Thank you,
Linas
--
Thank you,
Linas

Bob Carpenter

unread,
Jun 9, 2015, 12:16:37 PM6/9/15
to stan-...@googlegroups.com
Andrew's about to start our Wiki on recommended priors, so maybe
he'll address this.

- Bob

Linas Mockus

unread,
Jun 10, 2015, 5:30:52 PM6/10/15
to stan-...@googlegroups.com
Hi,

It looks like that lognormal did the trick. The code is attached. It
increased waic slightly. The correlation is still there but it is less
pronounced.

I wonder if techniques such as Matt's trick and/or adding additional
parameters could reduce correlation (as in eq 2 in Gelman's "Prior
distributions for variance parameters in hierarchical model").

Thank you,
Linas
On Mon, 08 Jun 2015 16:07:36 -0400, Andrew Gelman
<gel...@stat.columbia.edu> wrote:

--
Thank you,
Linas
ranint1.stan

Bob Carpenter

unread,
Jun 10, 2015, 5:39:10 PM6/10/15
to stan-...@googlegroups.com
You could definitely try a non-centered version of the lognormal.
I'm not exactly sure what the form should be --- you have to be
careful the posterior's what you want because of the nonlinear
(log) transform of y.

- Bob
> <ranint1.stan>

Linas Mockus

unread,
Jun 11, 2015, 9:59:11 PM6/11/15
to stan-...@googlegroups.com
Thanks, Bob. I wasn't able to find a way how to construct a non-centered
version of lognormal - is it possible to provide any reference. I have
found non-standard versions for t, chi square, even gamma, but not log
normal. By poking around I got the impression that non-centered version
converges better than centered version so I am eager to try.

Thank you,
Linas
--
Thank you,
Linas

Bob Carpenter

unread,
Jun 12, 2015, 12:05:21 AM6/12/15
to stan-...@googlegroups.com
I think this'll do it:

Centered:

parameters {
vector<lower=0> a[K];
real mu_a;
real<lower=0> sigma_a;

model {
a ~ lognormal(mu_a, sigma_a);

Non-Centered:

parameters {
vector<lower=0> log_a_raw[K];
real mu_a;
real<lower=0> sigma_a;

transformed_parameters {
vector<lower=0> a[K];
a <- exp(mu_a + sigma_a * log_a_raw);

model {
log_a_raw ~ normal(0, 1);


I've never tried it on the log scale, so I'm curious how well
it'll work.

- Bob

Linas Mockus

unread,
Jun 12, 2015, 12:33:19 PM6/12/15
to stan-...@googlegroups.com
Thanks, Bob. Mixing improved quite a bit, correlation didn't really change
- see attached trace and pairs. The first pdf is with centered lognormal,
the second pdf is with non-centered lognormal. I wonder if log_a_raw
should span (-inf,+inf) instead of being positive?

Thank you,
Linas
FAA_ACI9_noDummies_1_AsiaCountries_NB_Bayes_2012_with_extra_140_ranint1.stantracev.pdf
FAA_ACI9_noDummies_1_AsiaCountries_NB_Bayes_2012_with_extra_140_ranint4.stantracev.pdf

Linas Mockus

unread,
Jun 12, 2015, 12:43:36 PM6/12/15
to stan-...@googlegroups.com
The code with centered and uncentered versions is attached.

Thank you,
Linas
ranint1.stan
ranint4.stan

Bob Carpenter

unread,
Jun 12, 2015, 1:24:22 PM6/12/15
to stan-...@googlegroups.com
Oh, yes, log_a_raw shouldn't have had lower=0 --- sorry about that.

You should get the same posterior, so I'd hope the correlation of
parameters in the posterior would be the same.

- Bob
> <FAA_ACI9_noDummies_1_AsiaCountries_NB_Bayes_2012_with_extra_140_ranint1.stantracev.pdf><FAA_ACI9_noDummies_1_AsiaCountries_NB_Bayes_2012_with_extra_140_ranint4.stantracev.pdf>

Reply all
Reply to author
Forward
0 new messages