make_contrasts: One-hot encode categorical covariates

Description Usage Arguments Details Value Examples

View source: R/utils.R

Description

The causal_forest algorithm requires inputs to be numeric matrices. This function uses model.matrix to create such a matrix from a data frame of covariates.

Usage

1
make_contrasts(X, vars)

Arguments

X

A data frame of covariates. May contain both numeric and categorical features together.

vars

A character vector of covariates to one-hot encode.

Details

No levels are dropped during the one-hot encodeing; a covariate with n levels will turn into n binary columns.

No intercept term is returned in the matrix.

Value

A numeric matrix

Examples

1
2
3
4
5
## Not run: 
 Xdat <- subset(cfex, select = -c(W, Y))
 make_contrasts(Xdat, 'fct')

## End(Not run)

ensley-nexant/cfeval documentation built on May 20, 2020, 12:34 a.m.