bayesian panel data - prof. hedibert freitas lopes,...

18
1 BAYESIAN PANEL DATA Hedibert Freitas Lopes Graduate School of Business University of Chicago I took the following three examples from the WinBugs list of examples. Both WinBugs and the examples can be found at the The BUGS Project - Bayesian inference Using Gibbs Sampling site: http://www.mrcbsu.cam.ac.uk/bugs/welcome.shtml Example 1: Orange Trees, Non-linear growth curve This dataset was originally presented by Draper and Smith (1981) and reanalysed by Lindstrom and Bates (1990). The data Yij consist of trunk circumference measurements recorded at time xj, j=1,...,7 for each of i = 1,..., 5 orange trees. Example 2: London schools Goldstein et al. (1993) present an analysis of examination results from inner London schools. They use hierarchical or multilevel models to study the between-school variation, and calculate school- level residuals in an attempt to differentiate between `good' and `bad' schools. Example 3: Repeated measures on Poisson counts Breslow and Clayton (1993) analyse data initially provided by Thall and Vail (1990) concerning seizure counts in a randomised trial of anti-convulsant threrapy in epilepsy. The table below shows the successive seizure counts for 59 patients. Covariates are treatment (0,1), 8-week baseline seizure counts, and age in years.

Upload: vanphuc

Post on 22-Mar-2018

216 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: BAYESIAN PANEL DATA - Prof. Hedibert Freitas Lopes, …hedibert.org/wp-content/uploads/2013/12/nonlinearpanel-winbugs.pdf · 1 BAYESIAN PANEL DATA Hedibert Freitas Lopes Graduate

1

BAYESIAN PANEL DATA Hedibert Freitas Lopes

Graduate School of BusinessUniversity of Chicago

I took the following three examples from the WinBugs list of examples. Both WinBugsand the examples can be found at the The BUGS Project - Bayesian inference Using Gibbs Sampling site: http://www.mrcbsu.cam.ac.uk/bugs/welcome.shtml

Example 1: Orange Trees, Non-linear growth curveThis dataset was originally presented by Draper and Smith (1981) and reanalysed by Lindstrom and

Bates (1990). The data Yij consist of trunk circumference measurements recorded at time xj, j=1,...,7 for each of i = 1,..., 5 orange trees.

Example 2: London schoolsGoldstein et al. (1993) present an analysis of examination results from inner London schools. They

use hierarchical or multilevel models to study the between-school variation, and calculate school-level residuals in an attempt to differentiate between `good' and `bad' schools.

Example 3: Repeated measures on Poisson countsBreslow and Clayton (1993) analyse data initially provided by Thall and Vail (1990) concerning seizure

counts in a randomised trial of anti-convulsant threrapy in epilepsy. The table below shows the successive seizure counts for 59 patients. Covariates are treatment (0,1), 8-week baseline seizure counts, and age in years.

Page 2: BAYESIAN PANEL DATA - Prof. Hedibert Freitas Lopes, …hedibert.org/wp-content/uploads/2013/12/nonlinearpanel-winbugs.pdf · 1 BAYESIAN PANEL DATA Hedibert Freitas Lopes Graduate

Example 1: Non-linear growth curveThis dataset was originally presented by Draper and Smith (1981) and

reanalysed by Lindstrom and Bates (1990). The data Yij consist of trunk circumference measurements recorded at time xj, j=1,...,7 for each of i = 1,..., 5 orange trees. We consider a logistic growth curve as follows:

-------------------------------------------j xj y1j y2j y3j y4j y5j-------------------------------------------1 118 30 33 30 32 302 484 58 69 51 62 493 664 87 111 75 112 814 1004 115 156 108 167 1255 1231 120 172 115 179 1426 1372 142 203 139 209 1747 1582 145 203 140 214 177-------------------------------------------

2

