Skip to content

Instantly share code, notes, and snippets.

@dgrtwo
Created January 5, 2015 20:15
Show Gist options
  • Save dgrtwo/a526a44dee3905e44d0e to your computer and use it in GitHub Desktop.
Save dgrtwo/a526a44dee3905e44d0e to your computer and use it in GitHub Desktop.
Tidy, augment and glance (a la [broom](https://github.com/dgrtwo/broom) package) for lme4.0's "mer" class.
## "mer" methods for lme4.0, which couldn't be included in CRAN version
## of broom because it suggested lme4.0. See ?broom::lme4_tidiers for
## documentation.
tidy.mer <- function(x, effects = "random", ...) {
# pass directly on to lme4 method
effects <- match.arg(effects, c("random", "fixed"))
if (effects == "fixed") {
# return tidied fixed effects rather than random
ret <- coef(lme4.0::summary(x))
# p-values may or may not be included
nn <- c("estimate", "std.error", "statistic", "p.value")[1:ncol(ret)]
return(fix_data_frame(ret, newnames = nn, newcol = "term"))
}
# for random effects, can pass on to lme4 method
tidy.merMod(x, effects = "random", ...)
}
augment.mer <- function(x, data = model.frame(x), newdata, ...) {
if (missing(newdata)) {
newdata <- NULL
}
ret <- augment_columns(x, data, newdata, se.fit = NULL)
ret
}
glance.mer <- function(x, ...) {
ret <- unrowname(data.frame(sigma = lme4.0::sigma(x)))
finish_glance(ret, x)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment