model.frame {bayesnec} | R Documentation |
Model.frame methods in bayesnec.
Description
Retrieve data.frame used to fit models via bnec
, or directly
from a bayesnecformula
.
formula
should be of class bayesnecfit
,
bayesmanecfit
or bayesnecformula
.
Usage
## S3 method for class 'bayesnecfit'
model.frame(formula, ...)
## S3 method for class 'bayesmanecfit'
model.frame(formula, model, ...)
## S3 method for class 'bayesnecformula'
model.frame(formula, data, ...)
Arguments
formula |
An model object of class |
... |
Unused if |
model |
A valid model string. |
data |
A |
Details
If formula
is a bayesnecformula
and it
contains transformations to variables x and y, these are evaluated and
returned as part of the data.frame
.
Value
If formula
is a bayesnecfit
or a
bayesmanecfit
, a data.frame
containing
the data used to fit the model.
If, instead, formula
is a bayesnecformula
,
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"
).
Examples
library(bayesnec)
# if input is of class `bayesnecfit` or `bayesmanecfit`
model.frame(manec_example, model = "nec4param")
nec4param <- pull_out(manec_example, "nec4param")
model.frame(nec4param)
# if input is of class `bayesnecformula`
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")
model.frame(bnf(f_2), data)
m_3 <- model.frame(bnf(f_3), data)
attr(m_3, "bnec_group")
model.frame(bnf(f_4), data)