Add random effects to a data frame
add_ranef(.data, .by = NULL, ..., .cors = 0, .empirical = FALSE)
the data frame
the grouping column (groups by row if NULL)
the name and standard deviation of each random effect
the correlations among multiple random effects, to be passed to rnorm_multi
as r
logical. To be passed to rnorm_multi
as empirical
data frame with new random effects columns
add_random(rater = 2, stimulus = 2, time = 2) %>%
add_ranef("rater", u0r = 1.5) %>%
add_ranef("stimulus", u0s = 2.2, u1s = 0.75, .cors = 0.5) %>%
add_ranef(c("rater", "stimulus"), u0sr = 1.2)
#> # A tibble: 8 × 7
#> rater stimulus time u0r u0s u1s u0sr
#> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 rater1 stimulus1 time1 -0.00972 -2.57 -0.410 -0.532
#> 2 rater1 stimulus1 time2 -0.00972 -2.57 -0.410 -0.532
#> 3 rater1 stimulus2 time1 -0.00972 -0.922 -0.428 -0.453
#> 4 rater1 stimulus2 time2 -0.00972 -0.922 -0.428 -0.453
#> 5 rater2 stimulus1 time1 -1.15 -2.57 -0.410 1.13
#> 6 rater2 stimulus1 time2 -1.15 -2.57 -0.410 1.13
#> 7 rater2 stimulus2 time1 -1.15 -0.922 -0.428 -1.22
#> 8 rater2 stimulus2 time2 -1.15 -0.922 -0.428 -1.22