lecture 2 basic bayes and two stage normal … bayes and two stage normal normal model… diagnostic...

45
Lecture 2 Basic Bayes and two stage normal normal model…

Upload: hakhuong

Post on 31-Aug-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Lecture 2Basic Bayes and two stage

normal normal model…

Page 2: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Diagnostic Testing

Page 3: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Diagnostic Testing

Ask

Marilyn®

BY MARILYN VOS SAVANT

A particularly interesting and important question today is that of testing for drugs. Suppose it is assumed that about 5% of the general population uses

drugs. You employ a test that is 95% accurate, which we’ll say means that if the individual is a user, the test will be positive 95% of the time, and if the individual is a nonuser, the test will be negative 95% of the time. A person is

selected at random and is given the test. It’s positive. What does such a result suggest? Would you conclude that the individual is a drug user?

What is the probability that the person is a drug user?

Page 4: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

a

d

True positives

True negatives

Disease StatusTest Outcome

Diagnostic Testing

False positives

False negativesc

b

Page 5: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Diagnostic Testing

• “The workhorse of Epi”: The 2 × 2 table

a + b + c + db + da + cTotal

c + d dcTest -

a + bbaTest +

TotalDisease -Disease +

Page 6: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Diagnostic Testing

• “The workhorse of Epi”: The 2 × 2 table

a + b + c + db + da + cTotal

c + d dcTest -

a + bbaTest +

TotalDisease -Disease +

ca

aDPSens

+=+= )|(

db

dDPSpec

+=−= )|(

Page 7: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Diagnostic Testing

• “The workhorse of Epi”: The 2 × 2 table

a + b + c + db + da + cTotal

c + d dcTest -

a + bbaTest +

TotalDisease -Disease +

ca

aDPSens

+=+= )|(

db

dDPSpec

+=−= )|(

ba

aDPPPV

+=+= )|(

dc

dDPNPV

+=−= )|(

positive

predicted value

negative

predicted value

Page 8: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Diagnostic Testing

• Marilyn’s Example

100095050Total

905 9032Test -

954748Test +

TotalDisease -Disease +

PPV = 51%

NPV = 99%

Sens = 0.95

Spec = 0.95

P(D) = 0.05

Page 9: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Diagnostic Testing

• Marilyn’s Example

1000800200Total

770 76010Test -

23040190Test +

TotalDisease -Disease +

PPV = 83%

NPV = 99%

Sens = 0.95 = 190/200

Spec = 0.95 = 760/800

P(D) = 0.20

Point: PPV depends on prior probability of disease in the population

Page 10: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Diagnostic Testing & Bayes Theorem

•P(D): prior distribution, that is, the prevalence of disease in the population•P(+|D): likelihood function, that is, the probability ofpositive test given that the person has the disease

(specificity)•P(D|+): positive predicted value, that is, the probabilitythat, given that the test is positive, the person has the disease (posterior probability)

P(D | +) =P(+ | D)P(D)

P(+)

P(+) = P(+ | D)P(D) + P(+ | D )P(D )

0.95 0.20

0.23

Page 11: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Bayes & MLMs…

Page 12: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

A Two-stage normal normal model

y ij = θ j + ε ij

i = 1,..., n j , j = 1,.., J

ε ij ~ N (0,σ 2)

θ j ~ N (θ ,τ 2)

unit within the cluster

cluster

cluster-specific random effect

within cluster variance

between clusters varianceof the “true” cluster specific

means (heterogeneity parameter)

overall mean

Page 13: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Terminology

• Two stage normal normal model

• Variance component model• Two-way random effects ANOVA• Hierarchical model with a random intercept and no covariates

Are all the same thing!

Page 14: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Testing in Schools

• Goldstein and Spiegelhalter JRSS (1996)

• Goal: differentiate between `good' and `bad‘ schools

• Outcome: Standardized Test Scores

• Sample: 1978 students from 38 schools

– MLM: students (obs) within schools (cluster)

• Possible Analyses:

1. Calculate each school’s observed average score (approach A)

2. Calculate an overall average for all schools (approach B)

3. Borrow strength across schools to improve individual school

estimates (Approach C)

Page 15: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Shrinkage estimation

• Goal: estimate the school-specific average

score

• Two simple approaches:

– A) No shrinkage

– B) Total shrinkage

θ j

y j =1

n j

y ij

i=1

n j

y =

n j

σ 2y j

j=1

J

n j

σ 2

j=1

J

Page 16: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

ANOVA and the F test

• To decide which estimate to use, a traditional

approach is to perform a classic F test for

differences among means

• if the group-means appear significant variable

then use A

• If the variance between groups is not

significant greater that what could be

explained by individual variability within

groups, then use B

Page 17: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Shrinkage Estimation: Approach C

• We are not forced to choose between A and B

