page_title: Density estimation
section_title: Example of density estimation
hierarchical_section_title: Density estimation / Example of density estimation
caption_attribution_description: English: Example of conditional density estimation
context_page_description: In probability and statistics,
  density estimation is the construction of an estimate, based on observed data, of an unobservable underlying probability density function. The unobservable density function is thought of as the density according to which a large population is distributed; the data are usually thought of as a random sample from that population.
  A variety of approaches to density estimation are used, including Parzen windows and a range of data clustering techniques, including vector quantization. The most basic form of density estimation is a rescaled histogram.
context_section_description: We will consider records of the incidence of diabetes. The following is quoted verbatim from the data set description:
  A population of women who were at least 21 years old, of Pima Indian heritage and living near Phoenix, Arizona,  was tested for diabetes mellitus according to World Health Organization criteria.  The data were collected by the US National Institute of Diabetes and Digestive and Kidney Diseases. We used the 532 complete records.
  In this example, we construct three density estimates for "glu" (plasma glucose concentration), one conditional on the presence of diabetes,
  the second conditional on the absence of diabetes, and the third not conditional on diabetes.
  The conditional density estimates are then used to construct the probability of diabetes conditional on "glu".
  The "glu" data were obtained from the MASS package of the R programming language. Within R, ?Pima.tr and ?Pima.te give a fuller account of the data.
  The mean of "glu" in the diabetes cases is 143.1 and the standard deviation is 31.26.
  The mean of "glu" in the non-diabetes cases is 110.0 and the standard deviation is 24.29.
  From this we see that, in this data set, diabetes cases are associated with greater levels of "glu".
  This will be made clearer by plots of the estimated density functions.
  The first figure shows density estimates of p(glu | diabetes=1), p(glu | diabetes=0), and p(glu).
  The density estimates are kernel density estimates using a Gaussian kernel. That is, a Gaussian density function is placed at each data point, and the sum of the density functions is computed over the range of the data.
  From the density of "glu" conditional on diabetes, we can obtain the probability of diabetes conditional on "glu" via Bayes' rule. For brevity, "diabetes" is abbreviated "db." in this formula.
  The second figure shows the estimated posterior probability p(diabetes=1 | glu). From these data, it appears that an increased level of "glu" is associated with diabetes.
caption: Estimated probability of p (diabetes=1 | glu)
exif: {}