View source: R/learner_stratify.R
| learner_stratify | R Documentation |
This function creates a stratified learner from an existing
learner wrapper function such as learner_glm or learner_xgboost. The
stratification variable can be specified either using the stratify
argument (which can be given as a string "a" or a formula , for example ~
I(a==0)), or it can be defined as a special term directly in the formula, y
~ ... + stratify(a). The formula will subsequently be passed to the
learner_ wrapper without the stratify special term.
learner_stratify(
formula,
learner,
stratify = NULL,
info = NULL,
learner.args = list(),
...
)
formula |
formula specifying outcome and design matrix |
learner |
(learner) learner object |
stratify |
(character,formula) variables to stratify by |
info |
optional description of the model |
learner.args |
(list) optional arguments to the learner constructor |
... |
additional arguments passed to the learner constructor |
learner object
simdata <- function(n=1000) {
a <- rbinom(n, 1, 0.5)
x <- rnorm(n)
y <- rbinom(n, 1, plogis(-1 + a + a * x))
data.frame(y, a, x)
}
d <- simdata()
lr <- learner_stratify(
y ~ x + stratify(a),
learner_glm,
family=binomial()
)
lr$estimate(d)
lr$predict(head(d))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.