Learn R Programming

tidysynthesis (version 0.1.2)

add_noise_kde: Add normal noise to predicted values with variances calculated for ntiles using Gaussian kernel density estimators

Description

Add normal noise to predicted values with variances calculated for ntiles using Gaussian kernel density estimators

Usage

add_noise_kde(
  model,
  new_data,
  conf_model_data,
  outcome_var,
  col_schema,
  pred,
  exclusions = NULL,
  n_ntiles = NULL,
  obs_per_ntile = NULL,
  ties_method = "collapse",
  sd_scale = 1
)

Value

A numeric vector with noise added to each prediction

Arguments

model

A model_spec or a list of model_specs from library(parsnip)

new_data

A data frame used to generate predictions

conf_model_data

A data frame for estimating the predictive model

outcome_var

A string name representing the outcome variable

col_schema

A list of column schema specifications for the new variable

pred

A vector of values predicted by the model

exclusions

Numeric values that should not receive extra noise

n_ntiles

The number of ntiles

obs_per_ntile

A numeric for the minimum number of observations to be in an ntile. Cannot be used in conjunction with the n_ntiles argument.

ties_method

The ntiles approach to adding noise requires a one-to-one mapping from model-generated values to ntiles in the original data. The methods "collapse", "random", and "exclusions" deal with situations where the ntiles lack unique bounds. "collapse" collapses ntile breaks to preserve the one-to-one relationship; "random" adds a small random perturbation to the derived boundaries; finally, "exclusions" treats ntile tie values as derived exclusions.

sd_scale

float, a positive number to scale the estimated KDE variance. Defaults to 1.0

Examples

Run this code

add_noise_kde(
  model = NULL,
  new_data = tibble::tibble(x = 1:100),
  conf_model_data = tibble::tibble(x = 1:100),
  outcome_var = "x",
  col_schema = NULL,
  pred = 1:100,
  n_ntiles = 4
)

Run the code above in your browser using DataLab