The Mathematica Journal
Departments
Current Issue
Tricks of the Trade
In and Out
Riemann Surfaces IIc
The Mathematica Programmer
New Products
New Publications
Classifieds
Calendar
News Bulletins
Library
Editor's Pick
Mailbox
FAQ
Write Us
About the Journal
Staff and Contributors
Submissions
Subscriptions
Advertising
Back Issues
Home
Download This Issue

Package Usage

Code similar to the input of the previous section is at the core of the package ProbabilitySeries. The package ProbabilitySeries defines six functions. The first three--GramCharlierSeries, GammaSeries, and BetaSeries--generate a series for a density function. The remaining three functions generate a series for the complementary-cumulative distribution function, or, -function for short. The -function is related to the distribution function, , as follows.


The Q-functions are: GramCharlierQ, GammaQ, and BetaQ. Use of several of these functions is demonstrated in the remainder of this paper. Those omitted from this discussion should be applied in a similar fashion.

As was done in the previous section, the simplest demonstration of these functions is to show that they return only the zero-order term when applied to the moments for the base density function. This exercise is carried out for the functions GramCharlierSeries, GammaSeries, and BetaSeries.

As in the case of GramCharlierSeries above, each of these functions requires that either a characteristic function or a function to directly evaluate moments be supplied. In the first example, GramCharlierSeries is called on to generate the first 20 series terms using the characteristic function of a Gaussian density function.

The series is exactly equal to the Gaussian density function with mean and variance specified by the characteristic function. Higher-order terms are zero as expected.

In the next two examples, the functions momGamma and momBeta generate the moments for a Gamma and Beta density, respectively.

GammaSeries[x,n,f,xorigin] returns the first n terms of the Gamma series for the PDF with the moments supplied by f. The function f either gives the nth moment directly (Moment->MomFun) or, for the default case, is a characteristic function which is used to find the moments (Moment->CharFun). PDF[x]==0 for all x < xorigin. GammaSeries returns unevaluated if x is a numerical argument < xorigin.

The results are exactly equal to the Gamma and Beta density function corresponding to the supplied moments. Again, higher-order terms are zero as expected.

The next two examples are concerned with the following sum


where is a sequence of independent random variables, each uniformly distributed on . As approaches infinity, the density function of will tend to a Gaussian density as predicted by the central limit theorem, so appears a suitable target for application of one of our density function series representations. The most common application of the methods described here are to problems of the form in equation (14). Moments of are easily found in this case provided the characteristic function of the is known.

The specific case considered is . This case is examined partly because with is still occasionally suggested as a computational algorithm to generate Gaussian variates given a uniform random number generator. The following efforts will show as a side result how well approximates a Gaussian random variate. (Evaluation of equation (14) for is a poor Gaussian random number generator, yielding mediocre accuracy for the required number of uniform variates. See [5] for excellent alternates.)

For this example, fz[x] gives an exact expression for the density function of . In order to generate the Gram-Charlier series, a function, fmom, is defined to generate the moments of directly. Note p below.

The Gram-Charlier series will be evaluated for degrees 0, 5, 10, 20, and 50.

Here fGCz[x] is a list of truncated Gram-Charlier series with degree 0, 5, 10, 20, and 50. (Note that generation of the list of series takes approximately 5 seconds on a 500 MHz Pentium III.) The exact density function evaluated with argument 2 is as follows.

The following table compares the relative error made when approximating this value using a truncated Gram-Charlier series of the indicated degree.

Note that the series appears to converge with increasing degree as it should for this case. Normally, accuracy of the truncated series of the type considered here tends to improve as approaches the mean value, in this case zero, of the true density function.

Figure 1 contains a plot of fz[x] and the same truncated Gram-Charlier series used above, evaluated for in the interval (2, 5). Note that higher-degree series are required for useful approximations in the density function tails. Asymptotic methods such as those described in [6] are more efficient for use in the tails of the density function than the series representations described here.

Figure 1. Comparison of exact density for z with the absolute value of five truncated Gram-Charlier series of degree (0, 5, 10, 20, 50).

Figure 1 compares the exact density of with the absolute value of the truncated Gram-Charlier series. Note the sharp points on the curves, indicating where the truncated series crosses zero. If the true density were not available in this case, the first zero crossing could be used as an upper bound on the useful application domain of a given truncated series. The degree-0 curve confirms that random number generation based on would serve as a mediocre approximation to a Gaussian random variate as noted earlier.

Since is clearly distributed over a finite interval, , the Beta-series, which is based on a weight function with support on a finite interval, might better approximate the density of . This is demonstrated in Figure 2 which contains a plot of fz[x] and the truncated Beta-series. To create this figure, series of degree 0, 5, 10, 20, and 50 were evaluated for in the interval (2, 5). The relative approximation error of the truncated series is evaluated below for . (Note that generation of the list of series takes approximately 30 seconds on a dedicated 500 MHz Pentium III.)

Figure 2. Comparison of the exact density for z with five truncated Beta-series of degree (0, 5, 10, 20, 50). Note that the curve for degree 50 is indistinguishable from the exact result, except just above the x-axis.


Copyright © 2002 Wolfram Media, Inc. All rights reserved.

[Article Index][Prev Page][Next Page]