tombolo.plots.forest_plot
1import re 2import jsonschema 3import matplotlib.pyplot as plt 4 5from .primitives.forest import _forest 6 7_matrix = { 8 "type": "object", 9 "additionalProperties": { 10 "type": "object", 11 "additionalProperties": {"type": ["number", "null"]}, 12 }, 13} 14 15_schema = { 16 "type": "object", 17 "required": ["league"], 18 "properties": { 19 "league": { 20 "type": "object", 21 "required": ["md", "lower", "upper"], 22 "properties": { 23 "md": _matrix, 24 "lower": _matrix, 25 "upper": _matrix, 26 "pval": _matrix, 27 }, 28 } 29 }, 30} 31 32 33def forest_plot(data: dict, reference: str) -> plt.Figure: 34 """Forest plot of all treatments relative to a reference. 35 36 Args: 37 data: Result dict from `tombolo.nma` or `tombolo.bnma`. Only `league` is used. 38 reference: Name of the reference treatment. All other treatments are plotted 39 relative to it, sorted by effect size. Non-alphanumeric characters are 40 normalized to underscores. 41 42 Returns: 43 Mean differences and confidence (or credible) intervals for each treatment 44 versus the reference. P-values are included for NMA results. 45 46 Raises: 47 RuntimeError: If `reference` is not found in the data. 48 """ 49 jsonschema.validate(instance=data, schema=_schema) 50 ref = re.sub(r"[^A-Za-z0-9_]", "_", reference) 51 if ref not in data["league"]["md"]: 52 raise RuntimeError("Missing reference") 53 label = "[95% CI]" if "pval" in data["league"] else "[95% CrI]" 54 return _forest(data["league"], ref, interval_label=label)
def
forest_plot(data: dict, reference: str) -> matplotlib.figure.Figure:
34def forest_plot(data: dict, reference: str) -> plt.Figure: 35 """Forest plot of all treatments relative to a reference. 36 37 Args: 38 data: Result dict from `tombolo.nma` or `tombolo.bnma`. Only `league` is used. 39 reference: Name of the reference treatment. All other treatments are plotted 40 relative to it, sorted by effect size. Non-alphanumeric characters are 41 normalized to underscores. 42 43 Returns: 44 Mean differences and confidence (or credible) intervals for each treatment 45 versus the reference. P-values are included for NMA results. 46 47 Raises: 48 RuntimeError: If `reference` is not found in the data. 49 """ 50 jsonschema.validate(instance=data, schema=_schema) 51 ref = re.sub(r"[^A-Za-z0-9_]", "_", reference) 52 if ref not in data["league"]["md"]: 53 raise RuntimeError("Missing reference") 54 label = "[95% CI]" if "pval" in data["league"] else "[95% CrI]" 55 return _forest(data["league"], ref, interval_label=label)
Forest plot of all treatments relative to a reference.
Args:
data: Result dict from tombolo.nma or tombolo.bnma. Only league is used.
reference: Name of the reference treatment. All other treatments are plotted
relative to it, sorted by effect size. Non-alphanumeric characters are
normalized to underscores.
Returns: Mean differences and confidence (or credible) intervals for each treatment versus the reference. P-values are included for NMA results.
Raises:
RuntimeError: If reference is not found in the data.