MCMC 2: Lecture 2 Coding and output. Phil O Neill Theo Kypraios School of Mathematical Sciences University of Nottingham

Similar documents
MCMC 2: Lecture 3 SIR models - more topics. Phil O Neill Theo Kypraios School of Mathematical Sciences University of Nottingham

Statistical Inference for Stochastic Epidemic Models

Robust MCMC Algorithms for Bayesian Inference in Stochastic Epidemic Models.

Advanced Statistical Modelling

Lecture 6: Markov Chain Monte Carlo

Bayesian Inference for Contact Networks Given Epidemic Data

Multilevel Statistical Models: 3 rd edition, 2003 Contents

arxiv: v1 [stat.co] 13 Oct 2017

STA 4273H: Statistical Machine Learning

(5) Multi-parameter models - Gibbs sampling. ST440/540: Applied Bayesian Analysis

Markov Chain Monte Carlo

Markov Chain Monte Carlo methods

Computational statistics

Bayesian Inference for Regression Parameters

A Bayesian Approach to Phylogenetics

Hierarchical models. Dr. Jarad Niemi. August 31, Iowa State University. Jarad Niemi (Iowa State) Hierarchical models August 31, / 31

Introduction to Probabilistic Machine Learning

CSC 2541: Bayesian Methods for Machine Learning

Markov Chain Monte Carlo, Numerical Integration

Lecture: Gaussian Process Regression. STAT 6474 Instructor: Hongxiao Zhu

The Metropolis-Hastings Algorithm. June 8, 2012

19 : Bayesian Nonparametrics: The Indian Buffet Process. 1 Latent Variable Models and the Indian Buffet Process

Computer Practical: Metropolis-Hastings-based MCMC

A Review of Pseudo-Marginal Markov Chain Monte Carlo

Monte Carlo in Bayesian Statistics

Metropolis-Hastings Algorithm

Markov Chain Monte Carlo

Markov Chain Monte Carlo (MCMC)

Bayesian Methods for Machine Learning

19 : Slice Sampling and HMC

Particle Filtering a brief introductory tutorial. Frank Wood Gatsby, August 2007

PATTERN RECOGNITION AND MACHINE LEARNING CHAPTER 2: PROBABILITY DISTRIBUTIONS

DAG models and Markov Chain Monte Carlo methods a short overview

Principles of Bayesian Inference

Bayesian inference and model selection for stochastic epidemics and other coupled hidden Markov models

Comparison of Three Calculation Methods for a Bayesian Inference of Two Poisson Parameters

Bayesian Inference for Normal Mean

Lecture 5. G. Cowan Lectures on Statistical Data Analysis Lecture 5 page 1

Markov Networks.

27 : Distributed Monte Carlo Markov Chain. 1 Recap of MCMC and Naive Parallel Gibbs Sampling

CSC 2541: Bayesian Methods for Machine Learning

Bayesian model selection in graphs by using BDgraph package

Non-Parametric Bayes

Introduction to Bayesian Statistics and Markov Chain Monte Carlo Estimation. EPSY 905: Multivariate Analysis Spring 2016 Lecture #10: April 6, 2016

David Giles Bayesian Econometrics

MCMC algorithms for fitting Bayesian models

Stat 516, Homework 1

Density Estimation. Seungjin Choi

Bayesian inference for stochastic multitype epidemics in structured populations using sample data

CTDL-Positive Stable Frailty Model

Part 8: GLMs and Hierarchical LMs and GLMs

Modelling Operational Risk Using Bayesian Inference

Bayesian inference for stochastic multitype epidemics in structured populations via random graphs

13: Variational inference II

Bayesian linear regression

Sampling Rejection Sampling Importance Sampling Markov Chain Monte Carlo. Sampling Methods. Oliver Schulte - CMPT 419/726. Bishop PRML Ch.

CSC321 Lecture 18: Learning Probabilistic Models

MCMC Review. MCMC Review. Gibbs Sampling. MCMC Review

Heriot-Watt University

Bayesian estimation of the basic reproduction number in stochastic epidemic models

Probabilistic Graphical Models

Part IV: Monte Carlo and nonparametric Bayes

