Distribution of a linear combination of independent symmetric random variables, e.g. Student's t
TDIST Computes the distribution (PDF, CDF or QF  quantiles) of a linear combination of independent SYMMETRIC (zeromean) random variables (RVs), say Y = sum_i \lambda_i X_i, with X_i having specific distributions:
 STUDENT's t distribution with 0 < df < Inf,
 NORMAL distribution N(0,1),
 RECTANGULAR (uniform) distribution R(1,1),
 symmetric TRIANGULAR distribution T(1,1),
 symmetric ARCSINE distribution (Udistribution) U(1,1),
TDIST is based on numerical inversion of the characteristic function (GilPelaez method). The required integration is performed by the 14points Gaussian quadrature over N subintervals of [0, Tmax].
SYNTAX:
[yfun,xfun,results] = TDIST(X,df,lambda,funtype,options)
INPUT:
X  vector of appropriate (funtype) x values if X = [] then xfun is generated automatically
df  vector of degrees of freedom of independent STUDENT's t RVs, t_df, for 0 < df < Inf. Further,
set df = Inf for the NORMAL RVs, N(0,1),
set df = 1 for the RECTANGULAR RVs, R(1,1),
set df = 2 for the symmetric TRIANGULAR RVs, T(1,1),
set df = 3 for the symmetric ARCSINE RVs, U(1,1),
set df < 10 for the symmetric mixture of CHI2 and CHI2 RVs with nu = abs(df+10) degrees of freedom.
lambda  vector of coefficients of the linear combination
funtype  default value is 1 (calculates the CDF)
The following funtypes are legible:
0: TDIST calculates CDF and PDF, yfun = [CDF,PDF].
1: TDIST calculates the cumulative distribution function, CDF at X, yfun = CDF.
2: TDIST calculates the probability density function, PDF, at X, yfun = PDF.
3: TDIST calculates the quantile function, QF at X, yfun = QF.
4: TDIST calculates the characteristic function, CHF at X, yfun = CHF.
EXAMPLE 1: (CDF of a linear combination of RVs defined by df)
df = [Inf 1 1 2 3];
lambda = [1 1 5 1 10];
funtype = 1;
[cdf,x] = tdist([],df,lambda,funtype);
EXAMPLE 2: (PDF of a linear combination of RVs defined by df)
df = [Inf 1 1 2 3];
lambda = [1 1 5 1 10];
funtype = 2;
[pdf,x] = tdist([],df,lambda,funtype);
EXAMPLE 3: (QF of a linear combination of RVs defined by df)
options.isPlot = false;
df = [Inf 1 1 2 3];
lambda = [1 1 5 1 10];
funtype = 3;
prob = [0.9 0.95 0.99]';
qf = tdist(prob,df,lambda,funtype,options);
disp([prob qf]);
EXAMPLE 4: (CHF of a linear combination of RVs defined by df)
options.isPlot = true;
df = [Inf 1 1 2 3];
lambda = [1 1 5 1 10];
funtype = 4;
t = linspace(0,pi);
chf = tdist(t,df,lambda,funtype,options);
EXAMPLE 5 (Create PDF as a CHEBFUN function and use it to compute CDF)
df_true = [1 2 3 10];
df = 10  df_true; % symmetric chi2mixture distributions
lambda = [1 1 1 1];
funtype = 2;
N = 2^10;
xmax = 130;
x = xmax * cos((0:N)*pi/N);
f = tdist(x,df,lambda,funtype);
pdf = chebfun(f,[xmax,xmax]);
integrate = sum(pdf);
cdf = cumsum(pdf);
xnew = linspace(50,50);
figure
plot(xnew,cdf(xnew))
EXAMPLE 6: (Create a CHEBFUN for the QF)
options.isChebfun = true;
options.n = 2^8;
options.N = 2^9;
df = [Inf 1 1 2 3];
lambda = [1 1 5 1 10];
funtype = 3;
[qf,prob,results] = tdist([],df,lambda,funtype,options);
QF = results.chebfun;
disp(QF([0.9 0.95 0.99]'))
The algorithm requires evaluation of the BesselK and BesselJ functions.
The algorithm requires evaluation of the BesselK and BesselJ functions.
REFERENCES:
[1] GILPELAEZ, J. Note on the inversion theorem. Biometrika 38 (1951), 481–482.
[2] WITKOVSKY , V. On the exact computation of the density and of the quantiles of linear combinations of t and F random variables. Journal of Statistical Planning and Inference 94 (2001), 1–13.
[3] WITKOVSKY , V. Matlab algorithm TDIST: The distribution of a linear combination of Student’s t random variables. In COMPSTAT 2004 Symposium (2004), J. Antoch, Ed., PhysicaVerlag/Springer 2004, Heidelberg, Germany,1995–2002.
[4] DRISCOLL, T. A., HALE, N., TREFETHEN, L. N. Chebfun Guide. Pafnuty Publications, Oxford, 2014.
Viktor Witkovsky (witkovsky@gmail.com)
Ver.: 01Dec2014 01:30:48
1.6  Corrected was the error in computing the quantile function QF (changed was the starting value for the iteration procedure. Now, qf0 = 0). 

1.5  Added CHF2PDF. A simple function for evaluation of the PDF from the characteristic function by the Fast Fourier Transform (FFT). 

1.4  Added symmetric CHI2 distribution (symmetric mixture of CHI2 and minus CHI2 distributions). Possibility to create a CHEBFUN representation of the output functions. 

1.3  TDIST distributions: Student's t_nu, Normal N(0,1), Rectangular R(1,1,), Triangular T(1,1), Arcsine U(1,1) 

1.2  Summary updated 

1.1  Completely rewritten version 

Completely rewritten algorithm, ver.3.0. 

Corrected Error (normalizing constant) in tpdfw. 

Improved precission of tcdfw and tpdfw. 
Inspired by: LambertWchi2, Chebfun  current version, Collective Risk Model Tool
Inspired: LambertWchi2
Viktor Witkovsky (view profile)
Student's t distribution