question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WAIC/LOO for models with multiple observed variables

See original GitHub issue

(Related issue: #794 - cc @rpgoldman)

First, thank you for this great library!

I was told by @ahartikainen here that multiple observations were not supported in arviz (at least for numpyro and pyro, but I guess for other libraries like PyMC3 as well).

My question is: to go from 1 observation to multiple observations , isn’t it enough to sum all the log_likelihoods of observed variables to compute the waic and loo?

Indeed, the WAIC and LOO are computed based on where are all the examples (observations) and are all the samples from the posterior of all parameters and hidden variables.

  • In the case where are conditionally independent given all the hidden variables and parameters, then we can use and use this quantity as the likelihood of our observation. (Correct me if I’m mistaken)
  • When there are some dependencies between the observed variables, then it seems to me that it still holds - maybe except in the case where there are circular dependencies between variables.

Below I write examples of numpyro models:

for one observation:

def eight_schools(J, sigma, y=None):
    mu = numpyro.sample('mu', dist.Normal(0, 5))
    tau = numpyro.sample('tau', dist.HalfCauchy(5))
    with numpyro.plate('J', J):
        theta = numpyro.sample('theta', dist.Normal(mu, tau))
        numpyro.sample('obs', dist.Normal(theta, sigma), obs=y)

for several observations which are conditionally independent:

def eight_schools(J, sigma, y1=None, y2=None):
    mu = numpyro.sample('mu', dist.Normal(0, 5))
    tau = numpyro.sample('tau', dist.HalfCauchy(5))
    with numpyro.plate('J', J):
        theta = numpyro.sample('theta', dist.Normal(mu, tau))
        numpyro.sample('obs1', dist.Normal(theta, sigma), obs=y1)
        numpyro.sample('obs2', dist.Normal(theta, sigma), obs=y2)

for several observations which are not conditionally independent:

def eight_schools(J, sigma, y1=None, y2=None):
    mu = numpyro.sample('mu', dist.Normal(0, 5))
    tau = numpyro.sample('tau', dist.HalfCauchy(5))
    with numpyro.plate('J', J):
        theta = numpyro.sample('theta', dist.Normal(mu, tau))
        obs1 = numpyro.sample('obs1', dist.Normal(theta, sigma), obs=y1)
        numpyro.sample('obs2', dist.Normal(obs1, sigma), obs=y2)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:19 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
ahartikainencommented, Jan 9, 2020

I think we should have multiple options for different methods. LFO needs also possibility to resample (there are code to do this in pystan, but we really need to refine InferenceData class to enable this).

We should have same default as in loo2.

0reactions
OriolAbrilcommented, Nov 9, 2021

Closing this as the original issue has been fixed. For usage and interpretation questions on loo/waic, please ask on stan or pymc discourse forums.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Calculating WAIC for models with multiple likelihood functions
When working with several observed variables, there is not a single way of computing waic/loo nor or performing cross-validation.
Read more >
Understanding LOOIC - Modeling - The Stan Forums
Hello all, I'm making progress on my first Bayesian models, ... Bayes factor indicating under which model my observed data is more probable....
Read more >
Chapter 9 Model Comparison and Regularization - Bookdown
Sometimes it may not be a good practice to only choose one model with low WAIC or LOO-IC, especially when several models have...
Read more >
blavaan: Bayesian Latent Variable Analysis
Description Fit a variety of Bayesian latent variable models, including confirmatory factor analysis, structural equation models, ...
Read more >
Model for a latent exogenous variable and all other observed ...
If they are all observed variables, a multiple regression is the way to see the effect of the IV on the DV. Then,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found