<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Descriptive statistics
Acknowledging that variables and models are uncertain assumes that we directly or indirectly can describe them through probability distributions.
However for most applications the distribution is a messy entity that on its own is hard to interpret directly.
So instead, we use statistical metrics designed to summarize distribution and to get an intuitive understanding of its statistical properties. 
In addition, for each statistical property, there almost always exists an empirical counterpart that works as a best estimate of said statistical property in the scenarios where only data is available.
This is important, as Monte Carlo integration isn't possible without the empirical metrics used to describe the results.
This section takes a look at some popular statistical metrics and compares them to their empirical counterparts.
Expected value
Take for example the most common metric, the expected value function chaospy.E().
This operator works on any distribution
Step1:  Its empirical counterpart is the mean function
Step2:  The operator can also be used on any polynomial, but would then require the distribution of interest as a second argument
Step3:  In the multivariate case, the distribution and the polynomials needs to coincide politically.
E.g.
Step4:  Here q0, q1 and q2 correspond to chaospy.Normal(0, 1), chaospy.Uniform(0, 2) and chaospy.Normal(2, 2) respectively.
It is the variable name position and distribution length that matters here, not the shape of what is being taken the expected value of.
Note also that the model approximations created by e.g. chaospy.fit_regression() and chaospy.fit_quadrature() also are valid polynomials.
Higher order moments
In addition to the expected value there is also higher order statistics that work in the same way.
They are with their numpy and scipy empirical counterparts
Step5:  Conditional mean
The conditional expected value chaospy.E_cond() is similar to the more conventional chaospy.E(), but differs in that it supports partial conditioning.
In other words it is possible to "freeze" some of the variables and only evaluate the others.
For example
Step6:  Sensitivity analysis
Variance-based sensitivity analysis (often referred to as the Sobol method or Sobol indices) is a form of global sensitivity analysis. Working within a probabilistic framework, it decomposes the variance of the output of the model or system into fractions which can be attributed to inputs or sets of inputs. Read more in for example Wikipedia.
In chaospy, the three functions are available
Step7:  There are no direct empirical counterparts to these functions, but it is possible to create schemes using for example Saltelli's method.
Percentile
Calculating a closed form percentile of a multivariate polynomial is not feasible.
As such, chaospy does not calculate it.
However, as a matter of convenience, a simple function wrapper chaospy.Perc() that calculate said values using Monte Carlo integration is provided.
For example
Step8:  Note that the accuracy of this method is dependent on the number of samples.
Quantity of interest
If you want to interpret the model approximation as a distribution for further second order analysis, this is possible through the chaospy.QoI_Dist.
This is a thin wrapper function that generates samples and pass them to the kernel density estimation class chaospy.GaussianKDE().
It works as follows
<ASSISTANT_TASK:>
Python Code:
import chaospy
uniform = chaospy.Uniform(0, 4)
chaospy.E(uniform)
Explanation: Descriptive statistics
Acknowledging that variables and models are uncertain assumes that we directly or indirectly can describe them through probability distributions.
However for most applications the distribution is a messy entity that on its own is hard to interpret directly.
So instead, we use statistical metrics designed to summarize distribution and to get an intuitive understanding of its statistical properties. 
In addition, for each statistical property, there almost always exists an empirical counterpart that works as a best estimate of said statistical property in the scenarios where only data is available.
This is important, as Monte Carlo integration isn't possible without the empirical metrics used to describe the results.
This section takes a look at some popular statistical metrics and compares them to their empirical counterparts.
Expected value
Take for example the most common metric, the expected value function chaospy.E().
This operator works on any distribution:
End of explanation
samples = uniform.sample(1e7)
numpy.mean(samples)
Explanation: Its empirical counterpart is the mean function: $\bar X=\tfrac 1N \sum X_i$.
This function is available as numpy.mean and can be used on samples generated from said distribution:
End of explanation
q0 = chaospy.variable()
chaospy.E(q0**3-1, uniform)
Explanation: The operator can also be used on any polynomial, but would then require the distribution of interest as a second argument:
End of explanation
q0, q1, q2 = chaospy.variable(3)
joint3 = chaospy.J(chaospy.Normal(0, 1), chaospy.Uniform(0, 2), chaospy.Normal(2, 2))
chaospy.E([q0, q1*q2], joint3)
Explanation: In the multivariate case, the distribution and the polynomials needs to coincide politically.
E.g.
End of explanation
chaospy.Corr([q0, q0*q2], joint3)
Explanation: Here q0, q1 and q2 correspond to chaospy.Normal(0, 1), chaospy.Uniform(0, 2) and chaospy.Normal(2, 2) respectively.
It is the variable name position and distribution length that matters here, not the shape of what is being taken the expected value of.
Note also that the model approximations created by e.g. chaospy.fit_regression() and chaospy.fit_quadrature() also are valid polynomials.
Higher order moments
In addition to the expected value there is also higher order statistics that work in the same way.
They are with their numpy and scipy empirical counterparts:
Name              | chaospy                                    | numpy or scipy
---               | ---                                          | ---
Variance          | chaospy.Var()   | numpy.var
Standard deviation| chaospy.Std()   | numpy.std
Covariance        | chaospy.Cov()   | numpy.cov
Correlation       | chaospy.Corr() | numpy.corrcoef
Skewness          | chaospy.Skew() | scipy.stats.skew
Kurtosis          | chaospy.Kurt() | scipy.stats.kurtosis
For example (Pearson's) correlation:
End of explanation
chaospy.E_cond([q0, q1*q2], q0, joint3)
chaospy.E_cond([q0, q1*q2], q1, joint3)
chaospy.E_cond([q0, q1*q2], [q1, q2], joint3)
Explanation: Conditional mean
The conditional expected value chaospy.E_cond() is similar to the more conventional chaospy.E(), but differs in that it supports partial conditioning.
In other words it is possible to "freeze" some of the variables and only evaluate the others.
For example:
End of explanation
chaospy.Sens_m(6*q0+3*q1+q2, joint3)
chaospy.Sens_m2(q0*q1+q1*q2, joint3)
chaospy.Sens_t(6*q0+3*q1+q2, joint3)
Explanation: Sensitivity analysis
Variance-based sensitivity analysis (often referred to as the Sobol method or Sobol indices) is a form of global sensitivity analysis. Working within a probabilistic framework, it decomposes the variance of the output of the model or system into fractions which can be attributed to inputs or sets of inputs. Read more in for example Wikipedia.
In chaospy, the three functions are available:
Name          | chaospy function
---           | ---
1. order main | chaospy.Sens_m
2. order main | chaospy.Sens_m2
total order   | chaospy.Sens_m2
For example:
End of explanation
chaospy.Perc([q0, q1*q2], [25, 50, 75], joint3, sample=1000, seed=1234)
Explanation: There are no direct empirical counterparts to these functions, but it is possible to create schemes using for example Saltelli's method.
Percentile
Calculating a closed form percentile of a multivariate polynomial is not feasible.
As such, chaospy does not calculate it.
However, as a matter of convenience, a simple function wrapper chaospy.Perc() that calculate said values using Monte Carlo integration is provided.
For example:
End of explanation
new_dist = chaospy.QoI_Dist(q0*q1+q2, joint3)
new_dist.sample(6, seed=1234).round(6)
Explanation: Note that the accuracy of this method is dependent on the number of samples.
Quantity of interest
If you want to interpret the model approximation as a distribution for further second order analysis, this is possible through the chaospy.QoI_Dist.
This is a thin wrapper function that generates samples and pass them to the kernel density estimation class chaospy.GaussianKDE().
It works as follows:
End of explanation
<END_TASK>