Note
Go to the end to download the full example code.
Sample manipulation¶
This example will describe the main statistical functionalities on data through the Sample object. The Sample is an output variable of interest.
import openturns as ot
A typical example¶
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 .
We therefore use an
IndependentCopula to describe the link between the two marginals.
# input parameters
inputDist = ot.JointDistribution([ot.Normal()] * 2, ot.IndependentCopula(2))
inputDist.setDescription(["X1", "X2"])
We create a vector from the 2d-distribution created before :
Suppose our model f is known and reads as :
We define our model f with a SymbolicFunction
f = ot.SymbolicFunction(["x1", "x2"], ["x1^2+x2", "x2^2+x1"])
Our output vector is , the image of the inputVector by the model
We can now get a sample out of Y, that is realizations (here 1000) of the random outputVector
size = 1000
sample = outputVector.getSample(size)
The sample may be seen as a matrix of size . We print the 5 first samples (out of 1000) :
sample[:5]
Basic operations on samples¶
We have access to basic information about a sample such as
minimum and maximum per component
(class=Point name=Unnamed dimension=2 values=[-3.24513,-2.98342], class=Point name=Unnamed dimension=2 values=[10.6987,10.5037])
the range per component (max-min)
More elaborate functionalities are also available :
get the median per component
compute the covariance
get the empirical 0.95 quantile per component
get the value of the empirical CDF at a point
point = [1.1, 2.2]
sample.computeEmpiricalCDF(point)
0.569
Estimate the statistical moments¶
Oftentimes, we need to estimate the first moments of the output data. We can then estimate statistical moments from the output sample :
estimate the moment of order 1 : mean
estimate the standard deviation for each component
estimate the moment of order 2 : variance
estimate the moment of order 3 : skewness
estimate the moment of order 4 : kurtosis
Test the correlation¶
Some statistical test for correlation are available :
get the sample linear correlation matrix :
get the sample Kendall correlation matrix :
get the sample Spearman correlation matrix :
OpenTURNS