Skip to contents

Makes one row per combination of values of vars, which is the data frame conditional_effects() takes as conditions to draw one panel per row. This is brms's make_conditions(), and its output is identical to brms's on the same input.

Usage

make_conditions(x, vars, ...)

Arguments

x

A data frame, or a fitted model. From a frmtmb_fit the data the fit holds is used: the model frame and the variables the formula reads through a transform, such as x2 of log(x2), as brms uses its stored data. From any other list that has a data element, that element is used, as brms does.

vars

Character vector of the names of the variables to condition on.

...

Passed to the labeler that makes the cond__ column: digits (default 2) rounds a numeric value in the label, sep (default " & ") separates the variables, and incl_vars (default TRUE) puts the variable name before each value.

Value

A data frame with one column per variable of vars, in the order of vars, and a column cond__ that labels each row, for example "zBase = -1 & zAge = 1". As in brms, cond__ is the variable itself when there is one variable and incl_vars = FALSE.

Details

A factor, character or logical variable contributes each of its levels. A numeric variable contributes three values: its mean minus one standard deviation, its mean, and its mean plus one standard deviation. The last variable of vars varies fastest.

Examples

set.seed(1)
dd <- data.frame(x = rnorm(60), z = rnorm(60),
                 f = factor(rep(c("a", "b"), 30)))
dd$y <- rnorm(60, dd$x + dd$z * (dd$f == "b"))
fit <- frm(bf(y ~ x + z * f), family = gaussian(), data = dd)
conds <- make_conditions(fit, c("z", "f"))
conds
#>            z f           cond__
#> 1 -0.8024937 a z = -0.8 & f = a
#> 2 -0.8024937 b z = -0.8 & f = b
#> 3  0.1118054 a z = 0.11 & f = a
#> 4  0.1118054 b z = 0.11 & f = b
#> 5  1.0261045 a z = 1.03 & f = a
#> 6  1.0261045 b z = 1.03 & f = b
ce <- conditional_effects(fit, effects = "x", conditions = conds)