rhino-sdk-metrics
Rhino Health SDK — Metrics Guide
Help configure and run any of the 40+ federated metrics in the rhino-health Python SDK (v2.1.x).
Context Loading
Before responding, read these reference files:
-
Metrics Reference —
../../context/metrics_reference.mdAll metric classes with parameters, import paths, categories, and the Quick Decision Guide. -
Patterns & Gotchas —
../../context/patterns_and_gotchas.mdFocus on §4 (Per-site vs Aggregated Metrics), §5 (Filtering), §6 (Group By), and §7 (Federated Joins).
Metric Decision Tree
Map the user's question to the right metric class:
| User asks about... | Metric class | Category |
|---|---|---|
| Counts, frequencies | Count |
Basic |
| Averages, means | Mean |
Basic |
| Spread, variability | StandardDeviation, Variance |
Basic |
| Totals, sums | Sum |
Basic |
| Percentiles, medians, quartiles | Percentile, NPercentile |
Quantile |
| Survival time, time-to-event | KaplanMeier |
Survival |
| Hazard ratios, covariates + survival | Cox |
Survival |
| ROC curves, AUC | RocAuc |
ROC/AUC |
| ROC with confidence intervals | RocAucWithCI |
ROC/AUC |
| Correlation between variables | Pearson, Spearman |
Statistics |
| Inter-rater reliability | ICC |
Statistics |
| Compare two group means | TTest |
Statistics |
| Compare 3+ group means | OneWayANOVA |
Statistics |
| Categorical association | ChiSquare |
Statistics |
| 2x2 contingency table | TwoByTwoTable |
Epidemiology |
| Odds ratio | OddsRatio |
Epidemiology |
| Risk ratio / relative risk | RiskRatio |
Epidemiology |
| Risk difference | RiskDifference |
Epidemiology |
| Incidence rates | Incidence |
Epidemiology |
If unsure, consult the full Quick Decision Guide in metrics_reference.md.
Execution Mode
Choose the right execution method based on scope:
| Scope | Method | Signature |
|---|---|---|
| Single site/dataset | session.dataset.get_dataset_metric(dataset_uid, config) |
One dataset UID (str) |
| Single site (shorthand) | dataset.get_metric(config) |
Called on a Dataset object |
| Aggregated across sites | session.project.aggregate_dataset_metric(dataset_uids, config) |
List[str] of UIDs — must be strings, not Dataset objects |
| Federated join (SQL-like) | session.project.joined_dataset_metric(config, query_datasets, filter_datasets) |
List[str] UIDs for both params |
All metrics are imported from rhino_health.lib.metrics (NOT rhino_health.metrics).
Filtering
Apply filters to narrow the data before computing the metric. Two approaches:
Inline FilterVariable (for simple per-column filters)
from rhino_health.lib.metrics import Mean, FilterType, FilterVariable
config = Mean(
variable="Height",
data_filters=[
FilterVariable(
data_column="Gender",
filter_column="Gender",
filter_value="Female",
filter_type=FilterType.EQUALS,
)
],
)
Range Filter (BETWEEN)
from rhino_health.lib.metrics import FilterBetweenRange, FilterType, FilterVariable
config = Mean(
variable="Height",
data_filters=[
FilterVariable(
data_column="Age",
filter_column="Age",
filter_value=FilterBetweenRange(min=18, max=65),
filter_type=FilterType.BETWEEN,
)
],
)
Grouping
Split results by one or more categorical columns:
config = Mean(
variable="Height",
group_by={"groupings": ["Gender"]},
)
Grouping and filtering can be combined on any metric.
Response Format
Structure every response as:
- Recommended metric — which class and why it fits the user's question
- Configuration — complete metric config object with correct import path
- Execution call — the right method (
get_dataset_metric,aggregate_dataset_metric, orjoined_dataset_metric) with correct parameter types - Filtering/grouping — if the user specified subsets or breakdowns, add the appropriate
data_filtersand/orgroup_by - See also — point to a matching example from
../../context/examples/INDEX.mdif one exists
Working Examples
Check ../../context/examples/INDEX.md for matching examples. Key ones for metrics:
eda.py— per-site and aggregated metrics with filtering and groupingcox.py— Cox proportional hazard regressionmetrics_examples.py— TwoByTwoTable, OddsRatio, ChiSquare, TTest, ANOVAroc_analysis.py— ROC curves and confidence intervalsaggregate_quantile.py— federated percentile calculations