• An alternative is to use the a weighted combination between A and B

ˆ θ j = λ j y j + (1− λ j )y

λ j =τ 2

τ 2 + σ j

2;σ j

2 = σ 2/n j

Empirical Bayes estimate

Page 18: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Shrinkage estimation

• Approach C reduces to approach A (no

pooling) when the shrinkage factor is equal to

1, that is, when the variance between groups

is very large

• Approach C reduces to approach B,

(complete pooling) when the shrinkage factor

is equal to 0, that is, when the variance

between group is close to be zero

Page 19: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

A Case study: Testing in Schools

• Why borrow across schools?

• Median # of students per school: 48, Range: 1-

198

• Suppose small school (N=3) has: 90, 90,10

(avg=63)

• Difficult to say, small N ⇒ highly variable

estimates

• For larger schools we have good estimates, for

smaller schools we may be able to borrow

information from other schools to obtain more

accurate estimates

Page 20: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

0 1 0 2 0 3 0 4 0

02

04

06

08

01

00

s cho o l

sco

reTesting in Schools

Model:

Mean Scores & C.I.s for Individual Schools

µ

bj

E(Yij ) = θ j = µ + b j

Page 21: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Fixed and Random Effects

• Standard regression models: εij ~ N(0,σ2)

Yij = µ + εij E(Yij)=µ (overall average)

Yij = µ + b*j + εij E(Yij)=θj (observed school avgs)

• A random effects model:

Yij | bj = µ + bj + εij, where: bj ~ N(0,τ2)

Fixed Effects

Random Effects:

Page 22: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Testing in Schools: Shrinkage Plot

0 1 0 2 0 3 0 4 0

02

04

06

08

01

00

s cho o l

sco

re

D i re c t S a m p le E s tsB a ye s S hrunk E s ts

µ

b*j

bj

Page 23: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Some Bayes Concepts

• Frequentist: Parameters are “the truth”

• Bayesian: Parameters have a distribution

• “Borrow Strength” from other observations

• “Shrink Estimates” towards overall averages

• Compromise between model & data

• Incorporate prior/other information in estimates

• Account for other sources of uncertainty

Page 24: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Relative Risks for Six Largest Cities

.2025

.1600

.3025

.0169

.0625

.0169

Statistical

Variance

0.451.0San Diego

0.400.45Houston

0.550.25Dallas/Ft Worth

0.130.60Chicago

0.251.4New York

0.130.25Los Angeles

Statistical

Standard Error

