How does a marginal likelihood come to include both parameter and model values? I am new to this issue and am trying to get my head around how Bayes Factors work.
I think that when using a Bayesian approach to estimate parameters in a model, we use the formula: 
P(theta|data) = P(data|theta) x P(theta) / P(data)
Now, suppose I want to use a Bayesian approach to test the hypothesis that theta = 0 (i.e., the null hypothesis in this regard). In theory, I think the formula is:
P(hypothesis|data) = P(data|hypothesis) x P(hypothesis) / P(data)
In practice, one way that this is done is to use Bayes Factors. From my discussion here, I've gathered that this can be done in two ways: comparing the density of the posterior at zero to the density of the prior at 0. Another way to do this would be to compare a model with and without the parameter of interest. This is where I start to get lost in terms of the corresponding formula. From reading this, for instance, it sounds like the way to do this is to compare the marginal likelihoods of the two models. However, up until now, the marginal likelihood has been ignored. The paper I just linked gives a model's marginal likelihood as this. This formula doesn't make sense to me as I have up until now understood a formula to either be involving a parameter value or a hypothesis value (i.e., true or false). Can you help me understand just what this formula means, in the context of the previous two I have given?
 A: Let $y = (y_1, \ldots, y_n)$ denote the observations (the data) and let $\theta$ denote the parameter. Let $p(y|\theta)$ sampling distribution for the data given the parameter. After the data is observed, $p(y|\theta)$ become the likelihood for $\theta$. 
The idea is to compare two models. According to the first model, $\theta \in \Theta$. Let's label this model $M_1$. The model is defined by the prior for $\theta$, which we can write as $p(\theta|M_1)$. 
According to the second model, $\theta = \theta_0$. Let us label this model $M_0$.
It is convenient to express this model in terms of a prior as well. The "density" for a point mass can be represented using a Dirac delta function: $p(\theta|M_0) = \delta(\theta-\theta_0)$.  
The Bayes factor in favor of $M_0$ relative to $M_1$ is given by the ratio of the likelihoods of the models:
\begin{equation}
B_{01} = \frac{p(y|M_0)}{p(y|M_1)} ,
\end{equation}
where 
\begin{equation}
p(y|M_1) = \int p(y|\theta)\,p(\theta|M_1)\,d\theta 
\end{equation}
and
\begin{equation}
\begin{split}
p(y|M_0) 
&= \int p(y|\theta)\,p(\theta|M_0)\,d\theta \\
&= \int p(y|\theta)\,\delta(\theta-\theta_0)\,d\theta \\
&= p(y|\theta_0) .
\end{split}
\end{equation}
We see that the likelihood of $M_0$ is the same as the likelihood of $\theta_0$. 
Now consider the posterior distribution for $\theta$ given $M_1$:
\begin{equation}
p(\theta|y,M_1) = \frac{p(y|\theta)\,p(\theta|M_1)}{p(y|M_1)} .
\end{equation}
We can divide both sides by the prior, producing
\begin{equation}
\frac{p(\theta|y,M_1)}{p(\theta|M_1)} = \frac{p(y|\theta)}{p(y|M_1)} .
\end{equation}
This equality holds for every value of $\theta$, including $\theta_0$:
\begin{equation}
\frac{p(\theta_0|y,M_1)}{p(\theta_0|M_1)} = \frac{p(y|\theta_0)}{p(y|M_1)} .
\end{equation}
We can see that the right-hand side equals the Bayes factor, $B_{01}$. We now have an expression for the Bayes factor in terms of what is known as the Savage-Dickey density ratio:
\begin{equation}
B_{01} = \frac{p(\theta_0|y,M_1)}{p(\theta_0|M_1)} .
\end{equation}
This expression has a natural interpretation. The Bayes factor favors $\theta_0$ if the posterior density (according to $M_1$) is greater than the prior density (according to $M_1$). 
This expression for the Bayes factor suggests the necessity of having a well-informed prior in order for the Bayes factor to be meaningful. An ill-informed prior that puts very little density at $\theta_0$ will tend to produce a large Bayes factor in favor of $\theta_0$. The moral is that sharp hypothesis testing requires sophistication on the part of the user. 
