lm.pred: Generates a function that generates a learner from a formula

Description Usage Arguments Details Value See Also Examples

View source: R/predictors.R

Description

'lm.pred' takes a formula and returns a function that, when provided data, returns a predictor function. See examples.

Usage

1
lm.pred(form)

Arguments

form

A formula.

The formula will be passed without changes to the 'lm' function, so it must be compatible with it.

Details

The function can be used to generate a pair of predictors for use with the 'gob' function, e.g.

> gob(Y~X, Z, lm.pred(Y~X))

However, the 'gob' function provides a shorthand for this. The above call is exactly equivalent to:

> gob(lm(Y~X), Z)

Behind the scenes, the argument lm(Y~X) is not evaluated: instead, the function name 'lm' is matched to 'lm.pred', and the formula is extracted.

Value

A list of two functions

The functions returned have two arguments – a response vector 'Y' and covariates 'X' (which may be a vector a dataframe) – and they each return a predictor function; that is, a function that takes a covariate value and returns a prediction. The first function of the list returns a function that learns a predictor for the control potential outcomes, while the second returns a function that learns a predictor for the treatment potential outcomes.

See Also

Other predictor builders: glm.pred

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
library(RGOB)
N <- 100
X <- rnorm(N)
Z <- sample(c(0,1), size=N, replace=TRUE)
Y <- 1 + 0.2 * X + 0.5*Z 
mu_hat_ls <- lm.pred(Y~X)
mu_hat_0 <- mu_hat_ls[[1]](Y[Z==0], X[Z==0])
mu_hat_1 <- mu_hat_ls[[2]](Y[Z==1], X[Z==1])
mu_hat_0(0.2) # 1.04
mu_hat_1(0.1) # 1.52

gwb/RGOB documentation built on May 14, 2021, 7:39 a.m.