Markov chan Monte Carlo Rasmus Waagepetersen Department of Mathematcs Aalborg Unversty Denmark November, / Outlne for today MCMC / Condtonal smulaton for hgh-dmensonal U: Markov chan Monte Carlo Consder U = (U,...,U n ) N n (,Σ) wth Cov(U,U j ) = Σ j for all,j Then n-dmensonal condtonal densty for U Y = y: f (u,...,u n y) [ f (y u,...,u n )]f (u,...,u n ) Can not be factorzed nto lower dmensonal denstes. / Example: spatal statstcs (Chrstensen and Waagepetersen ) Observatons Y are weed counts at spatal locatons (x,y ) =,..., Coordnate Y (m) Coordnate X (m) 5 5 5 5 5 8 8 8 5 Y U s Posson where U random effect assocated wth (x,y ) (sol propertes). Cov(U,U j ) = τ exp( d j /α) where d j s dstance between (x,y ) and (x j,y j ) /
x x Example: quanttatve genetcs (Sorensen and Waagepetersen ) U, Ũ random genetc effects nfluencng sze and varablty of Y j : Y j sze of jth ltter of th pg. Y j U = u,ũ = ũ N (µ + u,exp( µ + ũ )) Hstogram x Pedgree z (U,...,U n,ũ,...,ũn) N(,G A) 8 5 5 ltter sze w v w Etc. pg wthout observaton. pg wth observaton. A: addtve genetc relatonshp matrx (dependng on pedgree). [ σa G = ] ρσ a σã ρσ a σã ρ: coeffcent of genetc correlaton between U and Ũ. NB: hgh dmenson n >. σ ã 5/ / MCMC Suppose U = (U,...,U n ) π( ) where π( ) s a complcated probablty dstrbuton. Markov chan Monte Carlo: Generate ergodc Markov chan so that U,U,U,... (U m = (U m,...,um n )) I.e. for large m, U m π( ) and dstrbuton of U m π( ) E π k(u) M k(u m ) m= Example: ergodc and non ergodc auto-regressve chans X = βx + ǫ ǫ N(,σ ) X = 5, σ =.5 and β ether. or.5: 5 8 8 t 8 NB: when β < we have convergence to statonary dstrbuton N(,σ /( β ). t / 8/
Jont updatng Metropols-Hastngs algorthm: Basc ngredent: proposal densty Some features of Metropols-Hastngs q(v u),v R n defned for all u R p and easy to sample. Gven ntal state U generate U,U,... as follows:. Condtonal on U m = u m generate proposal V m+ q( u m ).. Wth probablty mn{, π(v m+ )q(u V m+ ) π(u m )q(v m+ u m ) } accept U m+ = V m+ ; otherwse U m+ = u m. Even f π s very complcated probablty densty we may choose a smple proposal densty q (e.g. normal dstrbuton). Need only know π upto constant of proportonalty. If e.g. π(u) = f (u y) = f (y u)f (u) f (y) then we do not need to know margnal densty f (y) whch can often be hard to compute. Under mld condtons of rreducblty and aperodcty ths produces an ergodc Markov chan wth statonary dstrbuton gven by π( ). 9/ / Irreducblty and aperodcty Ex: random walk Metropols V m+ N(u m,σ prop) Irreducblty: chan can get from any part of the state space to any other apart of the state space (of postve π-probablty) Aperodc: chan not perodc. where σprop s the proposal varance. Then q(v u) = q(u v) so Metropols-Hastngs rato reduces to Metropols rato: mn{, π(v m+ )q(u V m+ ) π(u m )q(v m+ u m ) } = mn{, π(v m+ ) π(u m ) } / /
x Metropolzed AR() chan Comparson wth rejecton samplng β =.5 and σ =.5 but now ntroduce Metropols accept/reject n order to sample N(,.5/(. ). 5 Proposal for new state pertubaton of prevous state so easer to get accept. We reject some proposals to mantan statonary dstrbuton but do not throw away rejected states. Ths s at the expense that sample not uncorrelated. 8 t / / Smple example (Exercse ) π(u y) = = f (y exp(u + β))f (u;τ )/L(θ) where f (y λ) densty for Posson dstrbuton of ntensty λ. Convergence of Markov chans for smple example Plots of U,U,U,...: σ prop =. (accept rate %) σ prop = (accept rate %) Random walk Metropols rato (normalsng constant L(θ) = f (y;θ) cancels out): = f (y exp(v m+ + β))f (V m+ ;τ )/L(θ) = f (y = exp(u m + β)f (u m ;τ )/L(θ) = f (y exp(v m+ + β))f (V m+ ;τ ) = f (y exp(u m + β)f (u m ;τ ) sample..5..5. 8 Index sample.5..5..5. 8 Index NB: need only know π up to constant of proportonalty. 5/ /
Autocorrelaton/mxng Plot of autocorrelaton ρ(k) = Corr(U m,u m+k ): Sngle-ste Metropols-Hastngs Update one component n each teraton. σ prop =. (quck mxng) σ prop = (slow mxng) Update of th component:. Condtonal on U m = u m generate V m+ q ( u m ) and let Note: ACF.....8. 5 5 5 Lag Var M m= ACF U m = VarU M so small autocorrelaton advantageous......8. 5 5 5 Lag m= n= ρ( m n ). Wth probablty V m+ = (u m,...,um,vm+,u m +,...,um n ) mn{, π(v m+ )q (u m V m+ ) π(u m )q (V m+ u m ) } accept U m+ = V m+ ; otherwse U m+ = u m. Repeat for =,...,n / 8/ Examples MCMC ssues Random walk Metropols: V m+ N(u m,σ prop ) and mn{, π(v m+ )q (u m V m+ ) π(u m )q (V m+ u m ) } = mn{, π(v m+ ) π(u m ) } Gbbs sampler: V m+ U U j = u m j, j. Then q(v m+ u m ) = π (V m+ u m ) and π(v m+ )q (u m V m+ ) π(u m )q (V m+ u m ) so all proposals are accepted. = π (V m+ u m )π(um )π (u m u m ) π (u m u m )π(um )π (V m+ u m ) = when has chan reached equlbrum/statonary dstrbuton (burn-n) how long chans do we need (precson of Monte Carlo estmates)? These questons may be addressed by vsual nspecton of tmeseres and estmaton of Monte Carlo error. Ptfalls: hgh correlaton between components to be updated multmodalty No need to choose a proposal varance. 9/ /
Implementaton of MCMC usng BUGS (Bayesan analyss usng Gbbs samplng) Model specfcaton n BUGS: herarchcal/drected acyclc graph (DAG). Example: τ = σ =.5 U τ,σ N(,τ ) Y,Y U = u,τ,σ N(u,σ ) (Y,Y condtonally ndependent) model = { taunv <- sgmanv <- /.5 u ~ dnorm(.,taunv) y ~ dnorm(u,sgmanv) y ~ dnorm(u,sgmanv) } Exercses See exercses sheet on webpage. We can now sample (Y,Y,U), U Y,Y, Y,U Y etc. dependng on the data we specfy (whch varables to fx/condton on). / /