.. 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_manipulation.py" .. LINE NUMBERS ARE GIVEN BELOW. .. 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_manage_data_and_samples_plot_sample_manipulation.py: Sample manipulation =================== .. GENERATED FROM PYTHON SOURCE LINES 6-7 This example will describe the main statistical functionalities on data through the Sample object. The Sample is an output variable of interest. .. GENERATED FROM PYTHON SOURCE LINES 9-13 .. code-block:: default from __future__ import print_function import openturns as ot ot.Log.Show(ot.Log.NONE) .. GENERATED FROM PYTHON SOURCE LINES 14-16 A typical example ----------------- .. GENERATED FROM PYTHON SOURCE LINES 18-21 A recurring issue in uncertainty quantification is to perform analysis on an output variable of interest Y obtained through a model `f` and input parameters `X`. Here we shall consider the input parameters as two independent standard normal distributions :math:`X=(X_1, X_2)`. We therefore use an `IndependentCopula` to describe the link between the two marginals. .. GENERATED FROM PYTHON SOURCE LINES 21-26 .. code-block:: default # input parameters inputDist = ot.ComposedDistribution([ot.Normal()] * 2, ot.IndependentCopula(2)) inputDist.setDescription(['X1', 'X2']) .. GENERATED FROM PYTHON SOURCE LINES 27-28 We create a vector from the 2D-distribution created before : .. GENERATED FROM PYTHON SOURCE LINES 30-33 .. code-block:: default inputVector = ot.RandomVector(inputDist) .. GENERATED FROM PYTHON SOURCE LINES 34-43 Suppose our model `f` is known and reads as : .. math:: f(X) = \begin{pmatrix} x_1^2 + x_2 \\ x_1 + x_2^2 \end{pmatrix} We define our model `f` with a `SymbolicFunction` .. GENERATED FROM PYTHON SOURCE LINES 45-47 .. code-block:: default f = ot.SymbolicFunction(["x1", "x2"], ["x1^2+x2", "x2^2+x1"]) .. GENERATED FROM PYTHON SOURCE LINES 48-49 Our output vector is Y=f(X), the image of the inputVector by the model .. GENERATED FROM PYTHON SOURCE LINES 49-51 .. code-block:: default outputVector = ot.CompositeRandomVector(f, inputVector) .. GENERATED FROM PYTHON SOURCE LINES 52-53 We can now get a sample out of Y, that is realizations (here 1000) of the random outputVector .. GENERATED FROM PYTHON SOURCE LINES 53-56 .. code-block:: default size = 1000 sample = outputVector.getSample(size) .. GENERATED FROM PYTHON SOURCE LINES 57-58 The `sample` may be seen as a matrix of size :math:`1000 \times 2`. We print the 5 first samples (out of 1000) : .. GENERATED FROM PYTHON SOURCE LINES 60-63 .. code-block:: default sample[:5] .. raw:: html
y0y1
0-0.30506120.4053047
10.59305061.833625
21.0022281.122468
32.982256-1.643145
4-0.29186332.278239


.. GENERATED FROM PYTHON SOURCE LINES 64-70 Basic operations on samples --------------------------- We have access to basic information about a sample such as - minimum and maximum per component .. GENERATED FROM PYTHON SOURCE LINES 70-72 .. code-block:: default sample.getMin(), sample.getMax() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none (class=Point name=Unnamed dimension=2 values=[-2.56587,-2.84726], class=Point name=Unnamed dimension=2 values=[9.93535,12.1777]) .. GENERATED FROM PYTHON SOURCE LINES 73-75 - the range per component (max-min) .. GENERATED FROM PYTHON SOURCE LINES 75-77 .. code-block:: default sample.computeRange() .. raw:: html

[12.5012,15.025]



.. GENERATED FROM PYTHON SOURCE LINES 78-80 More elaborate functionalities are also available : .. GENERATED FROM PYTHON SOURCE LINES 82-84 - get the median per component .. GENERATED FROM PYTHON SOURCE LINES 84-86 .. code-block:: default sample.computeMedian() .. raw:: html

