Helpers for steps with case weightsSource:
These functions can be used to do basic calculations with or without case weights.
get_case_weights(info, .data) averages(x, wts = NULL, na_rm = TRUE) medians(x, wts = NULL) variances(x, wts = NULL, na_rm = TRUE) correlations(x, wts = NULL, use = "everything", method = "pearson") covariances(x, wts = NULL, use = "everything", method = "pearson") pca_wts(x, wts = NULL) are_weights_used(wts, unsupervised = FALSE)
A data frame from the
infoargument within steps
The training data
A numeric vector or a data frame
A vector of case weights
A logical value indicating whether
NAvalues should be removed during computations.
Can the step handle unsupervised weights
get_case_weights() is designed for developers of recipe steps, to return
a column with the role of "case weight" as a vector.
For the other functions, rows with missing case weights are removed from calculations.
variances(), missing values in the data (not the
case weights) only affect the calculations for those rows. For
correlations(), the correlation matrix computation first removes rows
with any missing values (equal to the "complete.obs" strategy in
are_weights_used() is designed for developers of recipe steps and is used
inside print method to determine how printing should be done.