# How to calculate likelihood for a bayesian model?

I am trying to do Bayesian posterior predictive checking, whereby I calculate the DIC for my fitted model, and compare to DIC from data simulated from the fitted model. I can get the DIC out of winBUGS, however I am not sure how to calculate the likelihood (for the DIC) outside of winBUGS (i.e., without fitting new models). All of the literature is quite general with respect to discrepancy functions for model checking, and have notation like p(D|theta) which I understand, but doesn't help me when I want to actually do the calculation.

Given a set of parameter values, and a Y_rep data set - how do I calculate the likelihood?

-
add comment

## 1 Answer

The likelihood is numerically equal to $\operatorname{P}(D\vert\theta)$, where D is the data vector and theta the parameter vector. Well, strictly speaking it's only equal up to a multiplicative factor, but most software packages including WinBUGS define it as being equal - see Q1 of their FAQ on DIC. The distinction between likelihood and probability is made because instead of the probability of the data for given values of the parameters, the likelihood is considered to be a function of the parameters for a fixed set of data.

It's usually analytically simpler and more computationally stable to work with the log-likelihood, and that's what you'll need to calculate the DIC anyway.

ADDED In response to user2654's comment below:
$\operatorname{P}(D\vert\theta)$ depends on the model for the data. The simplest case is when the data are independent and identically distributed (iid), in which case $\operatorname{P}(D\vert\theta)$ becomes a product over all the data points, and therefore the log-likelihood is a sum over all the data points. The probability for each data point is calculated from the probability density function or probability mass function defined by your model.

-
Thanks - I know I will need the log-likelihood to get the DIC, but I still don't know how to actually calculate P(D|theta) –  user2654 Jan 5 '11 at 15:39
Thanks onestop - I suspected this was model dependent. So if I have a model that is say, a Poisson regression with a bunch of covariates, then for each Y_rep data point, I calculate the probability that it came from a Poisson(lambda) distribution? - where lambda is a fitted parameter value. –  user2654 Jan 5 '11 at 17:35
Yes, that's it. –  onestop Jan 5 '11 at 18:02
add comment