View source: R/correct_outliers.R
correct_outliers | R Documentation |
This function identifies and corrects outliers in a dataset using principal component analysis (PCA). It scales the data, performs PCA, computes idiosyncratic components, and replaces values that fall outside a defined outlier threshold with the median of 5 previous values. The outlier threshold is determined using the interquartile range (IQR) method.
correct_outliers(data, r)
data |
A numeric matrix or data frame where rows represent observations and columns represent variables. |
r |
An integer specifying the number of principal components to use for PCA. |
A list containing:
data |
A matrix with corrected data where outliers are replaced by the median of previous values. |
outliers |
A binary matrix (same dimensions as the input data) indicating the position of outliers. |
data <- matrix(rnorm(100), nrow = 10, ncol = 10)
result <- correct_outliers(data, r = 3)
corrected_data <- result$data
outliers_matrix <- result$outliers
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.