difference in n_eff of population mean depending on model specification

Open
#405 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
1-2 days
Newbie friendliness
10/100
Issue type
Documentation
Clarity
Needs clarification
Activity status
Stale
Tech stack
r
Domain
data

Research direction

This is an open question, not a defect: the reporter's two ulam models in the issue body (m1 with a[I] ~ normal(abar, asigma), m2 with mu <- abar + a[I] and a[I] ~ normal(0, asigma)) give the same estimates but very different n_eff for abar. The reporter's own edit says the non-centering assumption was mistaken, so there may be nothing left to fix. Done would mean a maintainer reply, or a short explanation added to the docs, about why the parameterisations sample differently. No code location is named, and the thread has had no comment for over three years.

Written by the indexing model from the issue text.

Description

EDIT: after playing around with this and reading up a bit more I understand now that non-centering (which I suppose m2 is a clumsy attempt of, but the same thing happens with transpars> vector[I]:a <<- abar + z*asigma ) isn't always good for your sampling, which is the mistaken idea I was laboring under. Feel free to disregard the question below if it seems silly or trivial.


I'll admit upfront that I ask this question mostly out of curiosity. I'm not entirely sure it's appropriate to post this here, since this doesn't concern a code issue, but I don't really know what a more appropriate place would be so I figured I'd drop a question here:

I'm using ulam alongside some other stan frontends (e.g. brms) to model data obtained from multiple participants in a hierarchical way, with observations nested in participants. What I noticed is that, depending on the model specification, the effective n for the population mean can vary widely.

For a reproducable example I coded up a rudimentary simulation of participants drawn from a population to illustrate my point:

library(rethinking)
library(tidyverse)

set.seed(42)

abar <- 10      # pop mean
asigma <- 5     # pop variance
n <- 100         # n subjects
n_trials <- 100 # n trials (of course)
sigma <- 2     # within-subject/residual variance

as <- rnorm(n,abar,asigma) # draw some participants from pop

# now generate some data
d <- tibble(
I = rep(1:n,each=n_trials),
A = rep(as,each=n_trials) 
) %>% 
  rowwise %>% 
  mutate(Y = rnorm(1,A,sigma)) %>% 
  ungroup

I can model this data in (at least) two equivalent ways:


# abar is explicitly the mean of the a[I] distribution
m1 <- ulam(
  alist(
    Y ~ normal(mu, sigma),
    mu <- a[I],
    
    a[I] ~ normal(abar,asigma),
    
    abar ~ normal(0,10),
    asigma ~ exponential(1),
    
    sigma ~ exponential(1)
  ), data=d,chains=4,iter=2000,cores=4
)

# abar is pulled out of the a[I] distribution, which is now centered on 0
m2 <- ulam(
  alist(
    Y ~ normal(mu, sigma),
    mu <- abar + a[I],
    
    a[I] ~ normal(0,asigma),
    
    abar ~ normal(0,10),
    asigma ~ exponential(1),
    
    sigma ~ exponential(1)
  ), data=d,chains=4,iter=2000,cores=4
)

These two models have the same parameters and reach the same estimates of all coefficients, including abar. However, in my testing the n_eff for abar in model 1 is ~ 8000, while it only reaches 15(!) in model 2. While they reach the same conclusions numerically, I worry about the stability this has for posterior predictive checks etc.

I'm sure there's something obvious I'm missing, but I'm curious if there are known reasons for this discrepancy. Of course generally I would be happy to just always specify my model as seen in m1, but for more tricky models with multiple varying effects, or non-centered parametrizations, as I understand it, I have no choice but to 0-center the effects, which always leads to low sampling efficiency for these group means in my experience. Any advice would be appreciated!

Dominant language
R
Stars
2.4k
Forks
632
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rmcelreath/rethinking

All issues in rmcelreath/rethinking

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.