Learn R Programming

healthyR.ai (version 0.1.0)

hai_polynomial_augment: Augment Polynomial Features

Description

This function takes in a data table and a predictor column. A user can either create their own formula using the .formula parameter or, if they leave the default of NULL then the user must enter a .degree AND .pred_col column.

Usage

hai_polynomial_augment(
  .data,
  .formula = NULL,
  .pred_col = NULL,
  .degree = 1,
  .new_col_prefix = "nt_"
)

Value

An augmented tibble

Arguments

.data

The data being passed that will be augmented by the function.

.formula

This should be a valid formula like 'y ~ .^2' or NULL.

.pred_col

This is passed rlang::enquo() to capture the vector that you designate as the 'y' column.

.degree

This should be an integer and is used to set the degree in the poly function. The degree must be less than the unique data points or it will error out.

.new_col_prefix

The default is "nt_" which stands for "new_term". You can set this to whatever you like, as long as it is a quoted string.

Author

Steven P. Sanderson II, MPH

Details

A valid data.frame/tibble must be passed to this function. It is required that a user either enter a .formula or a .degree AND .pred_col otherwise this function will stop and error out.

Under the hood this function will create a stats::poly() function if the .formula is left as NULL. For example:

  • .formula = A ~ .^2

  • OR .degree = 2, .pred_col = A

There is also a parameter .new_col_prefix which will add a character string to the column names so that they are easily identified further down the line. The default is 'nt_'

See Also

Other Augment Function: hai_fourier_augment(), hai_fourier_discrete_augment(), hai_hyperbolic_augment(), hai_scale_zero_one_augment(), hai_scale_zscore_augment(), hai_winsorized_move_augment(), hai_winsorized_truncate_augment()

Examples

Run this code
suppressPackageStartupMessages(library(dplyr))
data_tbl <- data.frame(
  A = c(0, 2, 4),
  B = c(1, 3, 5),
  C = c(2, 4, 6)
)

hai_polynomial_augment(.data = data_tbl, .pred_col = A, .degree = 2, .new_col_prefix = "n")
hai_polynomial_augment(.data = data_tbl, .formula = A ~ .^2, .degree = 1)

Run the code above in your browser using DataLab