introduction to bayesian multilevel models (hierarchical ... · introduction to bayesian multilevel...

45
Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo Dept. of Astronomy, Cornell University http://www.astro.cornell.edu/staff/loredo/ IAC Winter School, 3–4 Nov 2014 1 / 44

Upload: others

Post on 08-Aug-2020

26 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Introduction to Bayesian multilevel models(hierarchical Bayes/graphical models)

Tom LoredoDept. of Astronomy, Cornell University

http://www.astro.cornell.edu/staff/loredo/

IAC Winter School, 3–4 Nov 2014

1 / 44

Page 2: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

1970 baseball averagesEfron & Morris looked at batting averages of baseball players whohad N = 45 at-bats in May 1970 — ‘large’ N & includes RobertoClemente (outlier!)

Red = n/N maximum likelihood estimates of true averagesBlue = Remainder of season, Nrmdr ≈ 9N

'True'

Early season

Shrinkage

RMSE = 0.277

RMSE = 0.148

0.2 0.3 0.4

0.265

Cyan = James-Stein estimator: nonlinear, correlated, biasedBut better!

2 / 44

Page 3: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

0 0.1 0.2 0.3 0.4 0.5

Batting Average

0

5

10

15

20

Full-S

eason R

ank

Lines show closer estimateShrinkage closer 15/18

First 45 at-batsFull seasonShrinkage estimator

3 / 44

Page 4: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

0 0.1 0.2 0.3 0.4 0.5

Batting Average

0

5

10

15

20

Full-S

eason R

ank

Lines show closer estimateShrinkage closer 15/18

First 45 at-batsFull seasonShrinkage estimator

Theorem (independent Gaussian setting): In dimension >∼3, shrinkageestimators always beat independent MLEs in terms of expected RMS error

“The single most striking result of post-World War II statistical theory”— Brad Efron

3 / 44

Page 5: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Accounting For Measurement ErrorIntroduce latent/hidden/incidental parameters

Suppose f (x |θ) is a distribution for an observable, x .

From N precisely measured samples, {xi}, we can infer θ from

L(θ) ≡ p({xi}|θ) =∏

i

f (xi |θ)

p(θ|{xi}) ∝ p(θ)L(θ) = p(θ, {xi})

(A binomial point process)

4 / 44

Page 6: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Graphical representation

• Nodes/vertices = uncertain quantities (gray → known)

• Edges specify conditional dependence

• Absence of an edge denotes conditional independence

θ

x1 x2 xN

Graph specifies the form of the joint distribution:

p(θ, {xi}) = p(θ) p({xi}|θ) = p(θ)∏

i

f (xi |θ)

Posterior from BT: p(θ|{xi}) = p(θ, {xi})/p({xi})5 / 44

Page 7: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

But what if the x data are noisy, Di = {xi + ǫi}?

{xi} are now uncertain (latent) parametersWe should somehow incorporate ℓi(xi ) = p(Di |xi ):

p(θ, {xi}, {Di}) = p(θ) p({xi}|θ) p({Di}|{xi})

= p(θ)∏

i

f (xi |θ) ℓi (xi )

Marginalize over {xi} to summarize inferences for θ.Marginalize over θ to summarize inferences for {xi}.

Key point: Maximizing over xi and integrating over xi can givevery different results!

6 / 44

Page 8: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

To estimate x1:

p(x1|{x2, . . .}) =

dθ p(θ) f (x1|θ) ℓ1(x1)×

N∏

i=2

dxi f (xi |θ) ℓi (xi)

= ℓ1(x1)

dθ p(θ) f (x1|θ)Lm,1(θ)

≈ ℓ1(x1)f (x1|θ)

with θ determined by the remaining data (EB)

f (x1|θ) behaves like a prior that shifts the x1 estimate away fromthe peak of ℓ1(xi )

This generalizes the corrections derived by Eddington, Malmquistand Lutz-Kelker (sans selection effects)

(Landy & Szalay (1992) proposed adaptive Malmquist corrections thatcan be viewed as an approximation to this.)

7 / 44

Page 9: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Graphical representation

DND1 D2

θ

x1 x2 xN

p(θ, {xi}, {Di}) = p(θ) p({xi}|θ) p({Di}|{xi})

= p(θ)∏

i

f (xi |θ) p(Di |xi ) = p(θ)∏

i

f (xi |θ) ℓi(xi )

(sometimes called a “two-level MLM” or “two-level hierarchical model”)

8 / 44

Page 10: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Multilevel models

1 Conditional and marginal dependence/independence

2 Populations and multilevel modeling

3 MLMs for cosmic populations

9 / 44

Page 11: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Multilevel models

1 Conditional and marginal dependence/independence

2 Populations and multilevel modeling

3 MLMs for cosmic populations

10 / 44

Page 12: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Binomial counts

...

... n2 heads in N flips

n1 heads in N flips

Suppose we know n1 and want to predict n2

11 / 44

Page 13: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Predicting binomial counts — known α

Success probability α → p(n|α) = N!n!(N−n)!α

n(1− α)N−n ||N

Consider two successive runs of N = 20 trials, known α = 0.5

p(n2|n1, α) = p(n2|α) ||N

n1 and n2 are conditionally independent

0 5 10 15 20

n1

0

5

10

15

20n2

12 / 44

Page 14: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Model structure as a graph

• Circular nodes/vertices = a priori uncertain quantities(gray = becomes known as data)

• Edges specify conditional dependence

• Absence of an edge indicates conditional independence

α

n1 n2 nN

α

ni

⇐⇒

nN

N − 1

p({ni}|α) =∏

i

p(ni |α)

Knowing α lets you predict each ni , independently

13 / 44

Page 15: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Predicting binomial counts — uncertain α

Consider the same setting, but with α uncertain

Outcomes are physically independent, but n1 tells us about α →outcomes are marginally dependent:

p(n2|n1,N) =

dα p(α, n2|n1,N) =

dα p(α|n1,N) p(n2|α,N)

Flat prior on α

0 5 10 15 20

n1

0

5

10

15

20

n2

Prior: α = 0.5± 0.1

0 5 10 15 20

n1

0

5

10

15

20

n2

14 / 44

Page 16: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Graphical model — “Probability for everything”

α

n1 n2

Flow

of

Information

p(α, n1, n2) = π(α)∏

i

p(ni |α) ≡ π(α)∏

i

ℓi(α)member likelihood

From joint to conditionals:

p(α|n1, n2) =p(α, n1, n2)

p(n1, n2)=

π(α)∏

i ℓi (α)∫

dα π(α)∏

i ℓi(α)

p(n2|n1) =

dα p(α, n1, n2)

p(n1)

Observing n1 lets you learn about αKnowledge of α affects predictions for n2 → dependence on n1

15 / 44

Page 17: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Multilevel models

1 Conditional and marginal dependence/independence

2 Populations and multilevel modeling

3 MLMs for cosmic populations

16 / 44

Page 18: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

A population of coins/flippers

Each flipper+coin flips different number of times

17 / 44

Page 19: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

n1

θ

α1 α2 αN

n2 nN

Populationparameters

Successprobabilities

Data

p(θ, {αi}, {ni}) = π(θ)∏

i

p(αi|θ) p(ni|αi)

= π(θ)∏

i

p(αi|θ) ℓi(αi)

Terminology: θ are hyperparameters, π(θ) is the hyperprior

18 / 44

Page 20: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

A simple multilevel model: beta-binomial

Goal: Learn a population-level “prior” by pooling data

Qualitative

n1

θ

α1 α2 αN

n2 nN

Populationparameters

Successprobabilities

Data

p(θ, {αi}, {ni}) = π(θ)∏

i

p(αi|θ) p(ni|αi)

= π(θ)∏

i

p(αi|θ) ℓi(αi)

Quantitative

θ = (a, b) or (µ, σ)

π(θ) = Flat(µ, σ)

p(αi |θ) = Beta(αi |θ)

p(ni |αi) =

(

Ni

ni

)

αnii (1 − αi)

Ni−ni

19 / 44

Page 21: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Generating the population & data

Beta

distribution

(mean, conc'n)

Binomial

distributions

20 / 44

Page 22: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Likelihood function for one member’s α

21 / 44

Page 23: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Learning the population distribution

22 / 44

Page 24: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Lower level estimates

Two approaches

• Hierarchical Bayes (HB): Calculate marginals

p(αj |{ni}) ∝

dθ π(θ)∏

i 6=j

p(αi |θ) p(ni |αi )

• Empirical Bayes (EB): Plug in an optimum θ and estimate {αi}View as approximation to HB, or a frequentist procedure

23 / 44

Page 25: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Lower level estimates

Bayesian outlook

• Marginal posteriors are narrower than likelihoods

• Point estimates tend to be closer to true values than MLEs(averaged across the population)

• Joint distribution for {αi} is dependent

24 / 44

Page 26: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Frequentist outlook

• Point estimates are biased

• Reduced variance → estimates are closer to truth on average(lower MSE in repeated sampling)

• Bias for one member estimate depends on data for all othermembers

Lingo

• Estimates shrink toward prior/population mean

• Estimates “muster and borrow strength” across population(Tukey’s phrase); increases accuracy and precision of estimates

25 / 44

Page 27: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Population and member estimates

26 / 44

Page 28: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Competing data analysis goals

“Shrunken” member estimates provide improved & reliableestimate for population member properties

But they are under-dispersed in comparison to the true values →not optimal for estimating population properties∗

No point estimates of member properties are good for all tasks!

We should view data catalogs as providingdescriptions of member likelihood functions,

not “estimates with errors”

∗Louis (1984); Eddington noted this in 1940!

27 / 44

Page 29: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Multilevel models

1 Conditional and marginal dependence/independence

2 Populations and multilevel modeling

3 MLMs for cosmic populations

28 / 44

Page 30: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Observing and modeling cosmic populations

F

z

Observables Measurements CatalogPopulation

SelectionObservationMapping

Space: !" # # #

= precise = uncertain

L

r

Indicator scatter & Transformation bias

Measurement Error

Truncation & Censoring

F

z

F

Science goals• Density estimation: Infer the distribution of source

characteristics, p(χ)

• Regression/Cond’l density estimation: Infer relationshipsbetween different characteristics

• Map regression: Infer parameters defining the mapping fromcharacteristics to observables

Notably, seeking improved point estimates of source characteristics isseldom a goal in astronomy.

29 / 44

Page 31: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Number counts, luminosity functionsGRB peak fluxes

Loredo & Wasserman 1993, 1995, 1998:GRB luminosity/spatial dist’n viahierarchical Bayes

TNO magnitudes

Gladman+1998, 2001, 2008:TNO size distribution viahierarchical Bayes

30 / 44

Page 32: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

CB244 molecular cloud

Herschel data from Stutz+ 2010

SED properties vs. position

Kelly+2012: Dust parametercorrelations via hierarchical Bayes

β = power law modification indexExpect β → 0 for large grains

31 / 44

Page 33: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Measurement error models for cosmic populations

F

z

Observables Measurements CatalogPopulation

SelectionObservationMapping

Space: !" # # #

= precise = uncertain

L

r

Indicator scatter & Transformation bias

Measurement Error

Truncation & Censoring

F

z

F

32 / 44

Page 34: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Schematic graphical modelPopulationparametersθ

χ1 χ2

O1 O2

D2

χN

ON

DND1

Sourcecharacteristics

Sourceobservables

Data

= "Random variable" node (has pdf)

Becomes known (data)

= Conditional dependence

A directed acyclic graph (DAG)

Graph specifies the form of the joint distribution:

p(θ, {χi}, {Oi}, {Di}) = p(θ)∏

i

p(χi |θ) p(Oi |χi) p(Di |Oi )

Posterior from Bayes’s theorem:

p(θ, {χi}, {Oi}|{Di}) = p(θ, {χi}, {Oi}, {Di}) / p({Di})

33 / 44

Page 35: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Plates

Populationparametersθ θ

Di

Oi

χiχ1 χ2

O1 O2

D2

χN

ON

DND1

Sourcecharacteristics

Sourceobservables

Data

N

Plate

34 / 44

Page 36: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

“Two-level” effective models

Number countsO = flux

θ

Di

Oi

N

Calculate flux dist’n using“fundamental eqn” of stat astro

(Analytically/numericallymarginalize over χ = (L, r))

Dust SEDsχ = spectrum params

χi

θ

Di

N

Observables = fluxes in bandpassesFluxes are deterministic in χi

35 / 44

Page 37: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

From flips to fluxes

Simplified number counts model

• αi → source flux, Fi

• Upper level π(α) → logN–log S dist’n

• ni → counts in CCD pixels

⇒ “Eddington bias” in disguise,with both member and population inference

and uncertainty quantification

36 / 44

Page 38: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Another conjugate MLM: Gamma-Poisson

Goal: Learn a flux dist’n from photon counts

Qualitative

Populationparameters

Sourceproperties

Observed

data

θ

F1 F2 FN

n1 n2 nN

Quantitative

θ = (α, s) or (µ, σ)

π(θ) = Flat(µ, σ)

p(Fi |θ) = Gamma(Fi |θ)

p(ni |Fi ) = Pois(ni |ǫiFi )

37 / 44

Page 39: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Gamma-Poisson population and member estimates

0 50 100 150 200 250

F

0.000

0.002

0.004

0.006

0.008

0.010

0.012

0.014

0.016

0.018

p(F)

KLDML = 0.060 b

KLDShr = 0.179 b

KLDMLM = 0.031 b

True

ML

Shrunken pts

MLM

True

ML

EB

RMSE = 4.30

RMSE = 3.72

Simulations: N = 60 sources from gamma with 〈F 〉 = 100 and σF = 30;exposures spanning dynamic range of ×16

38 / 44

Page 40: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Benefits and requirements of cosmic MLMs

Benefits

• Selection effects quantified by non-detection data

• vs. V /Vmax and “debiasing” approaches

• Source uncertainties propagated via marginalization

• Adaptive generalization of Eddington/Malmquist “corrections”• No single adjustment addresses source & pop’n estimation

Requirements

• Data summaries for non-detection intervals(exposure, efficiency)

• Likelihood functions (not posterior dist’ns) for detected sourcecharacteristics(Perhaps a role for interim priors)

39 / 44

Page 41: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Some Bayesian MLMs in astronomySurveys (number counts/“logN–log S”/Malmquist):• GRB peak flux dist’n (Loredo & Wasserman 1998+)

• TNO/KBO magnitude distribution (Gladman+ 1998;Petit+ 2008)

• Malmquist-type biases in cosmology; MLM tutorial(Loredo & Hendry 2009 in BMIC book)

• “Extreme deconvolution” for proper motion surveys(Bovy, Hogg, & Roweis 2011)

• Exoplanet populations (2014 Kepler workshop)

Directional & spatio-temporal coincidences:• GRB repetition (Luo+ 1996; Graziani+ 1996)

• GRB host ID (Band 1998; Graziani+ 1999)

• VO cross-matching (Budavari & Szalay 2008)40 / 44

Page 42: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Linear regression with measurement error:

• QSO hardness vs. luminosity (Kelly 2007)

Time series:

• SN 1987A neutrinos, uncertain energy vs. time (Loredo& Lamb 2002)

• Multivariate “Bayesian Blocks” (Dobigeon, Tourneret &Scargle 2007)

• SN Ia multicolor light curve modeling (Mandel+ 2009+)

41 / 44

Page 43: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

How far we’ve comeSN 1987A neutrinos, 1990

Marked Poisson point processBackground,

thinning/truncation,measurement error

θ

D

t, ǫ

N

t, ǫ

D

N

Model checking viaexamining conditionalpredictive dist’ns

SN Ia light curvesMandel 2009, 2011

Nonlinear regression,Gaussian process regression,

measurement error

Model checking via cross validation

42 / 44

Page 44: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

SN IIP light curves (Sanders+ 2014)

43 / 44

Page 45: Introduction to Bayesian multilevel models (hierarchical ... · Introduction to Bayesian multilevel models (hierarchical Bayes/graphical models) Tom Loredo ... Graphical model —

Recap of Key Ideas

• Conditional & marginal dependence/independence

• Latent parameters for measurement error

• Graphical models, multilevel models, hyperparameters

• Beta-binomial & gamma-Poisson conjugate MLMs

• Shrinkage estimators (member point estimates)• Empirical Bayes• Hierarchical Bayes

• Member vs. population inference—competing goals

44 / 44