Bayes factor

# Overview
In statistics, the use of Bayes factors is a Bayesian alternative to classical hypothesis testing.
Given a model selection problem in which we have to choose between two models M1 and M2, on the basis of a data vector x. The Bayes factor K is given by
where p(x|M_i) is called the marginal likelihood for model i. This is similar to a likelihood-ratio test, but instead of maximising the likelihood, Bayesians average it over the parameters. Generally, the models M1 and M2 will be parametrised by vectors of parameters 1 and 2; thus K is given by
The logarithm of K is sometimes called the weight of evidence given by x for M1 over  M2, measured in bits, nats, or bans, according to whether the logarithm is taken to base 2, base e, or base 10.
A value of K > 1 means that the data indicate that M1 is more strongly supported by the data under consideration than M2. Note that classical hypothesis testing gives one hypothesis (or model) preferred status (the 'null hypothesis'), and only considers evidence against it. Harold Jeffreys gave a scale for interpretation of K:
The second column gives the corresponding weights of evidence in decibans (tenths of a power of 10).  According to I. J. Good a change in a weight of evidence of 1 deciban (ie a change in an odds ratio from evens to about 5:4) is about as finely as humans can reasonably perceive their degree of belief in a hypothesis in everyday use.
The use of Bayes factors or classical hypothesis testing takes place in the context of inference rather than decision-making under uncertainty. That is, we merely wish to find out which hypothesis is true, rather than actually making a decision on the basis of this information. Frequentist statistics draws a strong distinction between these two because classical hypothesis tests are not coherent in the Bayesian sense. Bayesian procedures, including Bayes factors, are coherent, so there is no need to draw such a distinction. Inference is then simply regarded as a special case of decision-making under uncertainty in which the resulting action is to report a value. In a decision-making context Bayesian statisticians might use a Bayes factor as part of making a choice, but would also combine it with a prior distribution and a loss function associated with making the wrong choice. In an inference context the loss function would take the form of a scoring rule. Use of a logarithmic score function for example, leads to the expected utility taking the form of the Kullback-Leibler divergence. If the logarithms are to the base 2 this is equivalent to Shannon information.

# Example
Suppose we have a random variable which produces either a success or a failure.  We want to compare a model M1 where the probability of success is q = 12, and another model M2 where q is completely unknown and we take a prior distribution for q which is uniform on .  We take a sample of 200, and find 115 successes and 85 failures.  The likelihood is
So we have
but
The ratio is then 1.197..., which is "barely worth mentioning" even if it points very slightly towards M1.
This is not the same as a classical likelihood ratio test, which would have found the maximum likelihood estimate for q, namely 115200 = 0.575, and from that get a ratio of 0.1045..., and so pointing towards M2.  Alternatively, Edwards's "exchange rate" of two units of likelihood per degree of freedom suggests that M_2 is preferable (just) to M_1, as 0.1045\ldots = e^{-2.25\ldots} and 2.25>2: the extra likelihood compensates for the unknown parameter in M_2.
A frequentist hypothesis test of M_1 (here considered as a null hypothesis) would have produced a more dramatic result, saying that M1 could be rejected at the 5% significance level, since the probability of getting 115 or more successes from a sample of 200 if q = 12 is 0.0200..., and as a two-tailed test of getting a figure as extreme as or more extreme than 115 is 0.0400...  Note that 115 is more than two standard deviations away from 100.
M2 is a more complex model than M1 because it has a free parameter which allows it to model the data more closely.  The ability of Bayes factors to take this into account is a reason why Bayesian inference has been put forward as a theoretical justification for and generalisation of Occam's razor, reducing Type I errors.