# Correlation between random intercept and covariables in generalized mixed models

I'm little bit struggle this 4 past days about a specification of a likelihood in the context of correlation between a random intercept and covariables in generalized mixed models. A known approach is to suppress the random intercept by conditioning on it.
My work is based on the article Separating between- and within-Cluster Covariate Effects by Using Conditional and Partitioning Methods of John M.Neuhaus and Charles E.McCulloch

For my context: $$f(y_i \mid x_i, b_i) \sim B(\pi(x_i)) \\ b_i \sim N(0, \sigma_b^2) \\ x_i \mid b_i \sim N(0, \sigma_x^2)$$ with $$\pi(x_i) = \frac{1}{1+\exp(-(X\beta + Zb))}$$

And I have to implement this to estimate the fixed effects: $$f(y_i, x_i) = \int_b f(y_i, x_i \mid b) dG(b)\\ = \int_b f_y(y_i \mid x_i, b)f_{x|b}(x_i \mid b) dG(b)$$ Conceptually, I have no problem to derive this results of Bayes Theorem and marginal distribution. But I'm really struggle to implement the last equality in R.

So, I re-write my equality with my respected distributions as followed:
$$\int_b \pi(x_i)^{y_i}(1-\pi(x_i))^{1-y_i}\frac{1}{\sigma_x\sqrt(2\pi)}\exp(-\frac{1}{2\sigma_x^2}x^2)\frac{1}{\sigma_b\sqrt(2\pi)}\exp(-\frac{1}{2\sigma_b^2}b^2)db \\$$

Here I have a problem to evaluate my fixed effects. Did I specify my integrand fine ? Because I didn't, my likelihood will be incorrect. I can't estimate my coefficient fine.

It is not clear where exacly $$x_i$$ enters into the equation of $$\pi(x_i)$$, but, in general, integrals of the form you have written in the specification of the marginal distribution need to be numerically approximated. Popular ways to do this are the adaptive Gaussian quadrature rule and the Laplace approximation.