Marginalizing over a parameter: integrate the total joint likelihood, or the each individual likelihood? This is a general question about a model-fitting task. Suppose you have IID data $Y_1, ..., Y_n$ arising from a data generating modeling indexed by a parameter $(\theta, \lambda)$, where you are only interested in $\theta$. 
Under my model, I can easily calculate $P(Y_i | \theta, \lambda)$ for each $i$, and thus the likelihood of the sample is 
$$ P(Y_1, ..., Y_n | \theta, \lambda) = \prod_{i=1}^{n} P(Y_i | \theta, \lambda) $$
I want to integrate $\lambda$ out of this expression. Is the correct expression for the marginal likelihood then 
$$ L(\theta) = \int_{\Lambda} \ \prod_{i=1}^{n} P(Y_i | \theta, \lambda) \  d \lambda \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (1) $$
or do you calculate the marginal likelihood for each subject, and then take the product: 
$$ L(\theta) = \prod_{i=1}^{n} L_i (\theta) = \prod_{i=1}^{n} \int_{\Lambda} P(Y_i | \theta, \lambda) \ d \lambda \ \ \ \ \ \ \ (2)$$
Both seem reasonable but they obviously are not equal. Controlling numerical underflow is obviously more difficult with expression (1), but I'm mainly concerned with which answer obeys convention.  
Note: I am aware this is not exactly a "likelihood function", rather marginalizing over part of a posterior distribution with an uninformative prior. 
 A: First off, neither (1) or (2) are quite right because you didn't include the prior on $\lambda$ in the integrand [call these revised integrals (1') and (2'), respectively]. Just remember that marginalization occurs with respect to a joint distribution: $p(x) = \int p(x,y) \,dy = \int p(x \mid y) p(y) \,dy$. So (1') looks like
$$
L(\theta) = p(\mathbf{Y} \mid \theta) = \int p(\mathbf{Y} \mid \theta, \lambda)\, p(\lambda) \,d\lambda =\int \left[ \prod_{i=1}^n p(Y_i \mid \theta, \lambda) \right] p(\lambda) \,d\lambda.
$$
Second, if you want to calculate $P(\mathbf{Y} \mid \theta)$ then you should go for (1') because it is always true. (2') is false unless you assume that the outcomes are independent of $\lambda$ given $\theta$. Of course, that means that $p(Y_i \mid \theta, \lambda) = p(Y_i \mid \theta)$, which I doubt is what you want to assume in general.
Third, for posterior inference on $\theta$ it may be easier to just marginalize out $\lambda$ from the joint posterior of both parameters: $p(\theta \mid \mathbf{Y}) = \int p(\theta, \lambda \mid \mathbf{Y}) \, d\lambda$, but of course that depends on you and what problem you're working on.
