## Likelihood

Now we are ready to write the likelihood function. As usual, I
define a new class that extends `thinkbayes.Suite`

:

class Price(thinkbayes.Suite): def __init__(self, pmf, player): thinkbayes.Suite.__init__(self, pmf) self.player = player

`pmf`

represents the prior
distribution and `player`

is a Player
object as described in the previous section. Here’s `Likelihood`

:

def Likelihood(self, data, hypo): price = hypo guess = data error = price - guess like = self.player.ErrorDensity(error) return like

`hypo`

is the hypothetical price of
the showcase. `data`

is the contestant’s
best guess at the price. `error`

is the
difference, and `like`

is the likelihood
of the data, given the hypothesis.

`ErrorDensity`

is defined in
`Player`

:

# class Player: def ErrorDensity(self, error): return self.pdf_error.Density(error)

`ErrorDensity`

works by evaluating
`pdf_error`

at the given
value of `error`

. The result is a
probability density, so it is not really a probability. But remember that
`Likelihood`

doesn’t need to compute a
probability; it only has to compute something
*proportional* to a probability. As long as the
constant of proportionality is the same for all likelihoods, it gets
canceled out when we normalize the posterior distribution.

And therefore, a probability density is a perfectly good likelihood.

Get *Think Bayes* now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.