.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_data_analysis/manage_data_and_samples/plot_sample_correlation.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. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_data_analysis_manage_data_and_samples_plot_sample_correlation.py: Estimate correlation coefficients ================================= .. GENERATED FROM PYTHON SOURCE LINES 7-15 In this example we are going to estimate the correlation between an output sample Y and the corresponding inputs using various estimators: - Pearson coefficients - Spearman coefficients - PCC: Partial Correlation Coefficients - PRCC: Partial Rank Correlation Coefficient - SRC: Standard Regression Coefficients - SRRC: Standard Rank Regression Coefficient .. GENERATED FROM PYTHON SOURCE LINES 17-23 .. code-block:: Python from openturns.usecases import ishigami_function import openturns as ot import openturns.viewer as viewer from matplotlib import pyplot as plt .. GENERATED FROM PYTHON SOURCE LINES 24-26 To illustrate the usage of the method mentioned above, we define a set of `X` and `Y` data using the :ref:`Ishigami model `. This classical model is defined in a data class: .. GENERATED FROM PYTHON SOURCE LINES 26-28 .. code-block:: Python im = ishigami_function.IshigamiModel() .. GENERATED FROM PYTHON SOURCE LINES 29-31 Create X/Y data We get the input variables description : .. GENERATED FROM PYTHON SOURCE LINES 31-37 .. code-block:: Python input_names = im.inputDistribution.getDescription() size = 100 inputDesign = ot.SobolIndicesExperiment(im.inputDistribution, size, True).generate() outputDesign = im.model(inputDesign) .. GENERATED FROM PYTHON SOURCE LINES 38-40 Create a :class:`~openturns.CorrelationAnalysis` object to compute various estimates of the correlation between the inputs and the output. .. GENERATED FROM PYTHON SOURCE LINES 40-43 .. code-block:: Python corr_analysis = ot.CorrelationAnalysis(inputDesign, outputDesign) .. GENERATED FROM PYTHON SOURCE LINES 44-46 PCC coefficients ------------------ .. GENERATED FROM PYTHON SOURCE LINES 46-50 .. code-block:: Python pcc_indices = corr_analysis.computePCC() print(pcc_indices) .. rst-class:: sphx-glr-script-out .. code-block:: none [0.484053,0.0348492,0.0298963] .. GENERATED FROM PYTHON SOURCE LINES 54-59 .. code-block:: Python graph = ot.SobolIndicesAlgorithm.DrawCorrelationCoefficients( pcc_indices, input_names, "PCC coefficients" ) view = viewer.View(graph) .. image-sg:: /auto_data_analysis/manage_data_and_samples/images/sphx_glr_plot_sample_correlation_001.svg :alt: PCC coefficients :srcset: /auto_data_analysis/manage_data_and_samples/images/sphx_glr_plot_sample_correlation_001.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 60-62 PRCC coefficients -------------------- .. GENERATED FROM PYTHON SOURCE LINES 62-66 .. code-block:: Python prcc_indices = corr_analysis.computePRCC() print(prcc_indices) .. rst-class:: sphx-glr-script-out .. code-block:: none [0.493049,0.0275605,0.018878] .. GENERATED FROM PYTHON SOURCE LINES 67-72 .. code-block:: Python graph = ot.SobolIndicesAlgorithm.DrawCorrelationCoefficients( prcc_indices, input_names, "PRCC coefficients" ) view = viewer.View(graph) .. image-sg:: /auto_data_analysis/manage_data_and_samples/images/sphx_glr_plot_sample_correlation_002.svg :alt: PRCC coefficients :srcset: /auto_data_analysis/manage_data_and_samples/images/sphx_glr_plot_sample_correlation_002.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 73-75 SRC coefficients ------------------- .. GENERATED FROM PYTHON SOURCE LINES 75-79 .. code-block:: Python src_indices = corr_analysis.computeSRC() print(src_indices) .. rst-class:: sphx-glr-script-out .. code-block:: none [0.483797,0.03052,0.0261759] .. GENERATED FROM PYTHON SOURCE LINES 80-85 .. code-block:: Python graph = ot.SobolIndicesAlgorithm.DrawCorrelationCoefficients( src_indices, input_names, "SRC coefficients" ) view = viewer.View(graph) .. image-sg:: /auto_data_analysis/manage_data_and_samples/images/sphx_glr_plot_sample_correlation_003.svg :alt: SRC coefficients :srcset: /auto_data_analysis/manage_data_and_samples/images/sphx_glr_plot_sample_correlation_003.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 86-87 Normalized squared SRC coefficients (coefficients are made to sum to 1) : .. GENERATED FROM PYTHON SOURCE LINES 87-91 .. code-block:: Python squared_src_indices = corr_analysis.computeSquaredSRC(True) print(squared_src_indices) .. rst-class:: sphx-glr-script-out .. code-block:: none [0.99314,0.00395232,0.00290729] .. GENERATED FROM PYTHON SOURCE LINES 92-99 .. code-block:: Python graph = ot.SobolIndicesAlgorithm.DrawCorrelationCoefficients( squared_src_indices, input_names, "Squared SRC coefficients" ) view = viewer.View(graph) .. image-sg:: /auto_data_analysis/manage_data_and_samples/images/sphx_glr_plot_sample_correlation_004.svg :alt: Squared SRC coefficients :srcset: /auto_data_analysis/manage_data_and_samples/images/sphx_glr_plot_sample_correlation_004.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 100-102 SRRC coefficients -------------------- .. GENERATED FROM PYTHON SOURCE LINES 102-106 .. code-block:: Python srrc_indices = corr_analysis.computeSRRC() print(srrc_indices) .. rst-class:: sphx-glr-script-out .. code-block:: none [0.492985,0.0240038,0.0164373] .. GENERATED FROM PYTHON SOURCE LINES 107-112 .. code-block:: Python graph = ot.SobolIndicesAlgorithm.DrawCorrelationCoefficients( srrc_indices, input_names, "SRRC coefficients" ) view = viewer.View(graph) .. image-sg:: /auto_data_analysis/manage_data_and_samples/images/sphx_glr_plot_sample_correlation_005.svg :alt: SRRC coefficients :srcset: /auto_data_analysis/manage_data_and_samples/images/sphx_glr_plot_sample_correlation_005.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 113-116 Pearson coefficients ----------------------- We compute here the Pearson :math:`\rho` coefficients. .. GENERATED FROM PYTHON SOURCE LINES 116-120 .. code-block:: Python pearson_correlation = corr_analysis.computeLinearCorrelation() print(pearson_correlation) .. rst-class:: sphx-glr-script-out .. code-block:: none [0.483575,0.0226162,0.0337894] .. GENERATED FROM PYTHON SOURCE LINES 121-126 .. code-block:: Python graph = ot.SobolIndicesAlgorithm.DrawCorrelationCoefficients( pearson_correlation, input_names, "Pearson correlation coefficients" ) view = viewer.View(graph) .. image-sg:: /auto_data_analysis/manage_data_and_samples/images/sphx_glr_plot_sample_correlation_006.svg :alt: Pearson correlation coefficients :srcset: /auto_data_analysis/manage_data_and_samples/images/sphx_glr_plot_sample_correlation_006.svg :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 127-130 Spearman coefficients ----------------------- We compute here the Spearman :math:`\rho_s` coefficients. .. GENERATED FROM PYTHON SOURCE LINES 132-135 .. code-block:: Python spearman_correlation = corr_analysis.computeSpearmanCorrelation() print(spearman_correlation) .. rst-class:: sphx-glr-script-out .. code-block:: none [0.492777,0.0157241,0.0243608] .. GENERATED FROM PYTHON SOURCE LINES 136-141 .. code-block:: Python graph = ot.SobolIndicesAlgorithm.DrawCorrelationCoefficients( spearman_correlation, input_names, "Spearman correlation coefficients" ) view = viewer.View(graph) plt.show() .. image-sg:: /auto_data_analysis/manage_data_and_samples/images/sphx_glr_plot_sample_correlation_007.svg :alt: Spearman correlation coefficients :srcset: /auto_data_analysis/manage_data_and_samples/images/sphx_glr_plot_sample_correlation_007.svg :class: sphx-glr-single-img .. _sphx_glr_download_auto_data_analysis_manage_data_and_samples_plot_sample_correlation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_sample_correlation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_sample_correlation.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_sample_correlation.zip `