Page 3: BAYESIAN PANEL DATA - Prof. Hedibert Freitas Lopes, …hedibert.org/wp-content/uploads/2013/12/nonlinearpanel-winbugs.pdf · 1 BAYESIAN PANEL DATA Hedibert Freitas Lopes Graduate

3

Time x trunk circumference

Page 4: BAYESIAN PANEL DATA - Prof. Hedibert Freitas Lopes, …hedibert.org/wp-content/uploads/2013/12/nonlinearpanel-winbugs.pdf · 1 BAYESIAN PANEL DATA Hedibert Freitas Lopes Graduate

Model and prior distribution

3

11

2

1 1 2 2 3 3

~ ,1

where log( ), log( 1), and log( )

i j

iij Cx

i

i i i i i i

y Neφ

φ τφ

θ φ θ φ θ φ

−⎛ ⎞⎜ ⎟⎜ ⎟+⎝ ⎠

= = + = −

11 1 1

12 2 2

13 3 3

0 0, 0 0

0 0

~ (0,1000)~ (0.001,0.001)~ (0.001,0.001)

i

i

C

N

NGG

θ µ τθ µ τθ µ τ

µττ

⎡ ⎤⎛ ⎞⎛ ⎞ ⎛ ⎞⎢ ⎥⎜ ⎟⎜ ⎟ ⎜ ⎟⎢ ⎥⎜ ⎟⎜ ⎟ ⎜ ⎟

⎜ ⎟ ⎜ ⎟⎢ ⎥⎜ ⎟⎝ ⎠ ⎝ ⎠ ⎝ ⎠⎣ ⎦

4

Page 5: BAYESIAN PANEL DATA - Prof. Hedibert Freitas Lopes, …hedibert.org/wp-content/uploads/2013/12/nonlinearpanel-winbugs.pdf · 1 BAYESIAN PANEL DATA Hedibert Freitas Lopes Graduate

5

BUGS codemodel

for (i in 1:K) for (j in 1:n)

Y[i, j] ~ dnorm(eta[i, j], tauC)eta[i, j] <- phi[i, 1] / (1 + phi[i, 2] * exp(phi[i, 3] * x[j]))

phi[i, 1] <- exp(theta[i, 1])phi[i, 2] <- exp(theta[i, 2]) - 1phi[i, 3] <- -exp(theta[i, 3]) for (k in 1:3)

theta[i, k] ~ dnorm(mu[k], tau[k])

tauC ~ dgamma(1.0E-3, 1.0E-3)sigmaC <- 1 / sqrt(tauC)varC <- 1 / tauCfor (k in 1:3)

mu[k] ~ dnorm(0, 1.0E-4)tau[k] ~ dgamma(1.0E-3, 1.0E-3)sigma[k] <- 1 / sqrt(tau[k])

Page 6: BAYESIAN PANEL DATA - Prof. Hedibert Freitas Lopes, …hedibert.org/wp-content/uploads/2013/12/nonlinearpanel-winbugs.pdf · 1 BAYESIAN PANEL DATA Hedibert Freitas Lopes Graduate

6

Data and initial valueslist(n=7,K=5,x=c(118.00,484.00,664.00,1004.00,1231.00,1372.00,1582.00),

Y=structure(.Data=c(30.00,58.00,87.00,115.00,120.00,142.0,145.00,33.00,69.00,111.00,156.00,172.00,203.00,203.00,30.00,51.00,75.00,108.00,115.00,139.00,140.00,32.00,62.00,112.00,167.00,179.00,209.00,214.00,30.00,49.00, 81.00,125.00,142.00,174.00,177.00),.Dim=c(5, 7)))

list(theta=structure(.Data=c(5,2,-6,5,2,-6,5,2,-6,5, 2, -6,5,2,-6),.Dim=c(5, 3)),mu=c(5,2,-6),tau=c(20,20,20), tauC=20)

