Code covered by the BSD License

Highlights from TDIST

Be the first to rate this file! 13 Downloads (last 30 days) File Size: 89.4 KB File ID: #4199 Version: 1.5

TDIST

Viktor Witkovsky (view profile)

26 Nov 2003 (Updated )

Distribution of a linear combination of independent symmetric random variables, e.g. Student's t

File Information
Description

TDIST Computes the distribution (PDF, CDF or QF - quantiles) of a linear combination of independent SYMMETRIC (zero-mean) 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 (U-distribution) U(-1,1),
- symmetric CHI2 (mixture of CHI2 and -CHI2) distribution.
TDIST is based on numerical inversion of the characteristic function (Gil-Pelaez method). The required integration is performed by the 14-points Gaussian quadrature over N sub-intervals 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 chi2-mixture 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] GIL-PELAEZ, 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., Physica-Verlag/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.: 01-Dec-2014 01:30:48

Acknowledgements

Lambert Wchi2 and Chebfun Current Version inspired this file.

This file inspired Lambert Wchi2, Logndist, and Fdist.

Required Products Curve Fitting Toolbox
Statistics and Machine Learning Toolbox
MATLAB
MATLAB release MATLAB 8.3 (R2014a)
MATLAB Search Path
/
/html
30 Nov 2014 Viktor Witkovsky

Viktor Witkovsky (view profile)

Student's t distribution

Comment only
05 Dec 2003

Improved precission of tcdfw and tpdfw.

09 Dec 2003

Corrected Error (normalizing constant) in tpdfw.

29 Jan 2004

Completely rewritten algorithm, ver.3.0.

29 Nov 2014 1.1

Completely rewritten version

29 Nov 2014 1.2

Summary updated

30 Nov 2014 1.3

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

01 Dec 2014 1.4

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

01 Dec 2014 1.5

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