一键导入
statistical-modeling
Statistical modeling and machine learning for biomarker discovery, survival analysis, classification, regression, and model interpretation
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Statistical modeling and machine learning for biomarker discovery, survival analysis, classification, regression, and model interpretation
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Molecular structure analysis, SAR triage, compound library characterization, QSAR modeling, ADMET prediction, chemical space visualization, target engagement assessment, drug perturbation connectivity scoring, and selectivity profiling
Chromatin regulation analysis — ATAC-seq, ChIP-seq, CUT&Tag/CUT&Run, differential binding, motif analysis, and scATAC-seq
Systematic drug repurposing via signature matching, target-based analysis, network proximity, genetic evidence scoring, and clinical evidence mining
Functional enrichment and pathway analysis including GSEA, ORA, ssGSEA, GSVA, and decoupler-based activity inference
Genomic variant analysis — germline/somatic SNV, structural variants, CNV, GWAS, annotation, and filtering
Metabolomics and lipidomics analysis — untargeted/targeted workflows, normalization, annotation, and pathway mapping
| name | statistical-modeling |
| description | Statistical modeling and machine learning for biomarker discovery, survival analysis, classification, regression, and model interpretation |
| version | 1.0.0 |
| tags | ["survival","machine-learning","classification","regression","mixed-models","biomarker","shap"] |
This skill guides method selection and execution for survival analysis, classification, regression, feature selection, mixed-effects modeling, and model interpretation in biomedical contexts.
Choose the method based on your outcome type and analytical goal:
lifelines.KaplanMeierFitter for survival curves, logrank_test() for group comparison.lifelines.CoxPHFitter for Cox proportional hazards regression. Check PH assumption with check_assumptions().scikit-survival.RandomSurvivalForest for non-linear survival prediction.scikit-survival.GradientBoostingSurvivalAnalysis for best predictive performance.Escalate complexity only when simpler models underperform:
sklearn.LogisticRegression (interpretable, baseline).sklearn.RandomForestClassifier (handles interactions, feature importance built in).xgboost.XGBClassifier (gradient boosting, tunable).sklearn.Ridge (L2), sklearn.Lasso (L1, sparsity), sklearn.ElasticNet (L1+L2).sklearn.RandomForestRegressor.xgboost.XGBRegressor.sklearn.RFECV with cross-validation for optimal feature count.shap.TreeExplainer for tree-based models to rank features by contribution.sklearn.inspection.permutation_importance.statsmodels.MixedLM (Python).lme4::lmer() / lme4::glmer() via rpy2 for crossed random effects, GLMM.pingouin.ttest(): t-test with Cohen's d, Bayes factor, CI.pingouin.anova() / pingouin.rm_anova(): one-way and repeated measures ANOVA.pingouin.corr(): correlation with multiple methods and CI.pingouin.pairwise_tests(): post-hoc comparisons with correction.sklearn.StratifiedKFold (classification) or sklearn.KFold (regression) with k=5 or k=10.sklearn.calibration.calibration_curve).sklearn.inspection.PartialDependenceDisplay for marginal effect of top features.sklearn.Pipeline to enforce this.cv.glmnet() for cross-validated lambda selection.y ~ C(group) * covariate).gam(y ~ s(x1) + x2)).| File | Purpose |
|---|---|
references/lifelines-api.md | lifelines API: KaplanMeier, CoxPH, log-rank test |
references/scikit-learn-api.md | scikit-learn API: classifiers, regressors, pipelines, CV |
references/scikit-survival-api.md | scikit-survival API: RSF, GBS, concordance index |
references/xgboost-api.md | XGBoost API: XGBClassifier, XGBRegressor, tuning |
references/shap-api.md | SHAP API: TreeExplainer, summary plots, dependence |
references/statsmodels-api.md | statsmodels API: MixedLM, OLS, GLM |
references/pingouin-api.md | pingouin API: ttest, anova, correlation, effect sizes |
Biomarker development has distinct phases. Each analysis step should know which phase it operates in:
Most Cortex analyses operate at phase 1 (discovery) or phase 3 (clinical validation if outcome data is available). Be explicit about which phase the current analysis addresses.
Prognostic: associated with outcome REGARDLESS of treatment. Test: Cox PH or logistic regression with marker as predictor, no treatment interaction term. A gene that predicts poor survival in both treated and untreated patients is prognostic.
Predictive: associated with DIFFERENTIAL response to a specific treatment. Test: include a treatment x marker interaction term in the model. Only if the interaction is significant can the marker be called predictive.
# Prognostic test (marker → outcome)
from lifelines import CoxPHFitter
cph = CoxPHFitter()
cph.fit(df[["time", "event", "marker"]], "time", "event")
# Predictive test (marker x treatment → outcome)
df["marker_x_treatment"] = df["marker"] * df["treatment"]
cph_pred = CoxPHFitter()
cph_pred.fit(
df[["time", "event", "marker", "treatment", "marker_x_treatment"]],
"time", "event",
)
interaction_pval = cph_pred.summary.loc["marker_x_treatment", "p"]
Do NOT call a marker "predictive" unless the interaction test is significant. A marker that is only prognostic has no value for treatment selection.
When a continuous biomarker must be dichotomized (high/low) for clinical use:
# MaxStat approach (survminer-like in Python)
from lifelines import CoxPHFitter
from lifelines.statistics import logrank_test
import numpy as np
def find_optimal_cutpoint(df, marker_col, time_col, event_col,
min_group_frac=0.2):
"""Find optimal cutpoint via maximally selected rank statistics."""
values = df[marker_col].dropna().sort_values().unique()
lo = np.quantile(values, min_group_frac)
hi = np.quantile(values, 1 - min_group_frac)
candidates = values[(values >= lo) & (values <= hi)]
best_stat, best_cut = -np.inf, None
for cut in candidates:
mask = df[marker_col] >= cut
if mask.sum() < 5 or (~mask).sum() < 5:
continue
result = logrank_test(
df.loc[mask, time_col], df.loc[~mask, time_col],
df.loc[mask, event_col], df.loc[~mask, event_col],
)
if result.test_statistic > best_stat:
best_stat = result.test_statistic
best_cut = cut
return best_cut, best_stat
Always report:
Anti-pattern: Optimizing on the same data you report performance on. Use nested CV or a held-out test set.
When building a biomarker panel (signature of multiple markers):
from sklearn.linear_model import LogisticRegressionCV
from sklearn.model_selection import RepeatedStratifiedKFold
from sklearn.metrics import roc_auc_score
import numpy as np
# Panel construction with nested CV
cv_outer = RepeatedStratifiedKFold(n_splits=5, n_repeats=10, random_state=42)
aucs = []
for train_idx, test_idx in cv_outer.split(X, y):
model = LogisticRegressionCV(
penalty="elasticnet", solver="saga", l1_ratios=[0.5],
cv=5, scoring="roc_auc", max_iter=5000, random_state=42,
)
model.fit(X[train_idx], y[train_idx])
prob = model.predict_proba(X[test_idx])[:, 1]
aucs.append(roc_auc_score(y[test_idx], prob))
print(f"AUC: {np.mean(aucs):.3f} (95% CI: {np.percentile(aucs, 2.5):.3f}-{np.percentile(aucs, 97.5):.3f})")
Use sklearn.metrics for ROC analysis in Python:
from sklearn.metrics import (
roc_curve, roc_auc_score, precision_recall_curve,
average_precision_score,
)
import matplotlib.pyplot as plt
# ROC curve with AUC and CI
fpr, tpr, thresholds = roc_curve(y_true, y_score)
auc = roc_auc_score(y_true, y_score)
# Bootstrap AUC CI
from sklearn.utils import resample
boot_aucs = []
for _ in range(1000):
idx = resample(range(len(y_true)), random_state=None)
if len(set(y_true[idx])) < 2:
continue
boot_aucs.append(roc_auc_score(y_true[idx], y_score[idx]))
ci_lo, ci_hi = np.percentile(boot_aucs, [2.5, 97.5])
# Youden's J for optimal threshold
j_scores = tpr - fpr
best_idx = np.argmax(j_scores)
optimal_threshold = thresholds[best_idx]
Always report BOTH AUC-ROC and AUPRC. For imbalanced datasets, AUPRC is more informative than AUC-ROC.