#' @title apa.regression.glmerMod
#'
#' @description APA formated interpretation of \code{\link[lme4]{glmer}}
#'
#' @export
#'
#' @param model \code{\link[lme4]{glmer}} to be formatted
#' @param ci \code{\link[stats]{confint}} or similar (optional)
#' @return the formatted \code{\link[base]{data.frame}}
#'
#' @author Mark Newman, \email{mark@trinetteandmark.com}
#' @keywords regression
#' @family regression
#'
#' @details
#' Currently only the binomial family is supported \cr \cr
#' Pulls out the log odds, confidence interval, statistic, and p-value of the model; converts the log odds and confidence interval to odds ratios; formats p-values; and produces a table.
#'
#' @examples
#' \dontshow{
#' library(apaformat)
#' library(lme4)
#' library(knitr)}
#' x = testdata.apa.regression.glmerMod
#' model = glmer(Response ~ Attribute + (1|FocusGroup), data = x, family = binomial())
#' ci = confint(model, parm="beta_", method="Wald")
#' tab = apa.regression(model, ci)
#' kable(tab, caption = 'Odds ratios with 95% CI', booktabs = TRUE)
#'
apa.regression.glmerMod = function(model, ci = NULL) {
stopifnot(class(model) == "glmerMod")
stopifnot(attr(model,'resp')$family$family == "binomial")
fe = lme4::fixef(model)
cf = stats::coef(summary(model))[,3:4]
fe = round(exp(fe), 3)
cif = NULL
if(!is.null(ci)) { cif = apa.confint(exp(ci)) }
z = apa.zstat(cf[,1])
pv = apa.pvalue(cf[,2])
tab = cbind(fe, cif, z, pv)
colnames(tab) = c("Odds Ratio", if(!is.null(cif)) { colnames(cif) }, "z score", "p-value")
return(tab)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.