Skip to content
cccskills
FreePublished on GitHub

pca-dimensionality-reduction

Use when performing PCA principal component dimensionality reduction on tabular numeric data. Supports command-line parameter input, automatic numeric feature selection, parameter validation, result directory creation, and CSV or TXT format result export.

The English summary is being prepared. Showing the original description.

Run score Not tested

See how to install

Files included (12)

  • SKILL.md5.9 KB
  • eval_report_pca-dimensionality-reduction_result.json14.7 KB
  • references/algorithm.md4.0 KB
  • references/cli-guide.md3.8 KB
  • references/troubleshooting.md3.8 KB
  • scripts/functions.R7.8 KB
  • scripts/main.R3.6 KB
  • scripts/run_analysis.R5.2 KB
  • scripts/utils.R5.3 KB
  • tests/data/sample_pca_1.csv429 B
  • tests/data/sample_pca_2.csv3.2 MB
  • tests/data/sample_pca_3.csv228 B

SKILL.md (original)

Review the instructions the agent will receive before you install.

Source: https://github.com/aipoch/medical-research-skills

PCA Dimensionality Reduction Analysis

Use this skill to run principal component analysis on a tabular dataset and export explained variance, sample scores, feature loadings, and diagnostic figures.

Use This Skill When

  • You need to reduce multiple numeric variables into a smaller set of principal components.
  • You need a command-line PCA workflow with parameter validation.
  • You need standardized output files for downstream analysis.

Primary Command

Rscript scripts/main.R \
  --data_file <input_file> \
  --output_dir <output_dir> \
  --feature_columns <comma_separated_numeric_columns>

Prerequisites

  • Rscript is available in the shell.
  • Required R packages: optparse, data.table.
  • Install missing packages with Rscript -e 'install.packages(c("optparse", "data.table"), repos="https://cloud.r-project.org")'.

Core Arguments

ArgumentRequiredDescription
--data_fileYesInput data file in CSV, TXT, or TSV format
--output_dirNoOutput directory, default ./PCA_Results
--feature_columnsNoComma-separated numeric feature columns. Default uses all numeric columns except ID/group columns
--sample_id_columnNoOptional sample ID column. If omitted and the first column is non-numeric with unique values, it is used automatically
--group_columnNoOptional grouping column to carry into score output and score plot
--n_componentsNoMaximum number of principal components to export, default 5
--center_dataNotrue or false, default true
--scale_dataNotrue or false, default true
--top_loadingsNoNumber of top absolute loadings to export per component, default 10
--output_formatNocsv or txt, default csv
--output_prefixNoOutput filename prefix, default pca

Input Requirements

  • The input file must contain at least 2 usable numeric feature columns.
  • PCA is run on rows as samples and columns as features.
  • Missing or non-finite values in selected feature columns are removed row-wise before analysis.
  • At least 2 complete samples must remain after filtering.
  • Selected feature columns must have non-zero variance after filtering.

Example input:

SampleID,Group,GeneA,GeneB,GeneC,GeneD
S01,Control,2.1,1.9,8.2,4.3
S02,Control,2.4,2.2,8.0,4.6
S03,Treated,6.1,5.7,2.8,8.1

Minimal Workflow

  1. Confirm the input file exists and identify the numeric feature columns for PCA.
  2. Run scripts/main.R with the requested output directory and optional feature, ID, or group columns.
  3. Check the output directory for result files under table/, data/, and figure/.

If you omit --data_file, the script exits with SKILL_MISSING_INPUT.

Outputs

Expected output structure:

<output_dir>/
├── table/
├── figure/
└── data/

Primary result files:

  • table/<output_prefix>_summary.csv
  • table/<output_prefix>_scores.csv
  • table/<output_prefix>_loadings.csv
  • table/<output_prefix>_top_loadings.csv

Figure files:

  • figure/<output_prefix>_scree_plot.png
  • figure/<output_prefix>_score_plot.png

Key fields include:

  • component
  • standard_deviation
  • variance
  • proportion_variance
  • cumulative_variance
  • sample_id
  • feature
  • loading

