groupedstats (version 0.0.7)

grouped_glmer: Function to run generalized linear mixed-effects model (glmer) across multiple grouping variables.

Description

Function to run generalized linear mixed-effects model (glmer) across multiple grouping variables.

Usage

grouped_glmer(data, grouping.vars, formula, family = stats::binomial(link
  = "probit"), control = lme4::glmerControl(optimizer = "bobyqa",
  boundary.tol = 1e-07, calc.derivs = FALSE, use.last.params = FALSE,
  optCtrl = list(maxfun = 2e+09)), output = "tidy")

Arguments

data

Dataframe from which variables are to be taken.

grouping.vars

List of grouping variables.

formula

a two-sided linear formula object describing both the fixed-effects and random-effects part of the model, with the response on the left of a ~ operator and the terms, separated by + operators, on the right. Random-effects terms are distinguished by vertical bars ("|") separating expressions for design matrices from grouping factors.

family

a GLM family, see glm and family.

control

a list (of correct class, resulting from lmerControl() or glmerControl() respectively) containing control parameters, including the nonlinear optimizer to be used and parameters to be passed through to the nonlinear optimizer, see the *lmerControl documentation for details.

output

A character describing what output is expected. Two possible options: "tidy" (default), which will return the results, or "glance", which will return model summaries.

Value

A tibble dataframe with tidy results from linear model or model summaries.

See Also

grouped_lmer

Examples

Run this code
# NOT RUN {
# commented out because the examples are time-consuming and the R CMD CHECK
# makes a NOTE (> 5s)

# categorical outcome; binomial family
groupedstats::grouped_glmer(
  formula = Survived ~ Age + (Age |
    Class),
  family = stats::binomial(link = "probit"),
  data = dplyr::sample_frac(groupedstats::Titanic_full, size = 0.3),
  grouping.vars = Sex
)

# continuous outcome; gaussian family
library(gapminder)

groupedstats::grouped_glmer(
  data = dplyr::sample_frac(gapminder, size = 0.3),
  formula = scale(lifeExp) ~ scale(gdpPercap) + (gdpPercap | continent),
  family = stats::gaussian(),
  control = lme4::lmerControl(
    optimizer = "bobyqa",
    restart_edge = TRUE,
    boundary.tol = 1e-7,
    calc.derivs = FALSE,
    optCtrl = list(maxfun = 2e9)
  ),
  grouping.vars = year,
  output = "tidy"
)
# }

Run the code above in your browser using DataLab