Checks the input formula according to bayesnec requirements and expose the final brmsformula which is to be fitted via package brms.

make_brmsformula(formula, data)

Arguments

formula

Either a character string defining an R formula or an actual formula object. See details.

data

A data.frame containing the variables specified in formula.

Value

A named list, with each element containing the final brmsformula to be passed to brm.

Examples

library(bayesnec)
nec3param <- function(beta, nec, top, x) {
  top * exp(-exp(beta) * (x - nec) *
    ifelse(x - nec < 0, 0, 1))
}

data <- data.frame(x = seq(1, 20, length.out = 10), tr = 100, wght = c(1, 2),
                   group_1 = sample(c("a", "b"), 10, replace = TRUE),
                   group_2 = sample(c("c", "d"), 10, replace = TRUE))
data$y <- nec3param(beta = -0.2, nec = 4, top = 100, data$x)

# make one single model
f_1 <- "y | trials(tr) ~ crf(sqrt(x), \"nec3param\")"
make_brmsformula(f_1, data)
#> $nec3param
#> y | trials(tr) ~ top * exp(-exp(beta) * (sqrt(x) - nec) * step(sqrt(x) - nec)) 
#> top ~ 1
#> beta ~ 1
#> nec ~ 1
#> 
# make an entire class of models
f_2 <- y ~ crf(x, "ecx") + ogl(group_1) + pgl(group_2)
make_brmsformula(f_2, data)
#> $ecx4param
#> y ~ ogl + top + (bot - top)/(1 + exp((ec50 - x) * exp(beta))) 
#> bot ~ 1 + (1 | group_2)
#> ec50 ~ 1 + (1 | group_2)
#> top ~ 1 + (1 | group_2)
#> beta ~ 1 + (1 | group_2)
#> ogl ~ 1 + (1 | group_1)
#> 
#> $ecxlin
#> y ~ ogl + top - exp(slope) * x 
#> top ~ 1 + (1 | group_2)
#> slope ~ 1 + (1 | group_2)
#> ogl ~ 1 + (1 | group_1)
#> 
#> $ecxexp
#> y ~ ogl + top * exp(-exp(beta) * x) 
#> top ~ 1 + (1 | group_2)
#> beta ~ 1 + (1 | group_2)
#> ogl ~ 1 + (1 | group_1)
#> 
#> $ecxsigm
#> y ~ ogl + top * exp(-exp(beta) * x^exp(d)) 
#> d ~ 1 + (1 | group_2)
#> top ~ 1 + (1 | group_2)
#> beta ~ 1 + (1 | group_2)
#> ogl ~ 1 + (1 | group_1)
#> 
#> $ecxwb1
#> y ~ ogl + bot + (top - bot) * exp(-exp(exp(beta) * (x - ec50))) 
#> bot ~ 1 + (1 | group_2)
#> ec50 ~ 1 + (1 | group_2)
#> top ~ 1 + (1 | group_2)
#> beta ~ 1 + (1 | group_2)
#> ogl ~ 1 + (1 | group_1)
#> 
#> $ecxwb2
#> y ~ ogl + bot + (top - bot) * (1 - exp(-exp(-exp(beta) * (x - ec50)))) 
#> bot ~ 1 + (1 | group_2)
#> ec50 ~ 1 + (1 | group_2)
#> top ~ 1 + (1 | group_2)
#> beta ~ 1 + (1 | group_2)
#> ogl ~ 1 + (1 | group_1)
#> 
#> $ecxwb1p3
#> y ~ ogl + 0 + (top - 0) * exp(-exp(exp(beta) * (x - ec50))) 
#> ec50 ~ 1 + (1 | group_2)
#> top ~ 1 + (1 | group_2)
#> beta ~ 1 + (1 | group_2)
#> ogl ~ 1 + (1 | group_1)
#> 
#> $ecxwb2p3
#> y ~ ogl + 0 + (top - 0) * (1 - exp(-exp(-exp(beta) * (x - ec50)))) 
#> ec50 ~ 1 + (1 | group_2)
#> top ~ 1 + (1 | group_2)
#> beta ~ 1 + (1 | group_2)
#> ogl ~ 1 + (1 | group_1)
#> 
#> $ecxll5
#> y ~ ogl + bot + (top - bot)/(1 + exp(exp(beta) * (x - ec50)))^exp(f) 
#> bot ~ 1 + (1 | group_2)
#> top ~ 1 + (1 | group_2)
#> beta ~ 1 + (1 | group_2)
#> ec50 ~ 1 + (1 | group_2)
#> f ~ 1 + (1 | group_2)
#> ogl ~ 1 + (1 | group_1)
#> 
#> $ecxll4
#> y ~ ogl + bot + (top - bot)/(1 + exp(exp(beta) * (x - ec50))) 
#> bot ~ 1 + (1 | group_2)
#> top ~ 1 + (1 | group_2)
#> beta ~ 1 + (1 | group_2)
#> ec50 ~ 1 + (1 | group_2)
#> ogl ~ 1 + (1 | group_1)
#> 
#> $ecxll3
#> y ~ ogl + 0 + (top - 0)/(1 + exp(exp(beta) * (x - ec50))) 
#> top ~ 1 + (1 | group_2)
#> beta ~ 1 + (1 | group_2)
#> ec50 ~ 1 + (1 | group_2)
#> ogl ~ 1 + (1 | group_1)
#> 
#> $ecxhormebc4
#> y ~ ogl + 0 + (top - 0 + exp(slope) * x)/(1 + exp(exp(beta) * (x - ec50))) 
#> top ~ 1 + (1 | group_2)
#> beta ~ 1 + (1 | group_2)
#> ec50 ~ 1 + (1 | group_2)
#> slope ~ 1 + (1 | group_2)
#> ogl ~ 1 + (1 | group_1)
#> 
#> $ecxhormebc5
#> y ~ ogl + bot + (top - bot + exp(slope) * x)/(1 + exp(exp(beta) * (x - ec50))) 
#> bot ~ 1 + (1 | group_2)
#> top ~ 1 + (1 | group_2)
#> beta ~ 1 + (1 | group_2)
#> ec50 ~ 1 + (1 | group_2)
#> slope ~ 1 + (1 | group_2)
#> ogl ~ 1 + (1 | group_1)
#>