Compare slope values of different brms models

compare_slopes(..., Slope)

Arguments

...

brms models to be compared

Slope

A string containing the name of the covariate to have the slopes compared between models

Value

Returns a table of values with the log(slope model 1/slope model 2)

Examples


# Simulate data
md = tibble::tibble(
  group = factor(sample(1:10, 1000, replace = TRUE)),
  f_var = factor(sample(1:3, 1000, replace = TRUE)),
  n_var = rnorm(1000, mean = 0, sd = 1),
  resp = rnorm(1000, mean = 10, sd = 3))

# Run model without random slope
mod = brms_model(Response = "resp", 
                 FixedEffect = c("f_var","n_var"), 
                 RandomEffect = "group", 
                 Family = "gaussian", 
                 Data = md)
#> [1] "No problems so far 👌"
#> Compiling Stan program...
#> Start sampling

# Run model with random slope
mod_RS = brms_model(Response = "resp", 
                 FixedEffect = c("f_var","n_var"), 
                 RandomSlope = c("n_var", "group"),
                 Family = "gaussian", 
                 Data = md)
#> [1] "No problems so far 🤩"
#> l' NOW (CHAIN 2).
#> Chain 2: 
#> Chain 2: Gradient evaluation took 0.000226 seconds
#> Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 2.26 seconds.
#> Chain 2: Adjust your expectations accordingly!
#> Chain 2: 
#> Chain 2: 
#> Chain 2: Iteration:     1 / 30000 [  0%]  (Warmup)
#> Chain 2: Iteration:  3000 / 30000 [ 10%]  (Warmup)
#> Chain 1: Iteration:  3000 / 30000 [ 10%]  (Warmup)
#> Chain 2: Iteration:  6000 / 30000 [ 20%]  (Warmup)
#> Chain 1: Iteration:  6000 / 30000 [ 20%]  (Warmup)
#> Chain 2: Iteration:  9000 / 30000 [ 30%]  (Warmup)
#> Chain 1: Iteration:  9000 / 30000 [ 30%]  (Warmup)
#> Chain 2: Iteration: 12000 / 30000 [ 40%]  (Warmup)
#> Chain 1: Iteration: 12000 / 30000 [ 40%]  (Warmup)
#> Chain 2: Iteration: 15000 / 30000 [ 50%]  (Warmup)
#> Chain 2: Iteration: 15001 / 30000 [ 50%]  (Sampling)
#> Chain 1: Iteration: 15000 / 30000 [ 50%]  (Warmup)
#> Chain 1: Iteration: 15001 / 30000 [ 50%]  (Sampling)
#> Chain 1: Iteration: 18000 / 30000 [ 60%]  (Sampling)
#> Chain 2: Iteration: 18000 / 30000 [ 60%]  (Sampling)
#> Chain 1: Iteration: 21000 / 30000 [ 70%]  (Sampling)
#> Chain 2: Iteration: 21000 / 30000 [ 70%]  (Sampling)
#> Chain 1: Iteration: 24000 / 30000 [ 80%]  (Sampling)
#> Chain 2: Iteration: 24000 / 30000 [ 80%]  (Sampling)
#> Chain 1: Iteration: 27000 / 30000 [ 90%]  (Sampling)
#> Chain 2: Iteration: 27000 / 30000 [ 90%]  (Sampling)
#> Chain 1: Iteration: 30000 / 30000 [100%]  (Sampling)
#> Chain 1: 
#> Chain 1:  Elapsed Time: 65.371 seconds (Warm-up)
#> Chain 1:                61.569 seconds (Sampling)
#> Chain 1:                126.94 seconds (Total)
#> Chain 1: 
#> Chain 2: Iteration: 30000 / 30000 [100%]  (Sampling)
#> Chain 2: 
#> Chain 2:  Elapsed Time: 63.965 seconds (Warm-up)
#> Chain 2:                73.03 seconds (Sampling)
#> Chain 2:                136.995 seconds (Total)
#> Chain 2: 
#> Compiling Stan program...
#> Start sampling

compare_slopes(mod, mod_RS, Slope = "n_var")
#>   357.511 seconds (Total)
#> Chain 2: