PCA-Based Outlier Detection Using LOF
outlier_pca_lof.RdPerforms Principal Component Analysis (PCA) on a data frame and identifies
sample outliers using the Local Outlier Factor (LOF) method. Optionally
returns a ggplot2 pair plot of the PCA scores coloured by LOF. Samples
detected as outliers are removed from the returned data.
Value
A list with the following elements:
- df
Filtered data frame with outliers removed. If missing values are present, the original input is returned unchanged.
- plot_samples_outlier
A
ggplot2object showing PCA and LOF scores, orNULLifreturn_ggplot = FALSEor if missing values were found.- id_samples_outlier
A character vector of sample IDs (rownames) identified as outliers, or
NULLif skipped.