Residuals in LME models Good morning everyone!
I have implemented the following lme model in r:
lme_mod<-lme(Value ~ Treatment, random = ~ 1+Treatment| person_ID, method="ML", data=C)

I am analyzing the following residuals: resid(lme_mod).
That ones should be the random effect residuals, right?
Could you write to me a mathematical expression/formula to better explain these residuals?
Thank you very much :)


I am analyzing the following residuals: resid(lme_mod).
That ones should be the random effect residuals, right?

Unfortunately not. resid extracts the residuals - that is the "lower level", or "measurement level" residuals. These are sometimes called "residual error", but care must be taken when referring to "errors" which are  part of the data generating process, and "residuals" which are computed from the fitted model and the data. In a sense, the residuals are estimates of the error.
To extract the random effects you would use ranef(lme_mod)

Could you write to me a mathematical expression/formula to better explain these residuals?

The model is:
Value ~ Treatment, random = ~ 1 + Treatment | person_ID

which has the following features:
this has the following features:

*

*a global intercept, let us call it $\beta_0$

*a random intercept, let's call it $u_{0j}$, where $j$ indexes person_IDs

*fixed effects for Treatment, let's call it $\beta_1$

*random slopes for Treatment within levels of person_ID, let's call it $u_{1j}$

*residual error, let us call it $e_{ij}$ for the $i$th observation within the $j$th person_ID
We could write this model as:
$$ Value_{ij} = \beta_0 + u_{0j} + ( \beta_1 + u_{1j}) Treatment + e_{ij} $$
So, to obtain a formula for the residuals, we can start by writing:
$$ e_{ij} = Value_{ij} - \beta_0 - u_{0j} - ( \beta_1 + u_{1j}) Treatment $$
Now, as mentioned, $e_{ij}$ are not the residuals, they are the residual errors, or often just "errors". We compute the residuals after fitting the model and estimating $\beta_1$ and $\beta_0$, and since the model assumes that the random effects are normally distributed about zero (so that their expected value is zero), we have:
$$ \epsilon_{ij} = Value_{ij} - \hat{\beta_0}  -  \hat{\beta_1} Treatment $$
where $\hat{\beta_0}$ and $\hat{\beta_1}$ are the estimates of $\beta_0$ and $\beta_1$.
