
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/02-multisite-data/07-plot_simulate_multisite_data_with_costume_covariates.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_auto_examples_02-multisite-data_07-plot_simulate_multisite_data_with_costume_covariates.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_02-multisite-data_07-plot_simulate_multisite_data_with_costume_covariates.py:


Multisite data generation with covariates
=========================================

.. GENERATED FROM PYTHON SOURCE LINES 7-9

Imports
-------

.. GENERATED FROM PYTHON SOURCE LINES 9-50

.. code-block:: Python


    import matplotlib.pyplot as plt
    import pandas as pd
    import seaborn as sns

    from uniharmony import verbosity
    from uniharmony.datasets import make_multisite_classification
    from uniharmony.datasets import Covariate, CovariateSiteDistribution

    sns.set_theme(style="whitegrid")
    verbosity("warning")

    covars = [Covariate(
        name="age",
        site_distributions=[
            CovariateSiteDistribution(loc=10.0, scale=1.0, clip=None),
            CovariateSiteDistribution(loc=70.0, scale=1.0, clip=None)],
        x_correlation=0.1),
        Covariate(
        name="sex",
        site_distributions=[
            CovariateSiteDistribution(probs=[0.1,0.9]),
            CovariateSiteDistribution(probs=[0.9,0.1]),

        ],
        x_correlation=0.2)]


    X, y, sites, covars = make_multisite_classification(signal_type="blobs", covariates=covars)

    df = pd.DataFrame({"Class": y, "Site": sites, "Age": covars["age"],
                       "Feature1":X[:,0], "sex": covars["sex"]})

    print(f"X has {X.shape[0]} examples and {X.shape[1]} features")

    plt.figure(figsize=[10, 6])
    plt.title("Features vs age/sex distribution")
    sns.scatterplot(df, y="Feature1", x="Age", hue="sex", style="Site")
    plt.grid(axis="y", color="black", alpha=0.5, linestyle="--")





.. image-sg:: /auto_examples/02-multisite-data/images/sphx_glr_07-plot_simulate_multisite_data_with_costume_covariates_001.png
   :alt: Features vs age/sex distribution
   :srcset: /auto_examples/02-multisite-data/images/sphx_glr_07-plot_simulate_multisite_data_with_costume_covariates_001.png
   :class: sphx-glr-single-img


.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    X has 1000 examples and 10 features





.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 2.538 seconds)


.. _sphx_glr_download_auto_examples_02-multisite-data_07-plot_simulate_multisite_data_with_costume_covariates.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: 07-plot_simulate_multisite_data_with_costume_covariates.ipynb <07-plot_simulate_multisite_data_with_costume_covariates.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: 07-plot_simulate_multisite_data_with_costume_covariates.py <07-plot_simulate_multisite_data_with_costume_covariates.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: 07-plot_simulate_multisite_data_with_costume_covariates.zip <07-plot_simulate_multisite_data_with_costume_covariates.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
