-------------------------------------------------------------------------------
help for akdensity                                            Philippe Van Kerm
-------------------------------------------------------------------------------

Title

akdensity -- Adaptive kernel density estimation

Syntax

akdensity varname [weight] [if exp] [in range] [, options ]

akdensity0 varname [weight] [if exp] [in range] , bwidth(#|varname) generate(newvar) at(var_x) [ options ]

options Description ------------------------------------------------------------------------- akdensity: noadaptive de-activate adaptive estimation stdbands(#) request estimation of variability bands cdf(newvar) request estimation of kernel smoothed CDF kdensity_options any kdensity option

akdensity0: bwidth(#|varname) half-width of kernel (scalar or variable) generate(newvar) store the density estimate in newvar at(var_x) estimate density using the values specified by var_x stdbands(#) request estimation of variability bands cdf(newvar) request estimation of kernel smoothed CDF lambda(newvar) generate local bandwidth factors kernel(kernel) specify kernel function double requests double precision -------------------------------------------------------------------------

kdensity_options Description ------------------------------------------------------------------------- kernel(kernel) specify kernel function; default is kernel(epanechnikov) bwidth(#) half-width of kernel generate(newvar_x newvar_d) store the estimation points in newvar_x and the density estimate in newvar_d n(#) estimate density using # points; default is min(N, 50) at(var_x) estimate density using the values specified by var_x nograph suppress graph cline_options affect rendition of the plotted kernel density estimate normal add normal density to the graph normopts(cline_options) affect rendition of normal density student(#) add Student's t density with # degrees of freedom to the graph stopts(cline_options) affect rendition of the Student's t density addplot(plot) add other plots to the generated graph twoway_options any options other than by() documented in [G] twoway_options -------------------------------------------------------------------------

kernel Description ------------------------------------------------------------------------- epanechnikov Epanechnikov kernel function; the default epan2 alternative Epanechnikov kernel function gaussian Gaussian kernel function -------------------------------------------------------------------------

fweight and aweight are allowed; see help weights.

Description

akdensity produces density estimates using adaptive kernel estimation methods. The density estimates can be plotted and saved in new variables. akdensity0 is the engine used by akdensity to obtain the estimates. These modules also provide variability bands (standard error bands).

The syntax of akdensity mimics the syntax of the official kdensity that uses fixed kernel estimation methods.

akdensity can also be requested to produce kernel smoothed cumulative distribution function estimates.

See Van Kerm (2003, 2010) for detailed description.

Options

Most options for akdensity are the same as for kdensity (see [R] kdensity). The specific options are the following.

+-----------+ ----+ akdensity +--------------------------------------------------------

stdbands(#) requests estimation of variability bands, and specifies the number of standard errors above and below the estimates to be used (a positive number). If the generate option is specified, the estimated bands are stored in two new variables: newvard_up and newvard_lo.

noadaptive can be specified to obtain the standard fixed bandwidth kernel density estimate. The resulting density is exactly as produced by kdensity. This may be used to obtain the variability bands around the fixed kernel density estimates, or kernel smoothed CDF estimation with fixed bandwidth.

cdf(newvarname) requests estimation of a kernel smoothed cumulative distribution function in addition to the density function. Both function estimates are based on identical (adaptive) bandwidth and kernel function specifications. CDF estimates for each point on the grid specified by at or n options are stored in newvarname. Variability bands are also produced if stdbands is specified.

+------------+ ----+ akdensity0 +-------------------------------------------------------

at, bwidth and generate are not optional. Most options are as in kdensity. Note, however, that the bwidth option can here be either a scalar or a variable name containing observation-specific bandwidths. Also, generate must specify a single new variable name to store the estimated value of the density function at the grid points.

lambda(newvarname) requests the estimation of local bandwidth factors based on the estimated density function, and specifies a new variable name where these values are to be stored.

cdf(newvarname) requests estimation of the kernel smoothed cumulative distribution function (see akdensity option descriptions).

double requests the use of double precision in the estimation of the density functions and standard error bands.

Examples

. akdensity length

. akdensity length, bw(5) stdbands(2) gen(x fx)

. akdensity length, gen(x fx) cdf(cdfx)

References

Van Kerm, P. 2003. Adaptive kernel density estimation. The Stata Journal 3(2): 148-156.

Van Kerm, P. 2010. Kernel smoothed CDF estimation with akdensity. CEPS/INSTEAD, Differdange, Luxembourg;

Acknowledgements

A bug report from Ben Jann lead to a major fix. Financial support from the World Bank Knowledge for Change Program (KCP II - TF094570) for developing the cdf option for smoothed cumulative distribution function estimation is gratefully acknowledged, as well as support from the Luxembourg FNR (FNR/06/15/08) for extension of this work.

Also see

Manual: [R] kdensity STB: snp6 (STB-16) Online: help for kdensity, graph and hist, and help for adgakern, adgaker2, asciker, bsciker, kdens, varwiker and varwike2 if installed