Interpretation Guide

  • Use proportion_variance and cumulative_variance to decide how many components to retain.
  • Use the score table to inspect sample separation in PC space.
  • Use the loading tables to identify which original variables drive each component.

Read These Files When Needed

NeedFile
PCA method details and interpretationreferences/algorithm.md
More CLI examplesreferences/cli-guide.md
Error diagnosisreferences/troubleshooting.md
Main execution entry pointscripts/main.R
Sample test datatests/data/

Quick Examples

Basic PCA with explicit feature columns:

Rscript scripts/main.R \
  --data_file tests/data/sample_pca_1.csv \
  --sample_id_column SampleID \
  --group_column Group \
  --feature_columns GeneA,GeneB,GeneC,GeneD,GeneE \
  --output_dir tests/output_basic

Auto-detect all numeric columns:

Rscript scripts/main.R \
  --data_file tests/data/sample_pca_2.csv \
  --n_components 3 \
  --output_dir tests/output_numeric_only

Disable scaling:

Rscript scripts/main.R \
  --data_file tests/data/sample_pca_1.csv \
  --sample_id_column SampleID \
  --group_column Group \
  --scale_data false \
  --output_dir tests/output_unscaled

Validation

Rscript scripts/main.R --help
Rscript scripts/main.R \
  --data_file tests/data/sample_pca_1.csv \
  --sample_id_column SampleID \
  --group_column Group \
  --feature_columns GeneA,GeneB,GeneC,GeneD,GeneE \
  --output_dir tests/validation_output

After running analysis, verify that tests/validation_output/table/pca_summary.csv exists.

Common Errors

  • SKILL_FILE_NOT_FOUND: Input file path is wrong or inaccessible.
  • SKILL_MISSING_COLUMNS: A requested feature, sample ID, or group column is missing.
  • SKILL_INVALID_DATA: Input data is malformed or unsuitable for PCA.
  • SKILL_INVALID_PARAMETER: An argument value is invalid.
  • SKILL_INSUFFICIENT_DATA: Too few complete samples or features remain for PCA.
  • SKILL_DEPENDENCY_MISSING: A required R package such as optparse or data.table is unavailable.

If the issue is not obvious, read references/troubleshooting.md.

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

Transform lengthy academic papers into concise, structured 250-word abstracts.

The English summary is being prepared. Showing the original description.

aipoch/medical-research-skills2KUpdated Sep 17, 2026

Precision editing tool that reduces abstract word count through intelligent compression techniques, maintaining scientific rigor while meeting strict journal and conference requirements.

The English summary is being prepared. Showing the original description.

aipoch/medical-research-skills2KUpdated Sep 17, 2026

Refines long medical academic texts into SCI-style unstructured Chinese and English abstracts; use when you need to condense drafts/reports/summaries into bilingual abstracts and generate Summary_Report.md.

The English summary is being prepared. Showing the original description.

aipoch/medical-research-skills2KUpdated Sep 17, 2026

Generates submission-ready Elsevier/SCI Highlights from manuscript text or extracted PDF/DOCX/TXT content. Use when a user needs 3-5 concise, evidence-grounded highlight bullets for a research paper, review, meta-analysis, case report, or bioinformatics manuscript.

The English summary is being prepared. Showing the original description.

aipoch/medical-research-skills2KUpdated Sep 17, 2026

Generates complete FAERS pharmacovigilance study designs for multi-drug or class-level safety comparison inside one predefined SOC or AE family using active comparators, disproportionality analysis, subgroup characterization, and reviewer-facing evidence control.

The English summary is being prepared. Showing the original description.

aipoch/medical-research-skills2KUpdated Sep 17, 2026

Analyze data with `adme-property-predictor` using a reproducible workflow, explicit validation, and structured outputs for review-ready interpretation.

The English summary is being prepared. Showing the original description.

aipoch/medical-research-skills2KUpdated Sep 17, 2026

See all skills by aipoch

Report a problem with this skill