Exponential families also behave nicely under conditioning. Specifically, suppose we write η = (η 1, η 2 ) R k R p k so that

Advanced Statistical Methods. Lecture 6

STA 294: Stochastic Processes & Bayesian Nonparametrics

LECTURE 15 Markov chain Monte Carlo

1 A simple example. A short introduction to Bayesian statistics, part I Math 217 Probability and Statistics Prof. D.

Theory of Stochastic Processes 8. Markov chain Monte Carlo

Log Gaussian Cox Processes. Chi Group Meeting February 23, 2016

ICML Scalable Bayesian Inference on Point processes. with Gaussian Processes. Yves-Laurent Kom Samo & Stephen Roberts

18 : Advanced topics in MCMC. 1 Gibbs Sampling (Continued from the last lecture)

CSC411 Fall 2018 Homework 5

Advances and Applications in Perfect Sampling

Bayesian Inference and MCMC

MCMC notes by Mark Holder

Markov Networks. l Like Bayes Nets. l Graph model that describes joint probability distribution using tables (AKA potentials)

Detection ASTR ASTR509 Jasper Wall Fall term. William Sealey Gosset

Chapter 8: Sampling distributions of estimators Sections

Creating Non-Gaussian Processes from Gaussian Processes by the Log-Sum-Exp Approach. Radford M. Neal, 28 February 2005

Estimating the Exponential Growth Rate and R 0

Subject CS1 Actuarial Statistics 1 Core Principles

Probabilistic Graphical Models Lecture 17: Markov chain Monte Carlo

Fundamental Issues in Bayesian Functional Data Analysis. Dennis D. Cox Rice University

STA 4273H: Statistical Machine Learning

The Metropolis Algorithm

Markov Chain Monte Carlo Lecture 4

Introduction to Machine Learning

MCMC: Markov Chain Monte Carlo

Bayesian Phylogenetics:

Markov Chain Monte Carlo

Contents. Part I: Fundamentals of Bayesian Inference 1

Introduction: MLE, MAP, Bayesian reasoning (28/8/13)

Answers and expectations

1 Using standard errors when comparing estimated values

Bayesian Gaussian Process Regression

Sampling Methods (11/30/04)

Bayesian Inference for DSGE Models. Lawrence J. Christiano

Foundations of Statistical Inference

Exercises Tutorial at ICASSP 2016 Learning Nonlinear Dynamical Models Using Particle Filters

Calibration of Stochastic Volatility Models using Particle Markov Chain Monte Carlo Methods

Transcription:

MCMC 2: Lecture 2 Coding and output Phil O Neill Theo Kypraios School of Mathematical Sciences University of Nottingham

Contents 1. General (Markov) epidemic model 2. Non-Markov epidemic model 3. Debugging tips 4. What to do with MCMC output

Contents 1. General (Markov) epidemic model 2. Non-Markov epidemic model 3. Debugging tips 4. What to do with MCMC output

1. General epidemic model Population of N individuals At time t there are: S t susceptibles I t infectives R t recovered / immune individuals Thus S t + I t + R t = N for all t. Initially (S 0, I 0,R 0 ) = (N-1,1,0).

1. General epidemic model Each infectious individual remains so for a length of time T I ~ Exp( ). During this time, infectious contacts occur with each susceptible according to a Poisson process of rate / N. Thus overall infection rate is S t I t / N. Two model parameters, and.

1. General epidemic model Let infection times be i 1 i 2 i 3... i n, where i 1 is time that initial infective begins their infectious period. Note that n = total number infected. Define i = (i 2, i 3,..., i n )

1. General epidemic model Let removal times be r 1 r 2 r 3... r n. Note that kth infection time need not correspond to the kth removal. Define r = (r 1, r 2,..., r n )

1. General epidemic model Recall the standard inference problem: we observe removal times and wish to perform Bayesian inference for and. Solution [as discussed in MCMC I ] is to use MCMC, treat missing infection times i 1 and i = (i 2, i 3,..., i n ) as latent variables.

1. General epidemic model The target posterior density is π (,, i 1, i r ) π (i, r,, i 1 ) π (,, i 1 ) posterior likelihood prior

