I'm trying to generate an autoplot for mer objects in the same vein as the the autoplot.lm example.
I can extract the original data frame, the residuals and the linear predictors directly from the returned object...
> random.model <- lmer(a ~ b + c + (1 | d), data = example, family = binomial
> diagnostics <- cbind(random.model@frame, random.model@eta, random.model@resid)
...and after reading a suggestion here I can calculate Cooks Distance using the influence.ME package...
> library(influence.ME)
> cooks <- cooks.distance(influence.ME::influence(random.model))
> diagnostics <- cbind(diagnostics, cooks)
...and elsewhere (sorry can't find link) found that I could derive the standardised residuals using the HLMdiag package...
> library(HLMdiag)
> stdresid <- HLMresid(random.model, level = 1, standardize = TRUE)
> diagnostics <- cbind(diagnostics, stdresid)
But I've hit a problem as the autoplot example calls ggplot2's fortify()
function to calculate these and two additional measurements, sigma, the estimate of the residual SD when the corresponding observation is dropped from the model and hat, the diagonal of the hat matrix.
Reading around I thought the hatTrace()
function would be one part of the solution, but found posts on R-help indicating that it was removed from the lme4 package.
Can anyone advise on how to calculate sigma and hat vectors?
Or if anyone has canned solutions for diagnostic plots for lme4 that would be useful too.