Linear mixed-effects model (lmer) across multiple grouping variables.

grouped_lmer(
  data,
  grouping.vars,
  ...,
  output = "tidy",
  tidy.args = list(conf.int = TRUE, conf.level = 0.95, effects = "fixed", conf.method =
    "Wald"),
  augment.args = list()
)

Arguments

data

Dataframe (or tibble) from which variables are to be taken.

grouping.vars

Grouping variables.

...

Arguments passed on to lme4::lmer

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. Two vertical bars (||) can be used to specify multiple uncorrelated random effects for the same grouping variable. (Because of the way it is implemented, the ||-syntax works only for design matrices containing numeric (continuous) predictors; to fit models with independent categorical effects, see dummy or the lmer_alt function from the afex package.)

REML

logical scalar - Should the estimates be chosen to optimize the REML criterion (as opposed to the log-likelihood)?

start

a named list of starting values for the parameters in the model. For lmer this can be a numeric vector or a list with one component named "theta".

verbose

integer scalar. If > 0 verbose output is generated during the optimization of the parameter estimates. If > 1 verbose output is generated during the individual penalized iteratively reweighted least squares (PIRLS) steps.

subset

an optional expression indicating the subset of the rows of data that should be used in the fit. This can be a logical vector, or a numeric vector indicating which observation numbers are to be included, or a character vector of the row names to be included. All observations are included by default.

weights

an optional vector of ‘prior weights’ to be used in the fitting process. Should be NULL or a numeric vector. Prior weights are not normalized or standardized in any way. In particular, the diagonal of the residual covariance matrix is the squared residual standard deviation parameter sigma times the vector of inverse weights. Therefore, if the weights have relatively large magnitudes, then in order to compensate, the sigma parameter will also need to have a relatively large magnitude.

na.action

a function that indicates what should happen when the data contain NAs. The default action (na.omit, inherited from the 'factory fresh' value of getOption("na.action")) strips any observations with any missing values in any variables.

offset

this can be used to specify an a priori known component to be included in the linear predictor during fitting. This should be NULL or a numeric vector of length equal to the number of cases. One or more offset terms can be included in the formula instead or as well, and if more than one is specified their sum is used. See model.offset.

contrasts

an optional list. See the contrasts.arg of model.matrix.default.

devFunOnly

logical - return only the deviance evaluation function. Note that because the deviance function operates on variables stored in its environment, it may not return exactly the same values on subsequent calls (but the results should always be within machine tolerance).

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.

tidy.args

A list of arguments to be used in the relevant S3 method.

augment.args

A list of arguments to be used in the relevant S3 method.

Value

A tibble dataframe with tidy results from a linear mixed-effects model. Note that p-value is computed using parameters::p_value.

Examples

# \donttest{ # for reproducibility set.seed(123) # loading libraries containing data library(gapminder) # getting tidy output of results # let's use only subset of the data groupedstats::grouped_lmer( data = gapminder, formula = scale(lifeExp) ~ scale(gdpPercap) + (gdpPercap | continent), grouping.vars = year, REML = FALSE, tidy.args = list(effects = "fixed", conf.int = TRUE, conf.level = 0.95), output = "tidy" )
#> Warning: unable to evaluate scaled gradient
#> Warning: Model failed to converge: degenerate Hessian with 1 negative eigenvalues
#> boundary (singular) fit: see ?isSingular
#> boundary (singular) fit: see ?isSingular
#> boundary (singular) fit: see ?isSingular
#> boundary (singular) fit: see ?isSingular
#> boundary (singular) fit: see ?isSingular
#> boundary (singular) fit: see ?isSingular
#> boundary (singular) fit: see ?isSingular
#> boundary (singular) fit: see ?isSingular
#> boundary (singular) fit: see ?isSingular
#> boundary (singular) fit: see ?isSingular
#> boundary (singular) fit: see ?isSingular
#> Warning: unable to evaluate scaled gradient
#> Warning: Model failed to converge: degenerate Hessian with 1 negative eigenvalues
#> boundary (singular) fit: see ?isSingular
#> boundary (singular) fit: see ?isSingular
#> boundary (singular) fit: see ?isSingular
#> boundary (singular) fit: see ?isSingular
#> boundary (singular) fit: see ?isSingular
#> boundary (singular) fit: see ?isSingular
#> boundary (singular) fit: see ?isSingular
#> boundary (singular) fit: see ?isSingular
#> boundary (singular) fit: see ?isSingular
#> boundary (singular) fit: see ?isSingular
#> boundary (singular) fit: see ?isSingular
#> # A tibble: 24 x 10 #> year effect term estimate std.error statistic conf.low conf.high p.value #> <int> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 1952 fixed (Interc… 0.201 0.743 0.270 -1.26 1.66 7.87e-1 #> 2 1952 fixed scale(g… 0.900 0.742 1.21 -0.555 2.35 2.25e-1 #> 3 1957 fixed (Interc… 0.190 0.377 0.504 -0.548 0.928 6.15e-1 #> 4 1957 fixed scale(g… 0.756 0.384 1.97 0.00255 1.51 4.92e-2 #> 5 1962 fixed (Interc… 0.226 0.505 0.447 -0.765 1.22 6.55e-1 #> 6 1962 fixed scale(g… 0.547 0.273 2.01 0.0130 1.08 4.47e-2 #> 7 1967 fixed (Interc… 0.234 0.307 0.764 -0.367 0.836 4.45e-1 #> 8 1967 fixed scale(g… 0.269 0.0779 3.46 0.117 0.422 5.48e-4 #> 9 1972 fixed (Interc… 0.241 0.307 0.783 -0.362 0.843 4.34e-1 #> 10 1972 fixed scale(g… 0.378 0.109 3.45 0.163 0.593 5.56e-4 #> # … with 14 more rows, and 1 more variable: significance <chr>
# }