Page 7: BAYESIAN PANEL DATA - Prof. Hedibert Freitas Lopes, …hedibert.org/wp-content/uploads/2013/12/nonlinearpanel-winbugs.pdf · 1 BAYESIAN PANEL DATA Hedibert Freitas Lopes Graduate

7

Page 8: BAYESIAN PANEL DATA - Prof. Hedibert Freitas Lopes, …hedibert.org/wp-content/uploads/2013/12/nonlinearpanel-winbugs.pdf · 1 BAYESIAN PANEL DATA Hedibert Freitas Lopes Graduate

8

Saving MCMC sequences

Page 9: BAYESIAN PANEL DATA - Prof. Hedibert Freitas Lopes, …hedibert.org/wp-content/uploads/2013/12/nonlinearpanel-winbugs.pdf · 1 BAYESIAN PANEL DATA Hedibert Freitas Lopes Graduate

9

Posterior densities independent prior

Page 10: BAYESIAN PANEL DATA - Prof. Hedibert Freitas Lopes, …hedibert.org/wp-content/uploads/2013/12/nonlinearpanel-winbugs.pdf · 1 BAYESIAN PANEL DATA Hedibert Freitas Lopes Graduate

Posterior densities multivariate prior

1 2 3 1 2 3

3 3

13

( , , ) ', ( , , )| , ( , )~ (0 ,100000 )

~ (3,0.1 )~ (0.001,0.001)C

NN I

Wishart IG

θ θ θ θ µ µ µ µθ µ µµ

τ

= =

Σ Σ

Σ

10

Page 11: BAYESIAN PANEL DATA - Prof. Hedibert Freitas Lopes, …hedibert.org/wp-content/uploads/2013/12/nonlinearpanel-winbugs.pdf · 1 BAYESIAN PANEL DATA Hedibert Freitas Lopes Graduate

11

Posterior predictive Independent x multivariate priors

Page 12: BAYESIAN PANEL DATA - Prof. Hedibert Freitas Lopes, …hedibert.org/wp-content/uploads/2013/12/nonlinearpanel-winbugs.pdf · 1 BAYESIAN PANEL DATA Hedibert Freitas Lopes Graduate

12

Example 2: Multivariate hierarchical modelGoldstein et al. (1993) present an analysis of examination results from inner

London schools. They use hierarchical or multilevel models to study the between-school variation, and calculate school-level residuals in an attempt to differentiate between `good' and `bad' schools.

Standardized mean examination scores (Y) were available for 1978 pupils from 38 different schools. The median number of pupils per school was 48, with a range of 1--198.

Pupil-level covariates included gender plus a standardized London Reading Test (LRT) score and a verbal reasoning (VR) test category (1, 2 or 3, where 1 represents the highest ability group) measured when each child was aged 11. Each school was classified by gender intake (all girls, all boys or mixed) and denomination (Church of England, Roman Catholic, State school or other); these were used as categorical school-level covariates.

LTR:London Reading Test (LRT) ;VR: verbal reasoning (VR) testGirl: gender;G:Girls' school;B:Boys' school;CE:CE school;RC: RC school;OS:other school.

Page 13: BAYESIAN PANEL DATA - Prof. Hedibert Freitas Lopes, …hedibert.org/wp-content/uploads/2013/12/nonlinearpanel-winbugs.pdf · 1 BAYESIAN PANEL DATA Hedibert Freitas Lopes Graduate

13

Model and prior distribution

( )ij

1

1ij

1 2 3 1 2 3 4

y :standardized mean examination scores, for pupil i and school j.

~ ( , ) ,

log( )= + LRT

( , , ) ', ( , , , ,

T T Tij ij j ij j ij

ij

j j j j

y N x z wα β τ

τ θ φ

α α α α β β β β δ δ

+

= = 5 6 7 8

2

1 13 3 0

10

, , , ) '

(1,LTR ,VR1 ); (LTR ,VR2 ,Girl ); (G ,B ,CE ,RC ,OS )

