# glmer: how to test intra-patient variability to point out a clustering effect in drug concentration-outcome study

It is still not clear to me how to test for intra-patient variability test in R, and I wish to receive some help again.

I have some subjects and each of them has been measured for drug concentration (continuous variable, repeated measurements) and outcome (binary variable Y/N, repeated measurements). Concentration and outcome data vary within an individual on different days. I hypothesize that there is a drug concentration-outcome relationship. I would like to test the effect of intra-patient drug concentration variability on the outcome. My model is:

model1 <- glmer(outcome ~ drug_concen + (drug_concen | patient ID), family = binomial(), data = data1)


It was suggested to me to test for the clustering effect (whether intra-patient variability is zero) via a likelihood ratio test, or compare the AIC values. But I am wondering if my control model should be as follows:

model2 <- glm(outcome ~ drug_concen, family = binomial(), data = data1)
anova(model1, model2)


If you would like to test whether the outcome measurements are correlated within patients (i.e., intra-patient variability), then indeed you can use the likelihood ratio test between the two models you have provided.
More specifically, the model that allows for correlations and is fitted by glmer() is $$\log\left(\frac{\pi_{ij}}{1 - \pi_{ij}}\right) = \beta_0 + \beta_1 \texttt{drug_conc}_{ij} + b_{i0} + b_{i1} \texttt{drug_conc}_{ij},$$ where $$\pi_{ij} = \mbox{Pr}(Y_{ij} = 1 \mid b_i)$$, with $$Y_{ij}$$ denoting the dichotomous outcome of subject $$i$$ at time $$j$$, and $$b_i = \left [\begin{array}{c}b_{i0}\\ b_{i1}\end{array} \right] \sim \mathcal N \left (0, \left[\begin{array}{cc} \sigma_0^2 & \sigma_{01}\\ \sigma_{01} & \sigma_1^2\end{array} \right]\right),$$ where $$\sigma_0^2$$ is the variance for the random intercepts, $$\sigma_1^2$$ is the variance for the random slopes, and $$\sigma_{01}$$ the covariance between the random intercepts and slopes. Then, the specific null hypothesis you're testing by comparing the two models is: $$H_0: \sigma_0^2 = \sigma_1^2 = \sigma_{01} = 0.$$