Can anyone explain the process of this derivation, step by step? This derivation is from Joint Models for Longitudinal and Time-to Event Data by Dimitris Rizopoulos.
\begin{equation} \begin{aligned} S(\theta) &= \sum_i \frac{\partial}{\partial \theta^\top}\log\int p(T_i, \delta_i \mid b_i; \theta)p(y_i \mid b_i;\theta)p(b_i;\theta)db_i \\ &= \sum_i\frac{1}{p(T_i, \delta_i, y_i; \theta)}\frac{\partial}{\partial \theta^\top}\int p(T_i, \delta_i \mid b_i; \theta)p(y_i \mid b_i;\theta)p(b_i;\theta)db_i \\ & = \sum_i\frac{1}{p(T_i, \delta_i, y_i; \theta)}\int \frac{\partial}{\partial \theta^\top}\{ p(T_i, \delta_i \mid b_i; \theta)p(y_i \mid b_i;\theta)p(b_i;\theta)\}db_i \\ & =\sum_i\int\bigg[ \frac{\partial}{\partial \theta^\top}\log\{ p(T_i, \delta_i \mid b_i; \theta)p(y_i \mid b_i;\theta)p(b_i;\theta)\}\bigg]\\ & \times \frac{p(T_i, \delta_i \mid b_i; \theta)p(y_i \mid b_i;\theta)p(b_i;\theta)}{p(T_i, \delta_i, y_i; \theta)}db_i \\ &=\sum_i\int A(\theta,b_i)p(b_i \mid T_i, \delta_i, y_i; \theta)db_i, \end{aligned} \end{equation}
where $A(\cdot)$ denotes the complete data score vector, given by $A(\theta,b_i) = \partial\{\log p(T_i, \delta_i \mid b_i; \theta) + \log p(y_i \mid b_i;\theta) + \log p(b_i;\theta)\}/\partial \theta^\top$.
I also do not understand using a posterior distribution for the random effects $b_i$, since this is a frequentist derivation. Bayesians would have no need to integrate over the random effects, since the random effects vector is considered a parameter in the Bayesian regime.