RR Estimate (%

per 10

micrograms/ml

City

Approximate values read from graph in Daniels, et al. 2000. AJE

y j σ j σ j

2

Page 25: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

*

*

*

**

*

-2-1

01

23

4C ity -s p e c ific M L E s fo r L o g R e la tiv e R is k s

Pe

rce

nt C

ha

ng

e

Point estimates (MLE) and 95% CI of the airPollution effects in the six cities

Page 26: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Two-stage normal normal model

y j = θ j + ε j

ε j ~ N(0,σ j

2)

θ j ~ N(θ,τ 2)

RR estimate in city j True RR in city j

Within city statisticalUncertainty (known)

Heterogeneity acrosscities in the true RR

Page 27: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Two sources of variance

y j = θ j + ε j

θ j = µ + b j

y j = µ + b j + ε j

V (y j ) = V (b j ) + V (ε j ) = τ 2 + σ j

2

λ j =τ 2

τ 2 + σ j

2shrinkage factor

Totalvariance

Variancebetween

Variancewithin

Page 28: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

0

0 0

00 0

-2-1

01

23

4

C ity -s p e c ific M L E s fo r L o g R e la tiv e R is k s (*) a n d T r u e V a lu e s (o )

c i ty

Pe

rce

nt C

ha

ng

e

Page 29: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

0

0 0

00 0

-2-1

01

23

4

C ity -s p e c ific M L E s fo r L o g R e la tiv e R is k s (*) a n d T r u e V a lu e s (o )

c i ty

Pe

rcen

t C

ha

ng

e

*

*

*

**

*

Page 30: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

*

*

*

**

*

-2-1

01

23

4

C ity -s p e c ific M L E s fo r L o g R e la tiv e R is k s

c i ty

Pe

rce

nt C

ha

ng

e

Page 31: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

*

*

*

**

*

-2-1

01

23

4

C ity -s p e c ific M L E s fo r L o g R e la tiv e R is k s

c i ty

Pe

rce

nt C

ha

ng

e

Page 32: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Estimating Overall Mean

• Idea: give more weight to more precise values

• Specifically, weight estimates inversely proportional to their variances

Page 33: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Estimating the overall mean

(Der Simonian and Laird, Controlled Clinical Trial 1986)

ˆ τ 2 =1

J − 1( y j − y ) 2 −

1

Jσ j

2

j

∑j

h j =1

σ j

2 + τ 2; w j = h j / h j

j

ˆ µ =

w j y j

j

w j

j

∑;V ( ˆ µ ) =

1

w j

j

“crude” estimate of

the heterogeneity

parameter

Page 34: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Calculations for Empirical Bayes Estimates (redo this using the “meta”

function in stata..)

1.0037.30.65Over-

all

.09

.11

.07

.27

.18

.27

wj

3.5

4.1

2.6

10.1

6.9

10.1

1/TV

.285

,243

.385

.0994

.145

.0994

Total

Var

(TV)

.2025

.160

.3025

.0169

.0625

.0169

Stat Var

1.0SD

0.45Hou

0.25Dal

0.60Chi

1.4NYC

0.25LA

RRCity

overall = .27* 0.25 + .18*1.4 + .27*0.60 + .07*0.25 + .11*0.45 + 0.9*1.0 =

0.65

Page 35: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Software in R

yj <-c(0.25,1.4,0.60,0.25,0.45,1.0)

sigmaj <- c(0.13,0.25,0.13,0.55,0.40,0.45)

tausq <- var(yj) - mean(sigmaj^2)

TV <- sigmaj^2 + tausq

tmp<- 1/TV

ww <- tmp/sum(tmp)

v.muhat <- sum(ww)^{-1}

muhat <- v.muhat*sum(yj*ww)

Page 36: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Two Extremes

• Natural variance >> Statistical variance

– Weights wj approximately constant

– Use ordinary mean of estimates regardless

of their relative precision

• Statistical variance >> Natural variance

– Weight each estimator inversely

proportional to its statistical variance

Page 37: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Empirical Bayes Estimation

ˆ θ j = λ j y j + (1− λ j ) ˆ µ

λ j =τ 2

τ 2 + σ j

2

Page 38: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Calculations for Empirical Bayes Estimates

0.160.651.0037.31/37.3=

0.027

0.65Over-

all

0.24

0.23

0.25

0.12

0.19

0.12

0.75

0.58

0.56

0.61

1.1

0.32

.29

.34

.21

.83

.57

.83

.09

.11

.07

.27

.18

.27

3.5

4.1

2.6

10.1

6.9

10.1

1/TV

.285

,243

.385

.0994

.145

.0994

Total

Var

.2025

.160

.3025

.0169

.0625

.0169

Stat Var

1.0SD

0.45Hou

0.25Dal

0.60Chi

1.4NYC

0.25LA

RRCityλ j

ˆ θ j se( ˆ θ j )w j

0.83x0.25 + (1-0.83)x0.65

se ( ˆ θ j ) =1

σ j

2+

1

τ 2

−1

Page 39: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

*

*

*

**

*

-2-1

01

23

4

C ity -s p e c ific M L E s fo r L o g R e la tiv e R is k s

c i ty

Pe

rce

nt C

ha

ng

e

Page 40: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

*

*

*

**

*

-2-1

01

23

4

C ity -s p e c ific M L E s (L e ft) a n d E m p ir ic a l B a y e s E s tim a te s (R ig h t)

c i ty

Pe

rcen

t C

ha

ng

e

Page 41: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

* *** * *

0 .0 0 .5 1 .0 1 .5 2 .0

S h r in k a g e o f E m p ir ic a l B a y e s E s tim a te s

P e rc e nt Inc re a s e in M o rta li ty

o oooo o

Maximum likelihood estimates

Empirical Bayes estimates

Page 42: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

0 .0 0 .2 0 .4 0 .6 0 .8 1 .0

-0.5

0.0

0.5

1.0

1.5

2.0

2.5

S e n s itiv ity o f E m p ir ic a l B a y e s E s tim a te s

N a tura l V a ria nc e

Re

lative

Ris

k

ˆ µ

y j

τ 2

Page 43: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Key Ideas

• Better to use data for all cities to estimate the relative risk for a particular city

– Reduce variance by adding some bias

– Smooth compromise between city specific estimates and overall mean

• Empirical-Bayes estimates depend on measure of natural variation

– Assess sensitivity to estimate of NV (heterogeneity parameter )τ 2

Page 44: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

Caveats

• Used simplistic methods to illustrate the key ideas:

– Treated natural variance and overall estimate as known when calculating uncertainty in EB estimates

– Assumed normal distribution or true relative risks

• Can do better using Markov Chain Monte Carlo methods – more to come

Page 45: Lecture 2 Basic Bayes and two stage normal … Bayes and two stage normal normal model… Diagnostic Testing Diagnostic Testing Ask Marilyn ® BY MARILYN VOS SAVANT A particularly

In Stata (see 1.4 and 1.6, also Lab 1)

• xtreg with the mle option

• xtmixed: preferred for continuous

outcomes

• gllamm