.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/07_patterns/plot_27_validated_hyperedges.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via Binder. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_07_patterns_plot_27_validated_hyperedges.py: Statistically validated hyperedges ================================== Frequent is not the same as significant: groups of very active vertices co-occur often by chance. Testing every observed group against the iterated hypergeometric null model (after Musciotto et al. 2021) keeps only the over-expressed hyperedges. A planted set of repeated groups among random noise is recovered. .. GENERATED FROM PYTHON SOURCE LINES 13-30 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np import hatvis as hv rng = np.random.default_rng(0) nodes = [f"n{i}" for i in range(40)] planted = [["n1", "n2", "n3"], ["n4", "n5", "n6"], ["n7", "n8"], ["n1", "n9", "n10", "n11"]] edges = [g for g in planted for _ in range(6)] edges += [list(rng.choice(nodes, size=rng.integers(2, 5), replace=False)) for _ in range(300)] H = hv.Hypergraph(edges) # [snippet:validate] table = hv.patterns.validated_hyperedges(H, alpha=0.01, correction="bonferroni") # [/snippet:validate] print(table.head(8).to_string()) print("validated:", [sorted(s) for s in table.loc[table["validated"], "hyperedge"]]) .. rst-class:: sphx-glr-script-out .. code-block:: none hyperedge size multiplicity expected p_value tests validated 0 (n9, n11, n1, n10) 4 6 0.042161 8.711369e-14 91390 True 1 (n2, n3, n1) 3 6 0.111706 3.382625e-11 9880 True 2 (n4, n6, n5) 3 6 0.247472 1.339840e-08 9880 True 3 (n7, n8) 2 6 0.880435 9.025859e-06 741 True 4 (n14, n32, n9) 3 2 0.058166 1.206976e-03 9880 False 5 (n29, n37, n23) 3 2 0.071386 1.851325e-03 9880 False 6 (n37, n32, n34, n14) 4 1 0.002124 2.122291e-03 91390 False 7 (n25, n24, n14, n8) 4 1 0.002973 2.970453e-03 91390 False validated: [['n1', 'n10', 'n11', 'n9'], ['n1', 'n2', 'n3'], ['n4', 'n5', 'n6'], ['n7', 'n8']] .. GENERATED FROM PYTHON SOURCE LINES 31-37 .. code-block:: Python fig, ax = plt.subplots(figsize=(6.5, 4)) ax.scatter(table["multiplicity"] + rng.normal(0, 0.05, len(table)), -np.log10(table["p_value"].clip(1e-300)), c=np.where(table["validated"], hv.plotting.PALETTE[1], hv.plotting.GRAY), s=16) ax.set_xlabel("multiplicity of the vertex set") ax.set_ylabel(r"$-\log_{10}p$") plt.tight_layout() .. image-sg:: /auto_examples/07_patterns/images/sphx_glr_plot_27_validated_hyperedges_001.png :alt: plot 27 validated hyperedges :srcset: /auto_examples/07_patterns/images/sphx_glr_plot_27_validated_hyperedges_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.380 seconds) .. _sphx_glr_download_auto_examples_07_patterns_plot_27_validated_hyperedges.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/ComplexSystemsIntelligence/hatvis/main?urlpath=lab/tree/notebooks/auto_examples/07_patterns/plot_27_validated_hyperedges.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_27_validated_hyperedges.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_27_validated_hyperedges.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_27_validated_hyperedges.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_