Learn R Programming

targeted (version 0.6)

learner_stratify: Construct stratified learner

Description

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.

Usage

learner_stratify(
  formula,
  learner,
  stratify = NULL,
  info = NULL,
  learner.args = list(),
  ...
)

Value

learner object

Arguments

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

Examples

Run this code
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))

Run the code above in your browser using DataLab