kStatistics is a package in R
that serves as a unified framework for estimating univariate and multivariate cumulants as well as products of univariate and multivariate cumulants of a random sample, using unbiased estimators with minimum variance. The main computational machinery of kStatistics is an algorithm for computing multi-index partitions. The same algorithm underlies the general-purpose multivariate Faà di Bruno’s formula, which therefore has been included in the last release of the package. This formula gives the coefficients of formal power series compositions as well as the partial derivatives of multivariable function compositions. One of the most significant applications of this formula is the possibility to generate many well-known polynomial families as special cases. So, in the package, there are special functions for generating very popular polynomial families, such as the Bell polynomials. However, further families can be obtained, for suitable choices of the formal power series involved in the composition or when suitable symbolic strategies are employed. In both cases, we give examples on how to modify the R
codes of the package to accomplish this task. Future developments are addressed at the end of the paper
Joint cumulants are usually employed for measuring interactions among two or more random variables simultaneously, extending the familiar notion of covariance to higher orders. More in details, suppose Y
Orthogonality: Joint cumulants of independent random vectors are zero, that is ki(Y)=0 for |i|>0 if Y=(Y1,Y2) with Y1 independent of Y2.
Additivity: Cumulants linearize on independent random vectors, that is
ki(Y1+Y2)=ki(Y1)+ki(Y2)
for |i|>0 with Y1 independent of Y2.
Multilinearity: ki(AY)=∑j1,…,jm(A)j1i1⋯(A)jmimkj(Y) for |i|>0 with A∈Rm×Rm.
Semi-invariance: If b∈Rm then ki(Y+b)=ki(Y) for |i|≥2.
Thanks to all these properties, joint cumulants have a wide range of applications: from statistical inference and time series (Jammalamadaka et al. 2006) to asymptotic theory (Rao and Wong 1999), from spatial statistics modeling (Dimitrakopoulos et al. 2010) to signal processing (Giannakis 1987), from non-linear systems identification (Oualla et al. 2021) to Wiener chaos (Peccati and Taqqu 2011), just to mention a few. Indeed it is also well known that cumulants of order greater than two are zero for random vectors which are Gaussian. Therefore, higher order cumulants are often used in testing for multivariate Gaussianity (Jammalamadaka et al. 2006).
The i-th multivariate k-statistic is a symmetric function of the multivariate random sample whose expectation is the joint cumulant of order i of the population characters. These estimators have minimum variance when compared to all other unbiased estimators and are built by free-distribution methods without using sample moments. Due to the properties of joint cumulants, multivariate k-statistics are employed to check multivariate gaussianity (Ferreira et al. 1997) or to quantify high-order interactions among data (Geng et al. 2011), for applications in topology inference (Smith et al. 2022), in neuronal science (Staude et al. 2010) and in mathematical finance (Di Nardo et al. 2020). Polykays are unbiased estimators of cumulant products (Robson 1957) and are particularly useful in estimating covariances between k-statistics (McCullagh 1987). In the kStatistics package (Di Nardo and Guarino 2021), the nPolyk
function provides k-statistics and polykays as well as their multivariate generalizations. Further implementations are in Phyton
(Smith 2020), in Maple
(Guarino et al. 2009) and in Mathematica
(Rose and Smith 2002).
All these estimators are described with a wealth of details by Stuart and Ord (1994) and McCullagh (1987) and their construction relied on some well-known change of bases in the ring of symmetric polynomials. In Di Nardo (2011) a different approach is followed using suitable polynomial families and symbolic strategies. This procedure was the core of the first release (version 1.0) of the kStatistics package (Di Nardo and Guarino 2019), as the initial goal was to implement tools for the estimation of cumulants and cumulant products, both in the univariate and in the multivariate case. As the referred polynomial families can be traced back to the generalized (complete exponential) Bell polynomials, the latest version of the package (Di Nardo and Guarino 2021) has also included procedures to generate these polynomials together with a number of special cases.
Let us recall that the generalized (complete exponential) Bell polynomials are a family of polynomials involving multivariable Sheffer sequences (Brown 1979). Among its various applications, we recall the cumulant polynomial sequences and their connection with special families of stochastic processes (Di Nardo 2016a). Indeed, cumulant polynomials allow us to compute moments and cumulants of multivariate Lévy processes (Di Nardo and Oliva 2011), subordinated multivariate Lévy processes (Di Nardo et al. 2020) and multivariate compound Poisson processes (Di Nardo 2016b). Further examples can be found in Reiner (1976), Shrivastava (2002), Withers and Nadarajah (2010) or Privault (2021).
The generalized (complete exponential) Bell polynomials arise from the multivariate Faà di Bruno’s formula, whose computation has been included in the latest version of the kStatistics package. In enumerative combinatorics, Faà di Bruno’s formula is employed in dealing with formal power series. In particular the multivariate Faà di Bruno’s formula gives the i-th coefficient of the composition (Di Nardo et al. 2011)
h(z)=f(g1(z)−1,…,gn(z)−1)
The problem of finding suitable and easily manageable expressions of the multivariate Faà di Bruno’s formula has received attention from several researchers over the years. This is because the multivariate Faà di Bruno’s formula is a very general-purpose tool with many applications. We refer to the paper of Leipnik and Pearce (2007) for a detailed list of references on this subject and a detailed account of its applications. Further applications can be found in Savits (2006), Chacón and Duong (2015), Shabat and Efendiev (2017) and Nguwi et al. (2022). A classical way to generate the multivariate Faà di Bruno’s formula involves the partial derivatives of a composition of multivariable functions. Suppose f(x) and g1(z),…,gn(z) in (3) be differentiable functions a certain number of times. The multivariate Faà di Bruno’s formula gives the partial derivative of order i of h(z) in z0
hi=∂|i|∂zi11⋯∂zimmh(z1,…,zm)|z=z0for |i|>0,
There are various ways to express hi in (5), see for example Mishkov (2000), Hernández Encinas and Muñoz Masqué (2003) and Ma (2009). Symbolic manipulation using Macsyma
, Maple
, Mathematica
, etc. can produce any required order of (5), by applying the chain rule recursively and using a function that provides partial derivatives. Also in R
, there are some functions for computing partial derivatives (Clausen and Sokol 2020). Despite its conceptual simplicity, applications of the chain rule become impractical for its cumbersome computation even for small values of its order. As the number of additive terms becomes huge, the output is often untidy and further manipulations are required to simplify the result. By using combinatorial methods, Constantine and Savits (1996) have carried out the following expression of the multivariate Faà di Bruno’s formula
hi=i!∑1≤|t|≤|i|ft|i|∑k=1∑pk(i,t)k∏j=1(glj)qjqj!(lj!)|qj|
A completely different approach concerns the combinatorics of partial derivatives as Hardy (2006) pointed out for the univariate-multivariate composition using multisets and collapsing partitions. Motivated by his results and using the umbral calculus, which is a symbolic method particularly useful in dealing with formal power series (4), the combinatorics behind (6) has been simplified and a different expression has been given in Di Nardo et al. (2011). The key tool is the notion of partition of a multi-index which parallels the multiset partitions given in Hardy (2006).
The contribution of this paper is multi-sided. We explain how to recover in R
a multi-index partition, which is a combinatorial device. For statistical purposes, we show how to recover k-statistics and their multivariate generalizations using the referred polynomial approach and multi-index partitions. Then, we explain the main steps of the MFB
function producing the multivariate Faà di Bruno’s formula, without any reference to the umbral calculus or chain rules and whose applications go beyond statistical purposes. The main idea is to expand the multivariable polynomial
∑(is1,…,sn)q1,s1(y1)⋯qn,sn(yn)
Consequently, the MFB
function gives an efficient computation of the following compositions:
univariate with univariate, that is n=m=1;
univariate with multivariate, that is n=1 and m>1;
multivariate with univariate, that is n>1 and m=1;
multivariate with multivariate, that is n>1 and m>1.
The kStatistics package includes additional functions, for some of the most widespread applications of the multivariate Faà di Bruno’s formula. Indeed, not only this formula permits to generate joint cumulants and their inverse relations, but also further general families of polynomials. Therefore, we have set up special procedures for those families used very often in applications. These functions should be considered an easy to manage interfaces of the MFB
function, with the aim of simplifying its application. Moreover, since the R
codes are free, the user might follow similar steps to generate polynomial families not included in the package but
always coming from the multivariate Faà di Bruno’s formula. The construction of new families of polynomials can be done mainly in two ways. The first way is to choose appropriately the coefficients {ft} and {gj;s} in (4). The second way is to use some suitable symbolic strategies, as discussed in Di Nardo (2011). For both cases, we provide examples.
The paper is organized as follows. The next section explains the main steps of the algorithm that produces multi-index partitions with particular emphasis on its combinatorics. Then we present the symbolic strategy to generate k-statistics and their generalizations using suitable polynomial sequences and multi-index partitions. The subsequent section deals with generalized (complete exponential) Bell polynomials and some special cases corresponding to well-known families of polynomials. We have also included the procedures to generate joint cumulants from joint moments and vice versa. In the last section we explain the main steps of the algorithm to produce the multivariate Faà di Bruno’s formula. We give examples of how to build new polynomials not included in the package. Some concluding remarks end the paper.
Most routines of the kStatistics package use the partitions of a multi-index i. Therefore, before describing any of these routines, we recall the notion of multi-index partition and describe the algorithm for its construction as implemented in the mkmSet
function of the package.
A partition of the multi-index i=(i1,…,im)∈Nm0 is a matrix Λ=(λr11,λr22,…) of non-negative integers with m rows and no zero columns such that
r1≥1 columns are equal to λ1, r2≥1 columns are equal to λ2 and so on;
the columns λ1<λ2<… are in lexicographic order
the sum of the integers in the t-th row is equal to it, that is λt1+λt2+⋯=it for t=1,2,…,m.
We write Λ⊢i to denote that Λ is a partition of i. Some further notations are:
m(Λ)=(r1,r2,…), the vector of multiplicities of λ1,λ2,…
l(Λ)=|m(Λ)|=r1+r2+⋯, the number of columns of Λ with l(Λ)=0 if Λ⊢0
Λ!=(λ1!)r1(λ2!)r2⋯
Example 1: The partitions of i=(2,1) are the matrices
(21),(0210),(1101),(011100)=(λ1,λ22),
The algorithm to get all the partitions of a multi-index resorts to multiset subdivisions. Let’s start by recalling the notion of multiset. A multiset M is a “set with multiplicities”. Suppose a∈M. Then the multiplicity of a is the number of times a occurs in M as a member. For example, the integers 3 and 2 are the multiplicities of a and b respectively in M={a,a,a,b,b}. A subdivision of the multiset M is a multiset of sub-multisets of M, such that their disjoint union returns M. Examples of subdivisions of M={a,a,a,b,b} are
S1={{a},{a,b},{a,b}},S2={{a},{a,a,b},{b}},countP
function of the package. However, to find multi-index partitions using set partitions is not a particularly efficient algorithm since the computational cost is proportional to the n-th Bell number, if n is the sum of the multi-index components (Charalambides 2002).
The mkmSet
function is based on a different strategy which takes into account the partitions of the multi-index components. When m=1, the mkmSet
function lists all the partitions λ of the integer i. Recall that a partition of an integer i is a sequence λ=(λ1,λ2,…) of weakly decreasing positive integers, named parts of λ, such that λ1+λ2+⋯=i. A different notation is λ=(1r1,2r2,…), where r1,r2,… are the number of parts of λ equal to 1,2,… respectively. The length of the partition is l(λ)=r1+r2+⋯. We write λ⊢i to denote that λ is a partition of i.
In the following, we describe the main steps of the mkmSet
function by working on an example.
Suppose we want to generate all the partitions of (3,2). First consider the partitions of (3,0) obtained from the partitions (3),(1,2),(13) of the integer 3, and the partitions of (0,2) obtained from the partitions (2),(12) of the integer 2, that is
Λ1=(30),Λ2=(1200),Λ3=(111000)⊢(30)
The following iterated adding-appending rule is thus implemented.
1. Consider the partition Λ5 in (10).
1.1 Add the first column of Λ5 to each column of Λ1,Λ2 and Λ3 in (9) one by one with the following rules: the sum must be done only once (if the column has multiplicities greater than one) taking as reference the first column; the sum can be done only to columns whose second component is zero and without subsequent elements (in the same row) greater than or equal to the integer we are adding. Then we have
Λ(1,1)1=(31)Λ(1,1)2=(1210)Λ(2,1)2=(1201)Λ(1,1)3=(111100).
Λ(1,2)1=(3001)Λ(1,2)2=(120001)Λ(1,2)3=(11100001).
Λ(1,1)1=(31)add⇒rule outappend⇒(3011)Λ(1,1)2=(1210)add⇒(1211)append⇒(120101)Λ(2,1)2=(1201)add⇒rule outappend⇒(120011)Λ(1,1)3=(111100)add⇒(111110)append⇒(11101001)Λ(1,2)1=(3001)add⇒rule outappend⇒(300011)Λ(1,2)2=(120001)add⇒rule outappend⇒(12000011)Λ(1,2)3=(11100001)add⇒rule outappend⇒(1110000011)
Λ1=(30)add⇒(32)append⇒(3002)Λ2=(1200)add⇒(1220),(1202)append⇒(120002)Λ3=(111000)add⇒(111200)append⇒(11100002)mkmSet
function lists all the partitions Λ⊢i, with the columns reordered in increasing lexicographic order, together with
the number of set partitions corresponding to the same multi-index partition, that is i!/Λ!m(Λ)!. In the latest version of the kStatistics package, among the input parameters of the mkmSet
function, an input flag parameter has been inserted aiming to print the multi-index partitions in a more compact form. See the following example.
Example 2: To get all the partitions of (2,1) run
> mkmSet(c(2,1),TRUE)
[( 0 1 )( 1 0 )( 1 0 ), 1 ]
[( 0 1 )( 2 0 ), 1 ]
[( 1 0 )( 1 1 ), 2 ]
[( 2 1 ), 1 ]
Note that the integers 1,1,2,1 correspond to the coefficients 2!1!/Λ!m(Λ)!.
Example 3: To get all the partitions of the integer 3 run
> mkmSet(c(3),TRUE)
[( 1 )( 1 )( 1 ), 1 ]
[( 1 )( 2 ), 3 ]
[( 3 ), 1 ]
The mkmSet
function is called by the intPart
function, specifically designed with the purpose of listing only all the partitions of a given integer in increasing order. The input flag parameter allows us to print the partitions in a more compact form.
Example 4: To get all the partitions of the integer 4 run
> intPart(4,TRUE)
[ 1 1 1 1 ]
[ 1 1 2 ]
[ 2 2 ]
[ 1 3 ]
[ 4 ]
The parts
function of the partitions package (Hankin 2006) lists all the partitions of a given integer, but in decreasing order. Instead the get.partitions
function of the nilde package (Arnqvist et al. 2021) finds all the partitions of a given integer with a fixed length l(λ) (Voinov and Pya Arnqvist 2017). If l(λ) is equal to the given integer, the get.partitions
function lists all the partitions in increasing order.
The i-th k-statistic κi is the (unique) symmetric estimator whose expectation is the i-th cumulant ki(Y) of a population character Y and whose variance is a minimum relative to all other unbiased estimators.
The nKS
function generates the numerical value of the i-th k-statistic starting from a data sample. The computation relies on the following polynomials
Pt(y)=t∑j=1yjS(t,j)(−1)j−1(j−1)!fort=1,…,inStirling2
function. In detail, suppose to have a sample {a1,…,aN} of N numerical data and denote with pt the t-th power sum in the numerical data
pt(a1,…,aN)=N∑j=1atj,fort≥1.nKS
function computes the explicit expression of the polynomial of degree i
Qi(y)=∑λ⊢idλPλ(y)pλ
nKS
function are summarized in the following.
Function nKS
i) Compute the power sums pt in (14) for t=1,…,i.
ii) Compute S(t,j)(−1)j−1(j−1)! in (13) for j=1,…,t and t=1,…,i.
iii) Using the
mkmSet
function, compute all the partitions λ⊢i.
iv) For a given partition λ, expand the product Pλ(y) in (15) and compute the coefficient dλpλ of each monomial in Qi(y) using (16).
v) For t=1,…,i multiply (−1)t−1(t−1)!/(N)t with the coefficients of the monomial of degree t carried out at the previous step and do the sum over all the resulting numerical values.
vi) Repeat steps iv) and v) for all the partitions λ carried out at step iii) and do the sum over all the resulting numerical values.
Example 5: Using (15) for i=1, we have Q1(y)=P1(y)p1=y∑Nj=1aj and plugging 1/N in place of y, the sample mean is recovered. Using (15) for i=2, we have
Q2(y)=P2(y)p2+(P1(y)p1)2=yN∑j=1a2j+y2((N∑j=1aj)2−N∑j=1a2j)nKS
function and the mean
function, and the sample variance, computed with the nKS
function and the var
function, for the following dataset:
> data<-c(16.34, 10.76, 11.84, 13.55, 15.85, 18.20, 7.51, 10.22, 12.52, 14.68,
16.08, 19.43, 8.12, 11.20, 12.95, 14.77, 16.83, 19.80, 8.55, 11.58, 12.10, 15.02,
16.83, 16.98, 19.92, 9.47, 11.68, 13.41, 15.35, 19.11)
> nKS(1,data)
[1] 14.02167
> mean(data)
[1] 14.02167
> nKS(2,data)
[1] 12.65007
> var(data)
[1] 12.65007
Using the nKS
function, for instance, the sample skewness and the sample kurtosis can be computed. Let us recall that the sample skewness is a measure of the central tendency of a univariate sample and can be computed as κ3/κ3/22 where κ2 and κ3 are the second and the third k-statistics respectively (Joanes and Gill 1998). The sample kurtosis is a measure of the tail-heaviness of a sample distribution. The sample excess kurtosis is defined as the sample kurtosis minus 3 and can be computed as κ4/κ22 where κ2 and κ4 are the second and the fourth k-statistics respectively (Joanes and Gill 1998).
> nKS(3,data)/sqrt(nKS(2,data))^(3/2)
[1] -0.03216229
> nKS(4,data)/nKS(2,data)^2 + 3
[1] 2.114708
A similar strategy is employed to compute multivariate k-statistics (the nKM
function) of a sample data matrix whose columns each represent a population character. To simplify the notation, in the following we deal with the case of a bivariate data set {(a1,1,a2,1)…,(a1,N,a2,N)} of N paired numerical data. Denote with p(s,t) the bivariate power sum in the paired data
p(s,t)[(a1,1,a2,1),…,(a1,N,a2,N)]=N∑j=1as1,jat2,jfors,t≥1.nKM
function finds the explicit expression of the polynomial
Qi(y)=∑Λ⊢idΛPΛ(y)pΛ
The main steps of the nKM
function are summarized in the following.
Function nKM
i) Compute the bivariate power sums p(s,t) in (17) for s=1,…,i1 and t=1,…,i2.
ii) For i=i1+i2, compute S(t,j)(−1)j−1(j−1)! in (13) for j=1,…,t and t=1,…,i.
iii) Using the
mkmSet
function, compute all the partitions Λ⊢i.
iv) For a given partition Λ, expand the product PΛ(y) in (18) and compute the coefficient dΛpΛ of each monomial in Qi(y) using (19).
v) For j=1,…,i, multiply (−1)j−1(j−1)!/(N)j with the coefficient of the monomial of degree j carried out at the previous step and do the sum over all the resulting numerical values.
vi) Repeat steps iv) and v) for all the partitions Λ carried out at step iii) and do the sum over all the resulting numerical values.
Example 6: To estimate the joint cumulant c2,1 of the following dataset, run
> data1<-list(c(5.31,11.16),c(3.26,3.26),c(2.35,2.35),c(8.32,14.34),
c(13.48,49.45),c(6.25,15.05),c(7.01,7.01),c(8.52,8.52),c(0.45,0.45),
c(12.08,12.08),c(19.39,10.42))
> nKM(c(2,1),data1)
[1] -23.7379
If the first column are observations of a population character X and the second column observations of a population character Y, then c2,1 measures how far from connectedness (as opposite to independence) are X2 and Y (Di Nardo et al. 2020). A similar meaning has the estimation of the joint cumulant c2,2,2 of the following dataset:
> data2<-list(c(5.31,11.16,4.23),c(3.26,3.26,4.10),c(2.35,2.35,2.27),
c(4.31,10.16,6.45),c(3.1,2.3,3.2),c(3.20, 2.31, 7.3))
> nKM(c(2,2,2),data2)
[1] 678.1045
Similarly to k-statistics, polykays are symmetric unbiased estimators of cumulant products. More in detail, when evaluated on a random sample, the i-th polykay gives an estimation of the product ki1(Y)⋯kim(Y), where i=(i1,…,im)∈Nm0 and {kij(Y)} are cumulants of a population character Y.
To simplify the notation, in the following we show how to compute the i-th polykay of N numerical data {a1,…,aN} using the nPS
function for i=(i1,i2). Set i=i1+i2 and suppose i≤N. The computation relies on the so-called logarithmic polynomials
˜Pt(y1,…,yi)=∑λ⊢tyλdλ(−1)l(λ)−1(l(λ)−1)!nPS
function finds the explicit expression of the polynomial
Ai(y1,…,yi)=∑λ⊢idλ˜Pλ(y1,…,yi)pλ
The main steps of the nPS
function are summarized in the following.
Function nPS
i) Set i=i1+i2 and compute the power sums pt in (14) for t=1,…,i.
ii) Generate the polynomials ˜Pt(y1,…,yi) in (20) for t=1,…,i.
iii) Using the
mkmSet
function, compute all the partitions λ⊢i.
iv) For a given partition λ, expand the product ˜Pλ(y1,…,yi) in (21); then plug (23) or 0 in each monomial yλ, depending if λ is or not in the set ˜q(i1,i2) given in (22).
v) Multiply the numerical value of ˜Pλ carried out at step iv) with dλpλ given in (16).
vi) Repeat steps iv) and v) for all the partitions λ carried out at step iii) and do the sum over all the resulting numerical values.
Example 7: Suppose we need to estimate the square of the variance σ2 of the population character Y from which the data of Example 5 have been sampled. We have
> nKS(2,data)^2
[1] 160.0243
> var(data)^2
[1] 160.0243
but k22 is not an unbiased estimator of the square of σ2. An unbiased estimator of such a square is the polykay of order (2,2), that is
> nPS(c(2,2),data)
[1] 154.1177
Multivariate polykays are unbiased estimators of products of multivariate cumulants and the nPM
function returns a numerical value for these estimators when evaluated on a random sample. As before, to show how the nPM
function works, we consider a bivariate sample of N numerical data, that is {(a1,1,a2,1)…,(a1,N,a2,N)}. If we choose i=(i1,i2) and j=(j1,j2) with i1+i2+j1+j2≤N as input of the nPM
function, the output is a numerical value which represents an estimated value of the product ki(X,Y)kj(X,Y), where ki(X,Y) and kj(X,Y) are cumulants of the population characters (X,Y). The computation relies on suitable polynomials in the indeterminates {y(s,t)} for s=0,…,w1,t=0,…,w2, with s+t>0 and w1=i1+j1,w2=i2+j2.
These polynomials are a multivariable generalization of (20), that is
˜Pk({y(s,t)})=∑Λ⊢kyΛdΛ(−1)l(Λ)−1(l(Λ)−1)!nPM
function finds the explicit expression of the polynomial
Aw({y(s,t)})=∑Λ⊢wdΛ˜PΛ({y(s,t)})pΛ
The main steps of the nPM
function are summarized in the following.
Function nPM
i) Set w1=i1+j1 and w2=i2+j2; compute the power sums p(s,t) in (17) for s=1,…,w1 and t=1,…,w2.
ii) Generate the polynomials ˜Pk({y(s,t)}) in (24) for 0<k≤w=(w1,w2).
iii) Using the
mkmSet
function, compute all the partitions Λ⊢w.
iv) For a given partition Λ, expand the product ˜PΛ({y(s,t)}) in (25) and plug (27) or 0 in each obtained monomial of type yΛ depending if Λ is or not in ˜q(w) given in (26).
v) Multiply the numerical value of ˜PΛ obtained at step iv) with dΛpΛ given in (19).
vi) Repeat steps iv) and v) for all the partitions Λ carried out at step iii) and do the sum over all the resulting numerical values.
Example 8: For the same dataset employed in Example 6, to estimate k(2,1)(X,Y)k(1,0)(X,Y) run
> nPM(list(c(2,1),c(1,0)),data1)
[1] 48.43243
Remark 1: The master nPolyk
function runs one of the nKS
, nKM
, nPS
and nPM
functions depending if we ask for simple k-statistics, multivariate k-statistics, simple polykays or multivariate polykays.
The algorithms to produce k-statistics and polykays rely on handling suitable polynomial families which are special cases of generalizations of Bell polynomials, as introduced in this section. Moreover, there are further families of polynomials widely used in applications which are special cases of these polynomials. For the most popular ones, we have implemented special functions in the kStatistics package. The list is not exhaustive, see for instance Roman (1984). Furthermore additional families of polynomials might be recovered using the multivariate Faà di Bruno’s formula. We will give some examples in the next section.
The i-th generalized (complete exponential) Bell polynomial in the indeterminates y1,…,yn is
hi(y1,…,yn)=i!∑Λ⊢s1,…,˜Λ⊢sns1+⋯+sn=iyl(Λ)1⋯yl(˜Λ)ng1,Λ⋯gn,˜ΛΛ!⋯˜Λ!m(Λ)!⋯m(˜Λ)!GCBellPol
function.
Example 9: To get h(1,1)(y1,y2) run
> GCBellPol(c(1,1),2)
[1] (y1)(y2)g1[0,1]g2[1,0] + (y1)(y2)g1[1,0]g2[0,1] + (y1^2)g1[0,1]g1[1,0] +
(y1)g1[1,1] + (y2^2)g2[0,1]g2[1,0] + (y2)g2[1,1]
The e_GCBellPol
function evaluates hi(y1,…,yn) when its indeterminates y1,…,yn and/or its coefficients are substituted with numerical values.
Example 10: To plug the values from 1 to 6 respectively into the coefficients g1[ , ]
and g2[ , ]
of the polynomial h(1,1)(y1,y2) given in Example 9 run
> e_GCBellPol(c(1,1), 2, "g1[0,1]=1, g1[1,0]=2, g1[1,1]=3, g2[0,1]=4, g2[1,0]=5,
g2[1,1]=6")
[1] 13(y1)(y2) + 2(y1^2) + 3(y1) + 20(y2^2) + 6(y2)
To evaluate h(1,1)(1,5) run
> e_GCBellPol(c(1,1), 2, "y1=1, y2=5, g1[0,1]=1, g1[1,0]=2, g1[1,1]=3, g2[0,1]=4,
g2[1,0]=5, g2[1,1]=6")
[1] 600
When the multi-indexed sequences {g1;λ},…,{gn;˜λ} are all equal, the number of distinct addends in (28) might reduce and the corresponding generalized Bell polynomial is denoted by ˜hi(y1,…,yn). To deal with this special case, we have inserted an input flag parameter in the e_GCBellPol
function.
Example 11: To compare ˜h(1,1)(y1,y2) with h(1,1)(y1,y2) given in Example 9 run
> GCBellPol(c(1,1),2,TRUE)
[1] 2(y1)(y2)g[0,1]g[1,0] + (y1^2)g[0,1]g[1,0] + (y1)g[1,1] + (y2^2)g[0,1]g[1,0] +
(y2)g[1,1]
Set n=1 in (28). Then hi(y1,…,yn) reduces to the univariate polynomial
hi(y)=∑Λ⊢iyl(Λ)dΛgΛ
Example 12: To get h(1,1)(y) run
> GCBellPol(c(1,1),1)
[1] (y^2)g[0,1]g[1,0] + (y)g[1,1]
Remark 2: For all i∈Nm0, we have hi(y1+⋯+yn)=˜hi(y1,…,yn), where ˜hi(y1,…,yn) is the i-th generalized Bell polynomial (28) corresponding to all equal multi-indexed sequences {g1,λ},…,{gn,˜λ} (Di Nardo 2011). Therefore the e_GCBellPol
function, with the input flag TRUE
, produces also an explicit expression of hi(y1+⋯+yn).
The algorithm to generate joint moments in terms of joint cumulants and vice versa follows the same pattern designed to generate {hi(y)}. Indeed if {ki(Y)} and {mi(Y)} denote the sequences of joint cumulants and joint moments of a random vector Y respectively, then
mi(Y)=∑Λ⊢idΛkΛ(Y)andki(Y)=∑Λ⊢i(−1)l(Λ)−1(l(Λ)−1)!dΛmΛ(Y),
the mom2cum
function returns the right hand side of the first equation in (31), using the same algorithm producing hi(y) in (30) with the sequence {kλ} in place of {gλ} and with 1 in place of y;
the cum2mom
function returns the right hand side of the latter equation in (31), using the same algorithm producing hi(y) in (30) with the sequence {mλ} in place of {gλ} and with (−1)j−1(j−1)! in place of the powers yj for j=1,…,|i|.
When the multi-index i reduces to an integer i, formulae (31) are the classical expressions of univariate moments in terms of univariate cumulants and vice versa. The mom2cum
and cum2mom
functions do the same when the input is an integer.
Example 13: To get m(3,1) in terms of k(i,j) run
> mom2cum(c(3,1))
[1] k[0,1]k[1,0]^3 + 3k[0,1]k[1,0]k[2,0] + k[0,1]k[3,0] + 3k[1,0]^2k[1,1] +
3k[1,0]k[2,1] + 3k[1,1]k[2,0] + k[3,1]
To get k(3,1) in terms of m(i,j) run
> cum2mom(c(3,1))
[1] - 6m[0,1]m[1,0]^3 + 6m[0,1]m[1,0]m[2,0] - m[0,1]m[3,0] +
6m[1,0]^2m[1,1] - 3m[1,0]m[2,1] - 3m[1,1]m[2,0] + m[3,1]
Remark 3: There are different functions in R
performing similar computations for cumulants and moments: for instance see De Leeuw, J. (2012) for the multivariate case. A different strategy would rely on the recursive relations between cumulants and moments (Domino et al. 2018).
Similarly to (31), some of the polynomials employed in the previous sections are generated using the same pattern developed to find the explicit expression of hi(y) in (30):
The generation of an explicit expression of Qi(y) in (18) parallels the one implemented for hi(y) with 1 in place of y and with the polynomial sequence {P|λ|(y)pλ} in place of the sequence {gλ};
the same for the polynomials ˜Pk({y(s,t)}) in (24) with (−1)j−1(j−1)! for j=1,…,|i| in place of the powers yj and with the polynomial sequence {yλ} in place of the sequence {gλ};
the same for the polynomials Aw({y(s,t)}) in (25) with 1 in place of y and with the polynomial sequence {˜Pλ({y(s,t)})pλ} in place of the sequence {gλ}.
Note that when the multi-index i in (30) reduces to a positive integer i, then the polynomial hi(y) becomes
hi(y)=∑λ⊢idλyl(λ)gλ
Example 14: To get h3(y) run
> GCBellPol(c(3),1)
[1] (y^3)g[1]^3 + 3(y^2)g[1]g[2] + (y)g[3]
With a combinatorial structure very similar to (32), the i-th general partition polynomial has the following expression in the indeterminates y1,…,yi
Gi(a1,…,ai;y1,…,yi)=∑λ⊢idλal(λ)yλgpPart
function.
Example 15: To get G4(a1,a2,a3,a4;y1,y2,y3,y4) run
> gpPart(4)
[1] a4(y1^4) + 6a3(y1^2)(y2) + 3a2(y2^2) + 4a2(y1)(y3) + a1(y4)
When a1=…=ai=1, the i-th general partition polynomial in (34) reduces to
the complete (exponential) Bell polynomial
Gi(1,…,1;y1,…,yi)=i∑j=1Bi,j(y1,…,yi−j+1)
The eBellPol
function returns the complete (exponential) Bell polynomials (36). The same function also produces the (partial) exponential Bell polynomial Bi,j(y1,…,yi−j+1) using (33) with ak=δk,j (the Kronecker delta) for k=1,…,i. Mihoubi (2008) gives a rather extensive survey of applications of these homogeneous polynomials.
Example 16: To get B5,3(y1,y2,y3) run
> eBellPol(5,3)
[1] 15(y1)(y2^2) + 10(y1^2)(y3)
To get G4(1,1,1,1;y1,y2,y3,y4) run
> eBellPol(4)
[1] (y1^4) + 6(y1^2)(y2) + 3(y2^2) + 4(y1)(y3) + (y4)
The oBellPol
function returns the partial (ordinary) Bell polynomials
ˆBi,j(y1,…,yi−j+1)=j!i!Bi,j(1!y1,2!y2,…,(i−j+1)!yi−j+1)
Example 17: To get ˆB5,3(y1,y2,y3) run
> oBellPol(5,3)
[1] 1/120( 360(y1)(y2^2) + 360(y1^2)(y3) )
To get ˆG3(y1,y2,y3,y4) run
> oBellPol(4)
[1] 1/24( 24(y1^4) + 72(y1^2)(y2) + 24(y2^2) + 48(y1)(y3) + 24(y4) )
The e_eBellPol
function evaluates the exponential Bell polynomials when the indeterminates are substituted with numerical values. In Table 1 some special sequence of numbers are given obtained using this procedure.
Table 1: Numerical sequences (second column) obtained evaluating the exponential Bell polynomials (last column) when suitable numerical values replace indeterminates.
SequenceBell polynomialsLah numbersi!j!(i−1j−1)Bi,j(1!,2!,3!,…)Stirling numbers of first kinds(i,j)Bi,j(0!,−1!,2!,…)unsigned Stirling numbers of first kind|s(i,j)|Bi,j(0!,1!,2!,…)Stirling numbers of second kindS(i,j)Bi,j(1,1,1,…)idempotent numbers(ij)ji−jBi,j(1,2,3,…)Bell numbersBi∑ij=0Bi,j(1,1,1,…)e_eBellPol
function returns the Stirling numbers of second kind, as the following example shows.
Example 18: To get S(5,3) run
> e_eBellPol(5,3)
[1] 25
> e_eBellPol(5,3,c(1,1,1,1,1))
[1] 25
To get the 5-th Bell number B5 run
> e_eBellPol(5)
[1] 52
To get s(5,3) run
> e_eBellPol(5,3, c(1,-1,2,-6,24))
[1] 35
In (3), suppose ft the t-th coefficient of f(x) and g1;s1,…,gn;sn the s1-th,…,sn-th coefficients of g1(z),…,gn(z) respectively. Using multi-index partitions, the multivariate Faà di Bruno’s formula (6) can be written as (Di Nardo et al. 2011)
hi=i!∑Λ⊢s1,…,˜Λ⊢sns1+⋯+sn=if(l(Λ),…,l(˜Λ))g1,Λ⋯gn,˜ΛΛ!⋯˜Λ!m(Λ)!⋯m(˜Λ)!
The MFB
function generates all the summands of (37). Its first step is to find the set ˜p(n,i) of all the compositions of i in n parts, that is all the n-tuples
(s1,…,sn) of non-negative integer m-tuples such that s1+⋯+sn=i. This task is performed by the mkT
function.
Function mkT
i) Find all the partitions Λ⊢i, using the
mkmSet
function.
ii) Select the first partition Λ. If l(Λ)=n, then the columns of Λ are the m-tuples (s1,…,sn) such that s1+…+sn=i. If l(Λ)<n, add n−l(Λ) zero columns to Λ.
iii) Generate all the permutations of the columns of Λ as collected at step ii).
iv) Repeat steps ii) and iii) for each partition Λ carried out at step i).
In the mkT
function an input flag variable permits to obtain the output in a more compact set up. See the following example.
Example 19: Suppose we are looking for the elements of the set ˜p(2,(2,1)), that is the pairs (s1,s2) such that s1+s2=(2,1). Then run
> mkT(c(2,1),2,TRUE)
[( 0 1 )( 2 0 )]
[( 2 0 )( 0 1 )]
[( 1 0 )( 1 1 )]
[( 1 1 )( 1 0 )]
[( 2 1 )( 0 0 )]
[( 0 0 )( 2 1 )]
Consider the partitions of (2,1) as given in Example 2. Note that [( 2 1 )( 0 0 )]
and [( 0 0 )( 2 1 )]
are obtained adding a zero column to the partition [( 2 1 ), 1 ]
, and then permuting the two columns. No zero columns are added to [( 2 0 )( 0 1 )]
as the length of the partition is 2. The same is true for [( 0 1 )( 2 0 )]
or [( 1 1 )( 1 0 )]
which are only permuted.
The MFB
function produces the multivariate Faà di Bruno’s formula (37) making use of the following steps.
Function MFB
i) Find all the m-tuples (s1,…,sn) in ˜p(n,i) using the
mkT
function.
ii) Let y1,…,yn be indeterminates. For each j=1,…,n, compute all the partitions Λ⊢sj using the
mkmSet
function and find the explicit expression of the polynomial qj,sj(yj)=sj!∑Λ⊢sjyl(Λ)jgj,ΛΛ!m(Λ)!.
iii) Make the products q1,s1(y1)⋯qn,sn(yn) in the multivariable polynomial hi(y1,…,yn)=∑(s1,…,sn)∈˜p(n,i)(is1,…,sn)q1,s1(y1)⋯qn,sn(yn)
and compute its explicit expression.
iv) In the explicit expression of the polynomial hi(y1,…,yn) as carried out at the previous step iii), replace the occurrences of the products yl(Λ)1⋯yl(˜Λ)n with f(l(Λ),…,l(˜Λ)).
Step iii) is performed by the joint
function. This function is not directly accessible in the package, as defined locally in the MFB
function. The joint
function realizes a recursive pair matching: each coefficient g1,Λ of q1,s1(y1) is matched with each coefficient g2,˜Λ of q2,s2(y2), then each paired coefficient g1,Λg2,˜Λ is matched with each coefficient g3,Λ∗ of q3,s3(y3) and so on. Step iv) consists of multiplying each coefficient found at step iii) with ft, where t is the multi-index whose j-th component gives how many times gj,⋅ appears in this coefficient. See the following example.
Example 20: Suppose n=m=2 and i=(1,1). To get h(1,1) in (37) run
> MFB(c(1,1),2)
[1] f[1,1]g1[0,1]g2[1,0] + f[1,1]g1[1,0]g2[0,1] + f[2,0]g1[0,1]g1[1,0] +
f[1,0]g1[1,1] + f[0,2]g2[0,1]g2[1,0] + f[0,1]g2[1,1]
Taking into account (4), in the previous output f[i,j]
corresponds to f(i,j) as well as g1[i,j]
and g2[i,j]
correspond to g1;(i,j) and g2;(i,j) respectively for i,j=0,1,2. Note that g1[1,1]
is multiplied with f[1,0]
as there is one occurrence of g1
and no occurrence of g2
. In the same way, g1[1,0]g1[0,1]
is multiplied with f[2,0]
as there are two occurrences of g1
and no occurrence of g2
and g1[1,0]g2[0,1]
is multiplied with f[1,1]
as there is one occurrence of g1
and one occurrence of g2
and so on. Compare the previous output with the one obtained in Maple
running
diff(f(g1(x1,x2),g2(x1,x2),x1,x2): D2,2(f)(g1(x1,x2),g2(x1,x2))(∂∂x1g2(x1,x2))(∂∂x2g2(x1,x2))+D1,2(f)(g1(x1,x2),g2(x1,x2))(∂∂x2g1(x1,x2))(∂∂x1g2(x1,x2))+D1,2(f)(g1(x1,x2),g2(x1,x2))(∂∂x1g1(x1,x2)))(∂∂x2g2(x1,x2))+D1,1(f)(g1(x1,x2),g2(x1,x2))(∂∂x1g1(x1,x2)))(∂∂x2g1(x1,x2)))+D2(f)(g1(x1,x2),g2(x1,x2))(∂2∂x2∂x1g2(x1,x2))+D1(f)(g1(x1,x2),g2(x1,x2))(∂2∂x2∂x1g1(x1,x2))
where D1(f) denotes ∂f(x1,x2)/∂x1,D2(f) denotes ∂f(x1,x2)/∂x2 and similarly D1,1(f)←∂2f(x1,x2)∂x21,D2,2(f)←∂2f(x1,x2)∂x22,D1,2(f)←∂2f(x1,x2)∂x1∂x2.
The eMFB
function evaluates the multivariate Faà di Bruno’s formula (37) when the coefficients of the formal power series f and g1,…,gn in (4) are substituted with numerical values.
Example 21: To evaluate the output of Example 20 for some numerical values of the coefficients, run
> cfVal<-"f[0,1]=2, f[0,2]=5, f[1,0]=13, f[1,1]=-4, f[2,0]=0"
> cgVal<-"g1[0,1]=-2.1, g1[1,0]=2,g1[1,1]=3.1,g2[0,1]=5,g2[1,0]=0,g2[1,1]=6.1"
> cVal<-paste0(cfVal,",",cgVal)
> e_MFB(c(1,1),2,cVal)
[1] 12.5
The polynomial families discussed in the previous sections are generated using the MFB
function. Indeed, the generalized (complete exponential) Bell polynomials in (28) are coefficients of the following formal power series
H(y1,…,yn;z)=1+∑|i|>0hi(y1,…,yn)zii!=exp[n∑i=1yi(gi(z)−1)],GCBellPol
function - is obtained from the multivariate Faà di Bruno’s formula (37) dealing with y1,…,yn as they were constants. When {g1(z),…,gn(z)} are the same formal power series g(z), the formal power series H(y1,…,yn;z) in (38) reduces to
H(y1,…,yn;z)=exp[(y1+⋯+yn)(g(z)−1)]
If n=1 then H(y1,…,yn;z) reduces to the composition exp[y(g(z)−1)] whose coefficients are the polynomials given in (30). More in general the coefficients of f(g(z)−1) are
hi=∑Λ⊢idΛfl(Λ)gΛ
> MFB(c(5), 1)
[1] f[5]g[1]^5 + 10f[4]g[1]^3g[2] + 15f[3]g[1]g[2]^2 + 10f[3]g[1]^2g[3] +
10f[2]g[2]g[3] + 5f[2]g[1]g[4] + f[1]g[5]
For instance, the i-th general partition polynomial in (33) is generated using the MFB
function: in such a case the univariate Faà di Bruno’s formula (41) is generated with {ys} in place of {gs} and {aj} in place of {fj}.
In the following we give some suggestions on how to use the R
codes of the kStatistics package to generate additional polynomial families.
The pPart
function is an example of how to use the univariate Faà di Bruno’s formula and a symbolic strategy different from those presented so far. Indeed the pPart
function generates the so-called partition polynomial Fi(y) of degree i, whose coefficients are the number of partitions of i with j parts for j=1,…,i (Boyer and Goh 2008). The partition polynomial Fi(y) is obtained from the univariate Faà di Bruno’s formula (41) setting
fj=1/i!andgrss=(s!)rsrs!yrs
Example 23: To get F5(y) run
> pPart(5)
[1] y^5 + y^4 + 2y^3 + 2y^2 + y
Note that F5(y) is obtained from the output of Example 22 using (42).
Example 24: The following code shows how to evaluate F11(y) in y=7.
> s<-pPart(11) # generate the partition polynomial of degree 11
> s<-paste0("1",s) # add the coefficient to the first term
> s<-gsub(" y","1y",s) # replace the variable y without coefficient
> s<-gsub("y", "*7",s) # assign y = 7
> eval(parse(text=s)) # evaluation of the expression
[1] 3.476775e+182
We give a further example on how to generate a polynomial family not introduced so far but still coming from (41) for suitable choices of {fj} and {gs}. Consider the elementary symmetric polynomials in the indeterminates y1,…,yn
ei(y1,…,yn)={∑1≤j1<⋯<ji≤nyj1⋯yji,1≤i≤n,0,i>n.e2p
function expresses the i-th elementary symmetric polynomial ei in terms of the power sum symmetric polynomials p1,…,pi, using (44) and the MFB
function.
> e2p <- function(n=0){
+ v<-MFB(n,1); # Call the MFB Function
+ v<-MFB2Set( v ); # Expression to vector
+ for (j in 1:length(v)) {
+ # ----- read -----------[ fix block ]-----------------------#
+ c <- as.character(v[[j]][2]); # coefficient
+ x <- v[[j]][3]; # variable
+ i <- v[[j]][4]; # subscript
+ k <- strtoi(v[[j]][5]); # power
+ # ----- change --------------------------------------------#
+ if (x=="f") {
+ c<-paste0(c,"*( (-1)^",n,")");
+ x<-"";
+ i<-"";
+ }
+ else if (x=="g") {
+ c<-paste0(c,"*((-factorial(",strtoi(i)-1,"))^",k,")");
+ x<-paste0("(p",i,ifelse(k>1,paste0("^",k),""),")");
+ i<-"";k<-1;
+ }
+ # ----- write ---------[ fix block ]-----------------------#
+ v[[j]][2] <- c;
+ v[[j]][3] <- x;
+ v[[j]][4] <- i;
+ v[[j]][5] <- k;
+ # ---------------------------------------------------------#
+ }
+ noquote(paste0("1/",factorial(n),"( ",Set2expr(v), " )"));
+ }
This function starts by initializing the vector v
with (41) by means of the MFB
function. There is a first code snippet [fix block]
for extracting a set with the coefficients, variables, indexes and powers of v
by means of the MFB2Set
function. This first code snippet should not be changed whatever polynomial family we are generating. The second code snippet change
includes instructions that can be changed according to the expressions of the coefficients {fj} and {gs} in (41). To get (44), we set fj=1 and gs=−(s−1)!ps. Once these coefficients have been changed, the last code snippet [fix block]
updates the vector v
. The Set2expr
function assembles the final expression.
Example 25: To get e4 in (44) run
> e2p(4)
[1] 1/24( (p1^4) - 6(p1^2)(p2) + 3(p2^2) + 8(p1)(p3) - 6(p4) )
We have developed the kStatistics package with the aim to generate univariate and multivariate k-statistics/polykays, togheter with the multivariate Faà di Bruno’s formula and various user-friendly functions related to this formula. The paper briefly introduces the combinatorial tools involved in the package and presents, in detail, the core function of the package which generates multi-index partitions. We emphasize that the algorithms presented here have been designed with the aid of the umbral calculus, even if we did not mentioned this method in the paper.
One of the main applications we have dealt with is the generation and evaluation of various families of polynomials: from generalized complete Bell polynomials to general partition polynomials, from partial Bell polynomials to complete Bell polynomials. Numerical sequences obtained from the Bell polynomials can also be generated.
All these utilities intend to make the kStatistics package a useful tool not only for statisticians but also for users who need to work with families of polynomials usually available in symbolic software or tables. Indeed, we have provided examples on how to generate polynomial families not included in the package but which can still be recovered using the Faà di Bruno’s formula and suitable strategies, both numerical and symbolic. Following this approach, also the estimations of joint cumulants or products of joint cumulants is one further example of symbolic strategy coming from the multivariate Faà di Bruno’s formula.
Future works consist in expanding the kStatistics package by including extensions of the multivariate Faà di Bruno’s formula, as addressed in Bernardini et al. (2005) and references therein, aiming to manage nested compositions, as the BellY
function in the Wolfram Language and System does. Moreover, further procedures can be inserted relied on symbolic strategies not apparently related to the multivariate Faà di Bruno’s formula but referable to this formula, as for example the central Bell polynomials (Kim et al. 2019).
The results in this paper were obtained using the kStatistics 2.1.1 package. The package is currently available with a general public license (GPL) from the Comprehensive R
Archive Network.
The authors would like to thank the reviewers for their constructive feedback.
Supplementary materials are available in addition to this article. It can be downloaded at RJ-2022-033.zip
kStatistics, partitions, nilde
NumericalMathematics, Optimization
Text and figures are licensed under Creative Commons Attribution CC BY 4.0. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".
For attribution, please cite this work as
Nardo & Guarino, "kStatistics: Unbiased Estimates of Joint Cumulant Products from the Multivariate Faà Di Bruno's Formula", The R Journal, 2022
BibTeX citation
@article{RJ-2022-033, author = {Nardo, Elvira Di and Guarino, Giuseppe}, title = {kStatistics: Unbiased Estimates of Joint Cumulant Products from the Multivariate Faà Di Bruno's Formula}, journal = {The R Journal}, year = {2022}, note = {https://doi.org/10.32614/RJ-2022-033}, doi = {10.32614/RJ-2022-033}, volume = {14}, issue = {2}, issn = {2073-4859}, pages = {208-228} }