~ (0,10000), ~ (0,10000), ~ (0,10000), ~ ( , ),

~ (0 ,1000 ), ~ (3, )0.1 0.005 0.005

0.005 0.1 0.0050.005 0.0

ij

T T Tij ij ij ij ij ij j j j j j j

j j

x z w

N N N N

N I W

δ δ δ

β θ φ α γ

γ − −

= = =

Ω

Ω Ω

Ω =05 0.1

⎛ ⎞⎜ ⎟⎜ ⎟⎜ ⎟⎝ ⎠

Page 14: BAYESIAN PANEL DATA - Prof. Hedibert Freitas Lopes, …hedibert.org/wp-content/uploads/2013/12/nonlinearpanel-winbugs.pdf · 1 BAYESIAN PANEL DATA Hedibert Freitas Lopes Graduate

14

Prior - WinBugs code#Priors for fixed effects:for (k in 1 : 8)

beta[k] ~ dnorm(0.0, 0.0001)theta ~ dnorm(0.0, 0.0001)phi ~ dnorm(0.0, 0.0001)

# Priors for random coefficients:for (j in 1 : M)

alpha[j,1:3] ~ dmnorm(gamma[1:3 ], T[1:3 ,1:3 ]); alpha1[j] <- alpha[j,1]

# Hyper-priors:gamma[1:3] ~ dmnorm(mn[1:3 ], prec[1:3 ,1:3 ]);T[1:3 ,1:3 ] ~ dwish(R[1:3 ,1:3 ], 3)

mn = c(0, 0, 0)prec = structure(.Data = c(0.0001, 0, 0, 0, 0.0001, 0, 0,0, 0.0001), .Dim = c(3, 3))R = structure(.Data = c(0.1, 0.005, 0.005, 0.005, 0.1, 0.005, 0.005, 0.005, 0.1), .Dim = c(3, 3))

Page 15: BAYESIAN PANEL DATA - Prof. Hedibert Freitas Lopes, …hedibert.org/wp-content/uploads/2013/12/nonlinearpanel-winbugs.pdf · 1 BAYESIAN PANEL DATA Hedibert Freitas Lopes Graduate

15

A 1000 update burn in followed by a further 10000 updates gave the parameter estimates

Page 16: BAYESIAN PANEL DATA - Prof. Hedibert Freitas Lopes, …hedibert.org/wp-content/uploads/2013/12/nonlinearpanel-winbugs.pdf · 1 BAYESIAN PANEL DATA Hedibert Freitas Lopes Graduate

16

Example 3: Poisson hierarchical model

Breslow and Clayton (1993) analyse data initially provided by Thall and Vail (1990) concerning seizure counts in a randomised trial of anti-convulsantthrerapy in epilepsy. The table below shows the successive seizure counts for 59 patients. Covariates are:

• treatment (0,1)• 8-week baseline seizure counts, • age in years. The structure of this data is shown below

Patient y1 y2 y3 y4 Trt Base Age1 5 3 3 3 0 11 312 3 5 3 3 0 11 303 2 4 0 5 0 6 254 4 4 1 4 0 8 36....8 40 20 21 12 0 52 429 5 6 6 5 0 12 37....59 1 4 3 2 1 12 37

Page 17: BAYESIAN PANEL DATA - Prof. Hedibert Freitas Lopes, …hedibert.org/wp-content/uploads/2013/12/nonlinearpanel-winbugs.pdf · 1 BAYESIAN PANEL DATA Hedibert Freitas Lopes Graduate

17

Page 18: BAYESIAN PANEL DATA - Prof. Hedibert Freitas Lopes, …hedibert.org/wp-content/uploads/2013/12/nonlinearpanel-winbugs.pdf · 1 BAYESIAN PANEL DATA Hedibert Freitas Lopes Graduate

18

A burn in of 5000 updates followed by a further 10000 updates gave the following parameter estimates