3

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.

slackline
  • 256
  • 1
  • 8
  • 2
    I vote to keep this open. As to why, given the state of lme4, it may require theoretical as well as technical knowledge to get the diagonal of the hat matrix. Though the OP assumes that one can just extract this, I suspect the only way to get the desired result will be to compute it from other data included in the fitted model or from first principals that the OP could apply to the particular lme4 case. – Gavin Simpson Sep 17 '13 at 18:10
  • 2
    the newest versions of `lme4` (>=1.0, available for R-devel or on r-forge/github) have a `plot.merMod` method that's similar to the `plot.lm` method -- however, they only show Pearson residuals, not standardized residuals, for this very reason ... – Ben Bolker Sep 17 '13 at 21:14
  • Thanks both for the replies, I shall check out the newest version of lme4. I'd be happy with calculating the required statistics from available metrics but am unsure of how to proceed. Would looking at older code be appropriate or was it removed because it wasn't correct? – slackline Sep 18 '13 at 07:22
  • 1
    As a follow-up to my own question there are now some routines available for plotting fixed and random effects from some lme4 routines. See the blog post at [http://strengejacke.wordpress.com/2014/10/26/visualizing-generalized-linear-mixed-effects-models-with-ggplot-rstats-lme4/]. – slackline Oct 28 '14 at 11:26

0 Answers0