# Using the equation of a generalized linear mixed effects model to predict x values

Very similar to this question Find the equation from generalized linear model output, I want to derive an equation for the logistic regression that includes the estimates of a random effect.

I've included the following code for reference:

Trial=c(1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3)
Time=c(2.0, 6.0, 9.0, 12.0, 15.0, 18.0, 21.0, 24.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 1.5, 3.0, 4.5, 6.0, 39.0)
Alive=c(10, 0,  0,  0,  0,  0,  0,  0,  6,  2,  8,  1,  0,  0,  4,  6,  1,  2, 0)
Dead=c(0, 10,  6, 10, 10, 10,  7, 10,  0,  8,  1,  9, 10, 10,  5,  0,  8,  6, 10)


Retrieving the coefficients;

> ranef(ostrinaA.glmm)
$Trial (Intercept) 1 0.13701996 2 -0.17639754 3 0.04042084 > coef(ostrinaA.glmm)$Trial
(Intercept)       Time
1    2.778796 -0.9009119
2    2.465379 -0.9009119
3    2.682197 -0.9009119

attr(,"class")
[1] "coef.mer"
> fixef(ostrinaA.glmm)
(Intercept)        Time
2.6417764  -0.9009119
> summary(ostrinaA.glmm)
Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod']
Family: binomial  ( logit )
Formula: cbind(Alive, Dead) ~ Time + (1 | Trial)
Data: ostrinaA

AIC      BIC   logLik deviance df.resid
69.7     72.5    -31.8     63.7       16

Scaled residuals:
Min       1Q   Median       3Q      Max
-3.07128 -0.78873 -0.01476  0.56018  2.70666

Random effects:
Groups Name        Variance Std.Dev.
Trial  (Intercept) 0.06756  0.2599
Number of obs: 19, groups:  Trial, 3

Fixed effects:
Estimate Std. Error z value    Pr(>|z|)
(Intercept)   2.6418     0.6498   4.065 0.000047964 ***
Time         -0.9009     0.1695  -5.316 0.000000106 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Correlation of Fixed Effects:
(Intr)
Time -0.858


If this were simply a generalized linear model with the logit link function I believe my equation would read;

However, this does not include the random effect. How would I include the effect of trial in my equation? Ultimately, I'd like to use this equation to predict an x value (Time) where the response (Alive/Dead) is equal to 50% (LT50).

The random effect is not a number, but a random variable, with mean 0, and standard deviation $\sigma=0.2599$ in this case. It follows a normal distribution. Something you can do is simulate a large sample of the random effect, since you know what distribution it follows, and then average the predictions, like a Monte Carlo procedure. But, also, it is likely that the R library you are using already has a prediction function for this type of regression.
If you are asking about the formal way of writing the equation, it would be $$P(y=1|x,u)=\frac{1}{1+e^{-(2.6418-0.9009x+u)}},$$ where $u\sim N(0,0.2599^2)$.