Returns the data from all random effects terms.

get_random(x)

Arguments

x

A fitted mixed model.

Value

The data from all random effects terms, as data frame. Or NULL if model has no random effects.

Examples

if (require("lme4")) {
  data(sleepstudy)
  # prepare some data...
  sleepstudy$mygrp <- sample(1:5, size = 180, replace = TRUE)
  sleepstudy$mysubgrp <- NA
  for (i in 1:5) {
    filter_group <- sleepstudy$mygrp == i
    sleepstudy$mysubgrp[filter_group] <-
      sample(1:30, size = sum(filter_group), replace = TRUE)
  }

  m <- lmer(
    Reaction ~ Days + (1 | mygrp / mysubgrp) + (1 | Subject),
    data = sleepstudy
  )

  head(get_random(m))
}
#> boundary (singular) fit: see ?isSingular
#>   mysubgrp mygrp Subject
#> 1        1     4     308
#> 2       29     4     308
#> 3       13     4     308
#> 4       23     1     308
#> 5        2     4     308
#> 6       12     4     308