Sample manipulationΒΆ

This example will describe the main statistical functionalities on data through the Sample object.

[1]:
from __future__ import print_function
import openturns as ot
[2]:
# Generate a sample of dimension 3
sample = ot.Normal(3).getSample(500)
sample[:5]
[2]:
X0X1X2
00.6082016512187646-1.2661731022166567-0.43826561996041397
11.2054782008285756-2.18138523461651430.3500420865302907
2-0.35500704918563971.4372493101409030.8106679824694837
30.79315601145977-0.47052559863257040.26101793529769673
4-2.2900619818700854-1.2828852904549808-1.311781115463341
[26]:
# Get min and max per component
sample.getMin(), sample.getMax()
[26]:
(class=Point name=Unnamed dimension=3 values=[-2.4067,-3.24637,-3.09834],
 class=Point name=Unnamed dimension=3 values=[3.15958,3.01263,2.63821])
[4]:
# Get the range per component (xmax-xmin)
sample.computeRange()
[4]:

[5.56628,6.25899,5.73655]

[5]:
# Get the mean per component
sample.computeMean()
[5]:

[-0.0421682,-0.0168704,0.0580127]

[6]:
# Get the standard deviation per component
sample.computeStandardDeviationPerComponent()
[6]:

[0.96048,1.01449,0.995846]

[7]:
# Get the Variance per component
sample.computeVariance()
[7]:

[0.922521,1.02919,0.991709]

[8]:
# Get the Skewness per component
sample.computeSkewness()
[8]:

[0.200045,-0.0429991,-0.0712751]

[9]:
# Get the Kurtosis per component
sample.computeKurtosis()
[9]:

[3.15748,3.03583,3.02072]

[10]:
# Get the median per component
sample.computeMedian()
[10]:

[-0.0497493,-0.0559353,0.0312677]

[11]:
# Get the empirical 0.95 quantile per component
sample.computeQuantilePerComponent(0.95)
[11]:

[1.54329,1.64875,1.69843]

[12]:
# Get the sample covariance
sample.computeCovariance()
[12]:

[[ 0.922521 0.0383477 0.051918 ]
[ 0.0383477 1.02919 0.0143437 ]
[ 0.051918 0.0143437 0.991709 ]]

[13]:
# Get the sample standard deviation
sample.computeStandardDeviation()
[13]:

[[ 0.96048 0 0 ]
[ 0.0399256 1.01371 0 ]
[ 0.0540543 0.0120208 0.994305 ]]

[14]:
# Get the sample Pearson correlation matrix
sample.computePearsonCorrelation()
[14]:

[[ 1 0.0393553 0.0542798 ]
[ 0.0393553 1 0.0141978 ]
[ 0.0542798 0.0141978 1 ]]

[15]:
# Get  the sample Kendall correlation matrix
sample.computeKendallTau()
[15]:

[[ 1 0.0367936 0.0292906 ]
[ 0.0367936 1 0.0209539 ]
[ 0.0292906 0.0209539 1 ]]

[16]:
# Get  the sample Spearman  correlation matrix
sample.computeSpearmanCorrelation()
[16]:

[[ 1 0.0544864 0.0444143 ]
[ 0.0544864 1 0.0313186 ]
[ 0.0444143 0.0313186 1 ]]

[17]:
# Get the value of the empirical CDF at a point
point = [1.1, 2.2, 3.3]
sample.computeEmpiricalCDF(point)
[17]:
0.862