1. General epidemic model Recall the likelihood: π (i, r,, i 1 ) = n j2 n rn ( β / N)S i j Iij γirj exp {( β / N)SI t t γit }dt j1 i1 product terms integral term Note that Sij here means S just before time i j.

1. General epidemic model Recall: if and Gamma a priori then both have Gamma full conditional distributions. e.g., i 1, i, r ( m + n -1, + N -1 SI ) where ( m, ) a priori. Thus and can be updated using a Gibbs step - i.e. according to their full conditional distributions - during an MCMC algorithm.

1. General epidemic model Recall that the unknown infection times are updated using a Metropolis-Hastings step. The acceptance probability requires us to calculate posterior likelihood prior

1. General epidemic model Thus to write an MCMC algorithm, it is necessary to be able to evaluate both the product and (integral) terms in the likelihood.

1. General epidemic model Product terms First note that n j n j n n n j n j γ β γ βn 1 r 2 i i 1 1 r 2 i i 1 j j j j j j I S I I S I n j n j n n γ β 1 r 2 i 1 j j I I 1) (N -1)(N - 2)...(N - n

1. General epidemic model Product terms Thus only the products of numbers of infectives may potentially change when updating the infection times. The product is most easily evaluated directly, i.e. by keeping track of changes to I t at each infection or removal event.

1. General epidemic model Integral terms I t dt = 1 k n (r k - i k ) S t I t dt = 1 k n 1 j N [(r k i j ) - (i k i j )] Here, a b denotes minimum of a,b. Also i j = for j > n, i.e. for those individuals never infected.

1. General epidemic model Integral terms Explanation: I t dt = 1 k n 1 {k is infective at time t} dt = 1 k n 1 {k is infective at time t} dt where 1 A = 1 if event A occurs = 0 otherwise

1. General epidemic model Integral terms Recall that individual k is removed at r k. Suppose their infection time is i L(k). Then 1 {k is infective at time t} dt = total time k is infective = (r k i L(k) )

1. General epidemic model Integral terms Then I t dt = 1 k n (r k i L(k) ) = 1 k n r k - 1 k n i L(k) = 1 k n r k - 1 k n i k = 1 k n (r k - i k )

1. General epidemic model Integral terms S t I t dt = 1 k n 1 j N [(r k i j ) - (i k i j )] Similar arguments used to derive this

1. General epidemic model Integral terms [(r k i j ) - (i k i j )] = time that k is infective and j is susceptible [(r k i j ) - (i k i j )] = r k - i k if i j > r k (e.g. i j = ) [(r k i j ) - (i k i j )] = i j - i k [(r k i j ) - (i k i j )] = 0 if i k < i j < r k if i j < i k

Contents 1. General (Markov) epidemic model 2. Non-Markov epidemic model 3. Debugging tips 4. What to do with MCMC output

2. Non-Markov epidemic model We now consider a generalisation of the basic (Markov) SIR model in which the infectious periods are no longer exponentially distributed. This apparently minor change has a material impact on the likelihood calculations.

2. Non-Markov epidemic model Each infectious individual remains so for a length of time T I drawn from some specified distribution with parameter vector During this time, infectious contacts occur with each susceptible according to a Poisson process of rate / N. Thus overall infection rate is S t I t / N. Two model parameters, and.

2. Non-Markov epidemic model Likelihood Assume population contains N individuals of whom n ever become infective. Label the n infectives 1, 2,..., n and the other individuals n+1, n+2,..., N. Define r k and i k as the removal and infection times of individual k. Note these = if k never becomes infected.

2. Non-Markov epidemic model Likelihood Let b be the label of the last removal time, i.e. r b r k for all k = 1,..., n. Given removal data, b is observed and fixed for any given labelling. Define a as the label of the first infection time, i.e. i a i k for all k = 1,..., n. Given removal data, a is unknown.

2. Non-Markov epidemic model Likelihood Define r = (r 1, r 2,..., r n ) Define i = (i 1, i 2,..., i a-1, i a+1,..., i n ) Let f(x ) denote the probability density function (or mass function if appropriate) of the infectious period distribution with parameter vector.

2. Non-Markov epidemic model Likelihood π (i, r,, a, i a ) = ) ( }dt )SI / {( exp )I / ( 1 t 2 i t j j n j j r i n j i r f N β N β b a

2. Non-Markov epidemic model Bayesian inference π (,, a, i a, i r) π (i, r,, a, i a ) π (,, a, i a ) Thus we must specify a prior distribution for,, a, and i a.

2. Non-Markov epidemic model MCMC algorithm is updated as for the Markov model (i.e. Gibbs step, assuming has a Gamma prior) Infection times updated using a M-H step. One option is to propose (r k - i k ) from distribution of infectious period. updates depend on particular choice of infectious period distribution.

Contents 1. General (Markov) epidemic model 2. Non-Markov epidemic model 3. Debugging tips 4. What to do with MCMC output

3. Debugging tips 1. Test each piece of code separately Most MCMC algorithms in this field involve various components, e.g. Gibbs updates Metropolis-Hastings updates Likelihood It is good practice to check each component works before proceeding.

3. Debugging tips 2. Validate output using simulations As discussed in Lecture 1, one way to test MCMC code (e.g. for SIR model) is Simulate SIR model M times (e.g. M=1000) Run MCMC on each output to infer parameters Average parameter estimates from MCMC should be close to the known true values

3. Debugging tips 2. Validate output using simulations If the MCMC code is time-consuming to run then an alternative is use simulation output that gives a single large epidemic - idea being that this should give reasonable information about the model parameters.

3. Debugging tips 3. Beware Zeroes Some languages allow operations such as 0/0 without reporting an error.

3. Debugging tips 4. Try a very small data set Sometimes it is possible to test MCMC code by using a very small data set where one can work out the required inference by hand. This can then be checked against the MCMC output.

3. Debugging tips 5. Use log likelihood Many likelihoods require calculation of products which can in turn lead to numerical instabilities and run-time errors. One way to tackle this issue is to instead work with the log likelihood, since log( A 1 x A 2 x... x A m ) = log(a 1 )+...+ log(a m )

3. Debugging tips 5. Use log likelihood (cont) The likelihood may involve the calculation of Beta or Gamma functions. R has built-in functions to compute such functions, i.e. beta, gamma; but if we are working on the log scale, instead of doing something like log(gamma(k)) we could use another built in function lgamma(k) to ensure numerical stability, especially if k is large.

Contents 1. General (Markov) epidemic model 2. Non-Markov epidemic model 3. Debugging tips 4. What to do with MCMC output

4. What to do with MCMC output In this section, for illustration it is assumed that we have MCMC output from the Markov SIR model removal-data-observed scenario: ( 1, 1 ), ( 2, 2 ),..., ( M, M ), where M is large (e.g. M=10 6 ). Each pair ( k, k ) is (approx) a sample from the joint posterior density π (, r ).

4. What to do with MCMC output Marginal summaries Quantities such as the marginal mean, median, variance etc of and of can be readily obtained using the package R. It is also useful to plot the marginal posterior density of each parameter.

4. What to do with MCMC output Joint summaries It can be useful to assess the extent to which and can be estimated separately. The posterior correlation and a scatterplot of the samples against axes and provide such information.

4. What to do with MCMC output Functions of model parameters The quantity R 0 is of enormous interest in mathematical epidemic theory. It is (roughly) defined as the average number of secondary cases caused by a typical infective in an infinitely large population of susceptibles. If R 0 1, epidemics are unlikely to take off.

4. What to do with MCMC output Functions of model parameters For the (general) SIR model, R 0 = E(T I ), where E(T I ) is the mean infectious period. This follows from the fact that each infective causes new infections at (Poisson) rate during a period of time T I.

4. What to do with MCMC output Functions of model parameters For the Markov model we have since T I Exp( ). R 0 = E(T I ) = /, Thus given the MCMC output we can create a new file containing ( 1 / 1 ), ( 2 / 2 ),..., ( M / M ), i.e. samples from the posterior density of R 0.

4. What to do with MCMC output Functions of model parameters R 0 can be summarised in the usual ways (mean, variance etc): also interesting to find the posterior probability that R 0 1.

4. What to do with MCMC output Functions of model parameters Can also be interesting to translate inference for rates into inference for probabilities. e.g. 1 - exp(- / N) is the probability that one infective individual infects a given susceptible in one time unit.