sample-correlation-analysis
/sample-correlation-analysis
Use when performing correlation analysis between two variables including Pearson and Spearman correlation methods. Supports command-line parameter input, automatic data format detection, parameter validation, result directory creation, and CSV or TXT format result export.
- Author
- aipoch ↗
- Repository
- medical-research-skills ↗
- Licence
- MIT
- Last repository change
- 17.09.2026
Assessment and security
- Files in this package
- 12
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 3
No signals detected. Repository changed on 17.09.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
Use when performing correlation analysis between two variables including Pearson and Spearman correlation methods. Supports command-line parameter input, automatic data format detection, parameter validation, result directory creation, and CSV or TXT format result export.
Original author description
Use when performing correlation analysis between two variables including Pearson and Spearman correlation methods. Supports command-line parameter input, automatic data format detection, parameter validation, result directory creation, and CSV or TXT format result export.
How it works
- Use This Skill When
- Primary Command
- Prerequisites
- Core Arguments
- Input Requirements
- Minimal Workflow
- Outputs
- Choose the Method
- Read These Files When Needed
- Quick Examples
SKILL.md preview
---
name: sample-correlation-analysis
description: Use when performing correlation analysis between two variables including Pearson and Spearman correlation methods. Supports command-line parameter input, automatic data format detection, parameter validation, result directory creation, and CSV or TXT format result export.
license: MIT
author: AIPOCH
---
> **Source**: [https://github.com/aipoch/medical-research-skills](https://github.com/aipoch/medical-research-skills)
# Correlation Analysis
Use this skill to run correlation analysis on two variables from a tabular data file.
## Use This Skill When
- You need Pearson or Spearman correlation between two variables stored either as columns or as first-column row labels.
- You need a command-line workflow with parameter validation.
- You need standardized output files in CSV or TXT format.
## Primary Command
```bash
Rscript scripts/main.R \
--data_file <input_file> \
--method <pearson|spearman> \
--x_var <variable_name> \
--y_var <variable_name> \
--output_dir <output_dir>
```
## 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
| Argument | Required | Description |
|----------|----------|-------------|
| `--data_file` | Yes | Input data file in CSV, TXT, or TSV format |
| `--method` | No | Correlation method: `pearson` or `spearman`. Default `pearson` |
| `--x_var` | No | First variable name. It can match a column name or a first-column row label. Default `variable1` |
| `--y_var` | No | Second variable name. It can match a column name or a first-column row label. Default `variable2` |
| `--output_dir` | No | Output directory, default `./Correlation_Results` |
| `--alternative` | No | `two.sided`, `less`, or `greater`. Default `two.sided` |
| `--conf_level` | No | Confidence level between 0 and 1, default `0.95` |
| `--output_format` | No | `csv` or `txt`, default `csv` |
| `--output_prefix` | No | Output filename prefix, default `correlation` |
## Input Requirements
- The input file must contain both target variables.
- Both variables must contain numeric values.
- If the first column stores variable names and the remaining columns are samples, the script automatically reads variables by row label.
- Rows with missing values in either variable are excluded.
- At least 3 complete observation pairs are needed.
Example input:
```csv
variable1,variable2
10.2,8.5
11.5,9.2
9.8,7.9
```
## Minimal Workflow
1. Confirm the input file exists and variable names are correct.
2. Run `scripts/main.R` with the requested method and variable names.
3. Check the output directory for result files under `table/`.
If you omit `--data_file`, the script exits with `SKILL_MISSING_INPUT`.
## Outputs
Expected output structure:
```text
<output_dir>/
├── table/
├── figure/
└── data/
```
Primary result file:
- `table/<output_prefix>_<method>.csv`
- `table/<output_prefix>_<method>.txt`
Result fields include:
- `method`
- `correlation`
- `statistic`
- `p_value`
- `conf_low`
- `conf_high`
- `sample_size`
- `x_variable`
- `y_variable`
- `variable_orientation`
## Choose the Method
- Use `pearson` for linear relationships between continuous variables.
- Use `spearman` for monotonic relationships, non-normal data, or outlier-prone data.
## Read These Files When Needed
| Need | File |
|------|------|
| Statistical details and assumptions | `references/algorithm.md` |
| More CLI examples | `references/cli-guide.md` |
| Error diagnosis | `references/troubleshooting.md` |
| Main execution entry point | `scripts/main.R` |
| Sample test data | `tests/data/` |
## Quick Examples
Pearson:
```bash
Rscript scripts/main.R \
--data_file tests/data/sample_correlation_1.csv \
--method pearson \
--x_var variable1 \
--y_var variable2 \
--output_dir tests/output_pearson
```
Spearman:
```bash
Rscript scripts/main.R \
--data_file tests/data/sample_correlation_3.csv \
--method spearman \
--x_var "Activated CD8 T cell" \
--y_var "Central memory CD8 T cell" \
--output_dir tests/output_spearman
```
## Validation
```bash
Rscript scripts/main.R --help
```
```bash
Rscript scripts/main.R \
--data_file tests/data/sample_correlation_1.csv \
--method pearson \
--x_var variable1 \
--y_var variable2 \
--output_dir tests/validation_output
```
After running analysis, verify that `tests/validation_output/table/correlation_pearson.csv` exists.
## Common Errors
- `SKILL_FILE_NOT_FOUND`: Input file path is wrong or inaccessible.
- `SKILL_MISSING_COLUMNS`: One or both requested variables are missing.
- `SKILL_INVALID_DATA`: Input data is malformed or unsuitable for analysis.
- `SKILL_INVALID_PARAMETER`: An argument value is invalid.
- `SKILL_INSUFFICIENT_DATA`: Too few complete observations remain after filtering.
- `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`.
Files in this package (12)
- SKILL.md 5 KB
- eval_report_sample-correlation-analysis_result.json 16 KB
- references/algorithm.md 6 KB
- references/cli-guide.md 7 KB
- references/troubleshooting.md 8 KB
- scripts/functions.R 4 KB
- scripts/main.R 3 KB
- scripts/run_analysis.R 3 KB
- scripts/utils.R 3 KB
- tests/data/sample_correlation_1.csv 1 KB
- tests/data/sample_correlation_2.csv 69 KB
- tests/data/sample_correlation_3.csv 6 KB
Versions
The database has no other skills named sample-correlation-analysis.
Database snapshot: 13.11.2026 · package version 8f39a2a5e1d4 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100pca-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. - 100correlation-auditor
Analyzes correlation matrices (Pearson/Spearman), computes partial correlations to control for confounding variables, and flags potential spurious correlations in your data. Triggered when users ask about relationships between variables, need correlation matrices, or mention… - 90correlation-analysis
Detect and compute correlations between numeric variables in a dataset. Use when the user wants to see how variables in a CSV/Parquet/Excel file move together — Pearson, Spearman, or Kendall — with a short report flagging the strongest positive and negative pairs. - 100corr-insight
计算变量间的Pearson或Spearman相关矩阵、偏相关分析,并自动识别因混淆变量导致的伪相关。当用户需要检查数据相关性、计算相关系数、进行偏相关分析,或提及伪相关、spurious correlation、混淆变量等关键词时触发。 - 100correlation-analyzer
Analyze correlation analyzer operations. Auto-activating skill for Data Analytics. Triggers on: correlation analyzer, correlation analyzer Part of the Data Analytics skill category. Use when analyzing or auditing correlation analyzer. Trigger with phrases like "correlation… - 100km-survival-curve
Use when generating Kaplan-Meier survival curves from tabular survival data containing time, event status, and a precomputed risk group. Supports command-line parameter input, parameter validation, automatic time-unit handling, single-file PDF figure export, and session metadata capture.