.. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_data_analysis_estimate_dependency_and_copulas_plot_regression_test.py: Test samples independence using regression ========================================== In this example we are going to estimate whether samples are independent using the regression test. It consists in detecting a linear relation between two scalar samples. .. code-block:: default from __future__ import print_function import openturns as ot import openturns.viewer as viewer from matplotlib import pylab as plt ot.Log.Show(ot.Log.NONE) Generate a sample of dimension 3 with component 0 correlated to component 2 .. code-block:: default marginals = [ot.Normal()] * 3 S = ot.CorrelationMatrix(3) S[0, 2] = 0.9 copula = ot.NormalCopula(S) distribution = ot.ComposedDistribution(marginals, copula) sample = distribution.getSample(30) Split it in two samples: firstSample of dimension=2, secondSample of dimension=1 .. code-block:: default firstSample = sample[:, :2] secondSample = sample[:, 2] Test independance of each components of firstSample against secondSample .. code-block:: default test_results = ot.LinearModelTest.FullRegression(firstSample, secondSample) for i in range(len(test_results)): print('Component', i, 'is independent?', test_results[i].getBinaryQualityMeasure(), 'p-value=%.6g' % test_results[i].getPValue(), 'threshold=%.6g' % test_results[i].getThreshold()) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Component 0 is independent? True p-value=0.998225 threshold=0.05 Component 1 is independent? False p-value=3.56363e-15 threshold=0.05 Component 2 is independent? True p-value=0.111968 threshold=0.05 .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.003 seconds) .. _sphx_glr_download_auto_data_analysis_estimate_dependency_and_copulas_plot_regression_test.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_regression_test.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_regression_test.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_