Given a sample of observations, , from a distribution with unknown density function, , an estimate of the density function, , may be required. The simplest form of density estimator is the histogram. This may be defined by:
where is the number of observations falling in the interval to , is the lower bound to the histogram, is the upper bound and is the total number of intervals. The value is known as the window width. To produce a smoother density estimate a kernel method can be used. A kernel function, , satisfies the conditions:
The kernel density estimator is then defined as
The choice of is usually not important but to ease the computational burden use can be made of the Gaussian kernel defined as
The smoothness of the estimator depends on the window width . The larger the value of the smoother the density estimate. The value of can be chosen by examining plots of the smoothed density for different values of or by using cross-validation methods (see Silverman (1990)).
Silverman (1982) and Silverman (1990) show how the Gaussian kernel density estimator can be computed using a fast Fourier transform (FFT). In order to compute the kernel density estimate over the range to the following steps are required.
where is the inter-quartile range and the standard deviation of the sample, , and is a multipler supplied in WINDOW. The and quartiles, and , are calculated using G01AMF. This is the "rule-of-thumb" suggested by Silverman (1990).
4: – REAL (KIND=nag_wp)Input/Output
On entry: if , then , the window width. Otherwise, , the multiplier used in the calculation of .
On exit: , the window width actually used.
5: – REAL (KIND=nag_wp)Input/Output
On entry: if then , the lower limit of the interval on which the estimate is calculated. Otherwise, and , the lower and upper limits of the interval, are calculated as follows:
where is the window width.
For most applications should be at least three window widths below the lowest data point.
If , SLO must be unchanged since the last call to G10BBF.
and which would cause and to be set window widths below and above the lowest and highest data points respectively.
On exit: , the lower limit actually used.
6: – REAL (KIND=nag_wp)Input/Output
On entry: if then , the upper limit of the interval on which the estimate is calculated. Otherwise a value for is calculated from the data as stated in the description of SLO and the value supplied in SHI is not used.
For most applications should be at least three window widths above the highest data point.
If , SHI must be unchanged since the last call to G10BBF.
On exit: , the upper limit actually used.
7: – INTEGERInput
On entry: , the number of points at which the estimate is calculated.
If , NS must be unchanged since the last call to G10BBF.
8: – REAL (KIND=nag_wp) arrayOutput
On exit: , for , the values of the density estimate.
9: – REAL (KIND=nag_wp) arrayOutput
On exit: , for , the points at which the estimate is calculated.
10: – INTEGERInput
On entry: if then the values of are to be calculated by this call to G10BBF, otherwise it is assumed that the values of were calculated by a previous call to this routine and the relevant information is stored in RCOMM.
11: – REAL (KIND=nag_wp) arrayCommunication Array
On entry: communication array, used to store information between calls to G10BBF.
If , RCOMM must be unchanged since the last call to G10BBF.
On exit: the last NS elements of RCOMM contain the fast Fourier transform of the weights of the discretized data, that is
, for .
12: – INTEGERInput/Output
On entry: IFAIL must be set to , . If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value is recommended. If the output of error messages is undesirable, then the value is recommended. Otherwise, because for this routine the values of the output arguments may be useful even if on exit, the recommended value is . When the value is used it is essential to test the value of IFAIL on exit.
On exit: unless the routine detects an error or a warning has been flagged (see Section 6).
6 Error Indicators and Warnings
If on entry or , explanatory error messages are output on the current error message unit (as defined by X04AAF).
Note: G10BBF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
On entry, .
On entry, . On entry at previous call, . Constraint: if , N must be unchanged since previous call.
On entry, . Constraint: or .
On entry, .
On entry, . On exit from previous call, . Constraint: if , SLO must be unchanged since previous call.
On entry, and . On entry, and . Expected values of at least and for SLO and SHI. All output values have been returned.
On entry, . On exit from previous call, . Constraint: if , SHI must be unchanged since previous call.
On entry, .
On entry, . On entry at previous call, . Constraint: if , NS must be unchanged since previous call.
G10BBF is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
G10BBF makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.
9 Further Comments
The time for computing the weights of the discretized data is of order , while the time for computing the FFT is of order , as is the time for computing the inverse of the FFT.
Data is read from a file and the density estimated. The first values are then printed.