# Understanding residual vs fit plot for mixed effect model with AR1 structure

I am running a linear mixed effects model for time series data using R-INLA. My response variable is normally distributed. The model has a random intercept, and temporal autocorrelation between data points is modelled with a first order autoregressive structure. The parameter estimates from the model match our hypotheses. However, when I check diagnostic plots for the model, the residuals vs fitted values plot has a very clear pattern. Other diagnostic plots (like the QQ plot, etc.) look fine. I’m assuming that this residual vs fitted plot is telling me that there is a non-linear relationship between my response variable and my fixed effects variables. But I am not sure how to fix this. I was wondering if you could please give me some suggestions.

Here is the plot:

Here is the code for the model:

m_inla1 <- inla(y~ x1 +
x2+
x3+
x4+
x5+
f(group, model = "ar1"),
data = dat,
control.compute = list(waic = TRUE, dic = TRUE, cpo = TRUE, return.marginals.predictor=TRUE))


Where y is a continuous variable. Four of the covariates (x1, x2, x3, and x4) are also continuous variables. These have been standardised using the r function ‘scale’, which standardises each value by subtracting the mean and dividing by the standard deviation. The final covariate (x5) is a binary categorical variable that takes the value 0 or 1. The variable ‘group’ is the random intercept and has 48 levels.

Thanks so much!

• Welcome to CV! It would really help if you provided a lot more information about how you coded your model as well as some descriptions of your variables (which may give clues on what should be done with this mixed model). Apr 16, 2023 at 14:05

This pattern of data points that seem to be aligned on a straight line resembles the pattern that might occur with the Yule-Simpson effect.

The effect within the groups is different from the main effect.

### create data
m = 10
n = 10

z = rnorm(m)
z = rep(z,each=n)
x = rnorm(m*n,z)
y = 3*z-x

### plot data
plot(x,y, main = "x versus y")