[0.68633,0.885105]



.. GENERATED FROM PYTHON SOURCE LINES 87-89 - compute the covariance .. GENERATED FROM PYTHON SOURCE LINES 89-91 .. code-block:: default sample.computeCovariance() .. raw:: html

[[ 2.561 -0.0572927 ]
[ -0.0572927 3.30347 ]]



.. GENERATED FROM PYTHON SOURCE LINES 92-94 - get the empirical 0.95 quantile per component .. GENERATED FROM PYTHON SOURCE LINES 94-96 .. code-block:: default sample.computeQuantilePerComponent(0.95) .. raw:: html

[3.63824,4.13131]



.. GENERATED FROM PYTHON SOURCE LINES 97-99 - get the value of the empirical CDF at a point .. GENERATED FROM PYTHON SOURCE LINES 99-103 .. code-block:: default point = [1.1, 2.2] sample.computeEmpiricalCDF(point) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 0.517 .. GENERATED FROM PYTHON SOURCE LINES 104-106 Estimate the statistical moments -------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 108-109 Oftentimes, we need to estimate the first moments of the output data. We can then estimate statistical moments from the output sample : .. GENERATED FROM PYTHON SOURCE LINES 111-113 - estimate the moment of order 1 : mean .. GENERATED FROM PYTHON SOURCE LINES 113-115 .. code-block:: default sample.computeMean() .. raw:: html

[0.90343,1.15761]



.. GENERATED FROM PYTHON SOURCE LINES 116-118 - estimate the standard deviation for each component .. GENERATED FROM PYTHON SOURCE LINES 118-120 .. code-block:: default sample.computeStandardDeviation() .. raw:: html

[1.60031,1.81754]



.. GENERATED FROM PYTHON SOURCE LINES 121-123 - estimate the moment of order 2 : variance .. GENERATED FROM PYTHON SOURCE LINES 123-125 .. code-block:: default sample.computeVariance() .. raw:: html

[2.561,3.30347]



.. GENERATED FROM PYTHON SOURCE LINES 126-128 - estimate the moment of order 3 : skewness .. GENERATED FROM PYTHON SOURCE LINES 128-130 .. code-block:: default sample.computeSkewness() .. raw:: html

[1.28117,1.80261]



.. GENERATED FROM PYTHON SOURCE LINES 131-133 - estimate the moment of order 4 : kurtosis .. GENERATED FROM PYTHON SOURCE LINES 133-135 .. code-block:: default sample.computeKurtosis() .. raw:: html

[6.47372,9.58353]



.. GENERATED FROM PYTHON SOURCE LINES 136-138 Test the correlation -------------------- .. GENERATED FROM PYTHON SOURCE LINES 140-144 Some statistical test for correlation are available : - get the sample Pearson correlation matrix : .. GENERATED FROM PYTHON SOURCE LINES 144-146 .. code-block:: default sample.computePearsonCorrelation() .. raw:: html

[[ 1 -0.0196974 ]
[ -0.0196974 1 ]]



.. GENERATED FROM PYTHON SOURCE LINES 147-149 - get the sample Kendall correlation matrix : .. GENERATED FROM PYTHON SOURCE LINES 149-151 .. code-block:: default sample.computeKendallTau() .. raw:: html

[[ 1 0.0251852 ]
[ 0.0251852 1 ]]



.. GENERATED FROM PYTHON SOURCE LINES 152-154 - get the sample Spearman correlation matrix : .. GENERATED FROM PYTHON SOURCE LINES 154-155 .. code-block:: default sample.computeSpearmanCorrelation() .. raw:: html

[[ 1 0.0292559 ]
[ 0.0292559 1 ]]



.. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.008 seconds) .. _sphx_glr_download_auto_data_analysis_manage_data_and_samples_plot_sample_manipulation.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_sample_manipulation.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_sample_manipulation.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_