bayesnecformula
R/bayesnecformula.R
model.frame.bayesnecformula.Rd
Recovers evaluated data.frame
given input data
and a formula of class bayesnecformula
.
# S3 method for bayesnecformula
model.frame(formula, data, ...)
A formula of class bayesnecformula
.
A data.frame
containing the variables
specified in formula
.
Additional arguments to be passed to
check_formula
.
A data.frame
with additional attributes
detailing the population-level variables (attribute "bnec_pop"
)
(response y, predictor x, and, if binomial a formula, trials) and, if
applicable, the group-level variables (attribute "bnec_group"
).
If the formula contains transformations to variables x and y,
these are evaluated and returned as part of the
data.frame
.
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)
f_1 <- y ~ crf(x, "nec3param")
f_2 <- "y | trials(tr) ~ crf(sqrt(x), \"nec3param\")"
f_3 <- y | trials(tr) ~ crf(x, "nec3param") + ogl(group_1) + pgl(group_2)
f_4 <- y | trials(tr) ~ crf(x, "nec3param") + (nec + top | group_1)
m_1 <- model.frame(bnf(f_1), data)
attr(m_1, "bnec_pop")
#> y_var x_var
#> "y" "x"
#> attr(,"na.action")
#> [1] 3
#> attr(,"class")
#> [1] "omit"
model.frame(bnf(f_2), data)
#> y sqrt(x) trials(tr)
#> 1 1.000000e+02 1.000000 100
#> 2 1.000000e+02 1.763834 100
#> 3 3.676327e+01 2.285218 100
#> 4 6.527785e+00 2.708013 100
#> 5 1.159091e+00 3.073181 100
#> 6 2.058113e-01 3.399346 100
#> 7 3.654441e-02 3.696846 100
#> 8 6.488923e-03 3.972125 100
#> 9 1.152191e-03 4.229526 100
#> 10 2.045861e-04 4.472136 100
m_3 <- model.frame(bnf(f_3), data)
attr(m_3, "bnec_group")
#> [1] "group_1" "group_2"
model.frame(bnf(f_4), data)
#> y x trials(tr) group_1
#> 1 1.000000e+02 1.000000 100 a
#> 2 1.000000e+02 3.111111 100 b
#> 3 3.676327e+01 5.222222 100 b
#> 4 6.527785e+00 7.333333 100 b
#> 5 1.159091e+00 9.444444 100 a
#> 6 2.058113e-01 11.555556 100 a
#> 7 3.654441e-02 13.666667 100 b
#> 8 6.488923e-03 15.777778 100 b
#> 9 1.152191e-03 17.888889 100 b
#> 10 2.045861e-04 20.000000 100 a