Good morning,
For a polynomial chaos expansion (PCE) of total degree 2 with five input variables, the number P of basis functions is indeed
P=\binom{M+p}{p}=\binom{5+2}{2}=21.
These correspond to one constant term, five first-degree terms, five pure second-degree terms, and ten pairwise interaction terms.
However, the association between the coefficients and the input variables depends on the ordering of the polynomial basis. Therefore, the coefficient values alone are not sufficient to identify the corresponding terms.
In UQLab, you can retrieve the multi-indices associated with the polynomial basis through the following fields, assuming your PCE metamodel is called myPCE:
- myPCE.PCE.Basis.Indices
- myPCE.PCE.Coefficients
Each row of myPCE.PCE.Basis.Indices identifies the polynomial degrees associated with the five input variables. For example, denoting the five input variables by (X_1,\ldots,X_5):
-
(\boldsymbol{\alpha}=(0,0,0,0,0)): constant term, corresponding to the mean of the PCE.
-
(\boldsymbol{\alpha}=(1,0,0,0,0)): first-degree polynomial in X_1.
-
(\boldsymbol{\alpha}=(2,0,0,0,0)): second-degree polynomial in X_1.
-
(\boldsymbol{\alpha}=(1,1,0,0,0)): interaction between X_1 and X_2.
Regarding your partial variance analysis, provided that the inputs are independent and the basis is orthonormal, the variance contribution of an individual basis function is simply the square of its coefficient. You can therefore obtain partial variances by grouping the squared coefficients according to their corresponding multi-indices.
For example, the first-order contribution of X_1 is obtained by summing the squared coefficients of all basis functions involving X_1 alone, with all other components of the multi-index equal to zero. Interaction contributions can be computed similarly by grouping terms involving the relevant variables.
I hope this helps!
PS: For further details on sensitivity analysis, I recommend consulting the UQLab User Manual on Sensitivity Analysis.