agentsclimarketplace

Missing value imputation for pca

Skill HolobiomicsLab/asb-skill-collections/collections/metabolomics/v2/skills/missing-value-imputation-for-pca

Use when your metabolomic dataset contains missing values (common in untargeted or targeted mass spectrometry data) and you need to perform PCA for outlier detection at multiple standard deviation thresholds (e.g., 3 SD, 4 SD, 5 SD) on principal component scores.From its SKILL.md

Install
npx -y skills add HolobiomicsLab/asb-skill-collections --skill missing-value-imputation-for-pca

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 15 stars15 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its file declares

Copied from the file, not written here

The file declares its own license as CC-BY-4.0. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

8.2 KB, ~1.5k tokens by cl100k_base, as published. Nobody here has run it

missing-value-imputation-for-pca

License: restricted — no clear open-source license detected for the underlying tool; verify licensing before commercial use or redistribution. <!-- asb-license-banner -->

Summary

Impute missing values to the median prior to principal component analysis in metabolomic datasets to enable PCA-based outlier detection and dimensionality reduction. This preprocessing step is essential because PCA requires a complete data matrix and median imputation preserves the distributional properties needed for downstream SD-based outlier thresholding.

When to use

Your metabolomic dataset contains missing values (common in untargeted or targeted mass spectrometry data) and you need to perform PCA for outlier detection at multiple standard deviation thresholds (e.g., 3 SD, 4 SD, 5 SD) on principal component scores. This is particularly relevant when quality control workflows require identification of sample outliers in PC space before or after batch normalization.

When NOT to use

  • Your data contains no missing values and you wish to avoid unnecessary imputation that might alter PC loadings.
  • You have strong prior biological knowledge that missingness is non-random (MNAR) and requires domain-specific imputation (e.g., values below LOD); median imputation assumes data are missing at random (MAR) or completely at random (MCAR).
  • Your workflow requires preservation of the original missing data structure for sensitivity analysis or comparison of imputation methods; use this skill only after such comparisons are complete.

Inputs

  • Metaboprep object containing metabolomic data with potential missing values
  • source_layer parameter specifying the data layer to impute (e.g., 'input')
  • optional sample_ids and feature_ids filters to subset the data before imputation

Outputs

  • Complete (non-missing) data matrix with missing values replaced by feature medians
  • data.frame containing PC eigenvectors for the top 10 PCs
  • outlier count vector for samples at 3 SD, 4 SD, and 5 SD thresholds on top two PCs
  • attributes: variance explained vector, acceleration factor result, parallel analysis result

How to apply

Before calling pc_and_outliers() or performing PCA within the quality_control() pipeline, the metaboprep package automatically imputes missing data to the median of each feature. This median imputation is applied after loading the data into a Metaboprep object and prior to acceleration analysis and parallel analysis to determine the number of significant PCs. The rationale is that median imputation is robust to skewed distributions common in metabolomics data and avoids bias introduced by mean imputation. After imputation, the complete data matrix is then subjected to PCA, with sample outlier counts computed on the top two PCs at 3 SD, 4 SD, and 5 SD thresholds. The choice of median over other imputation methods (e.g., mean, KNN, MICE) is justified by its simplicity and stability in high-dimensional omics contexts.

Related tools

  • metaboprep (Implements median imputation internally within pc_and_outliers() and quality_control() workflows) — https://github.com/MRCIEU/metaboprep
  • R (Computational environment for executing imputation and PCA operations)

Examples

mydata <- mydata |> quality_control(source_layer = "input", sample_missingness = 0.2, feature_missingness = 0.2, pc_outlier_sd = 5)

Evaluation signals

  • Check that the output data matrix contains zero missing values (NA count = 0) after imputation.
  • Verify that imputed values fall within the range [min, max] of observed feature values and equal the median of each feature's non-missing data.
  • Confirm that PCA variance explained by the top 2 PCs is reasonable (typically >30% for metabolomic data) and that PC scores are finite (no NaN or Inf).
  • Validate that outlier counts at 3 SD, 4 SD, and 5 SD thresholds form a nested hierarchy (outliers_3SD ≥ outliers_4SD ≥ outliers_5SD).
  • Compare PC eigenvector magnitudes before and after imputation to ensure the imputation does not artificially inflate or suppress PC loadings.

Limitations

  • Median imputation assumes data are missing at random (MAR) or completely at random (MCAR); it is inappropriate for missing-not-at-random (MNAR) data such as values below a detection limit that are systematically missing.
  • Median imputation does not account for feature correlations and may underestimate variance in high-dimensional spaces; more sophisticated methods (KNN, MICE) may be preferable if missingness exceeds ~30% of the matrix.
  • The metaboprep implementation uses a fixed imputation strategy (median only); no option to select or compare alternative imputation methods (e.g., mean, minimum, KNN) is exposed via the pc_and_outliers() interface.
  • If a feature has >50% missing values, its median is unstable and may not represent the true central tendency; extreme feature missingness should be filtered before imputation (metaboprep provides feature_missingness threshold for this purpose).

Evidence

  • [other] The function internally imputes missing data to the median, performs acceleration analysis and parallel analysis to determine the number of significant PCs, and computes sample outlier counts at 3 SD, 4 SD, and 5 SD thresholds on the top two PCs.: "The function internally imputes missing data to the median, performs acceleration analysis and parallel analysis to determine the number of significant PCs, and computes sample outlier counts at 3"
  • [readme] Run QC example showing the quality_control pipeline which calls pc_and_outliers internally: mydata <- mydata |> quality_control( source_layer = "input", sample_missingness = 0.2, feature_missingness = 0.2, total_peak_area_sd = 5, outlier_udist = 5, outlier_treatment = "leave_be", winsorize_quantile = 1.0, tree_cut_height = 0.5, pc_outlier_sd = 5, sample_ids = NULL, feature_ids = NULL): "mydata <- mydata |> quality_control( source_layer = "input", sample_missingness = 0.2, feature_missingness = 0.2, total_peak_area_sd = 5, outlier_udist = 5, outlier_treatment = "leave_be","
  • [other] The metaboprep package provides data filtering capabilities using a standard pipeline with user-defined thresholds, which includes outlier detection mechanisms applied to principal components at configurable standard deviation cutoffs.: "The metaboprep package provides data filtering capabilities using a standard pipeline with user-defined thresholds, which includes outlier detection mechanisms applied to principal components at"
  • [other] Load a Metaboprep object containing metabolomic data (or subset by sample_ids and/or feature_ids). Call pc_and_outliers() with the Metaboprep object, specify source_layer (e.g., 'input'), and optional sample/feature ID filters.: "Load a Metaboprep object containing metabolomic data (or subset by sample_ids and/or feature_ids). Call pc_and_outliers() with the Metaboprep object, specify source_layer (e.g., 'input'), and"

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.