Jump to content

Density estimation: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Inserted two missing indefinite articles.
(19 intermediate revisions by 15 users not shown)
Line 1: Line 1:
{{Short description|Estimate of an unobservable underlying probability density function}}
{{for|the signal processing concept|spectral density estimation}}
{{for|the signal processing concept|spectral density estimation}}
{{more citations needed|date=August 2012}}
{{more citations needed|date=August 2012}}


[[File:KernelDensityGaussianAnimated.gif|thumb|350px|Demonstration of density estimation using [[Kernel density estimation]]: The true density is mixture of two Gaussians centered around 0 and 3, shown with solid blue curve. In each frame, 100 samples are generated from the distribution, shown in red. Centered on each sample, a Gaussian kernel is drawn in gray. Averaging the Gaussians yields the density estimate shown in the dashed black curve.]]
[[File:KernelDensityGaussianAnimated.gif|thumb|350px|Demonstration of density estimation using [[Kernel density estimation]]: The true density is a mixture of two Gaussians centered around 0 and 3, shown with a solid blue curve. In each frame, 100 samples are generated from the distribution, shown in red. Centered on each sample, a Gaussian kernel is drawn in gray. Averaging the Gaussians yields the density estimate shown in the dashed black curve.]]


In [[statistics]], '''probability density estimation''' or simply '''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.<ref>Alberto Bernacchia, Simone Pigolotti, Self-Consistent Method for Density Estimation, Journal of the Royal Statistical Society Series B: Statistical Methodology, Volume 73, Issue 3, June 2011, Pages 407–422, https://doi.org/10.1111/j.1467-9868.2011.00772.x</ref>
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 window]]s and a range of [[data clustering]] techniques, including [[vector quantization]]. The most basic form of density estimation is a rescaled [[histogram]].
A variety of approaches to density estimation are used, including [[Parzen window]]s and a range of [[data clustering]] techniques, including [[vector quantization]]. The most basic form of density estimation is a rescaled [[histogram]].


== Example of density estimation ==
== Example ==
[[File:P glu given diabetes.png|thumb|right|360px|Estimated density of ''p'' (glu &#124; diabetes=1) (red), ''p''&nbsp;(glu &#124; diabetes=0) (blue), and ''p''&nbsp;(glu) (black)]]
[[File:P glu given diabetes.png|thumb|right|360px|Estimated density of ''p'' (glu &#124; diabetes=1) (red), ''p''&nbsp;(glu &#124; diabetes=0) (blue), and ''p''&nbsp;(glu) (black)]]
[[File:P diabetes given glu.png|thumb|rightr|360px|Estimated probability of ''p''(diabetes=1 &#124; glu)]]
[[File:P diabetes given glu.png|thumb|right|360px|Estimated probability of ''p''(diabetes=1 &#124; glu)]]
[[File:Glu opt.png|thumb|right|360px|Estimated probability of ''p''&nbsp;(diabetes=1 &#124; glu)]]
[[File:Glu opt.png|thumb|right|360px|Estimated probability of ''p''&nbsp;(diabetes=1 &#124; glu)]]


Line 22: Line 22:
The conditional density estimates are then used to construct the probability of diabetes conditional on "glu".
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<ref>{{cite web|url=https://cran.r-project.org/web/packages/MASS/index.html|title=Support Functions and Datasets for Venables and Ripley's MASS}}</ref> of the [[R programming language]]. Within R, <tt>?Pima.tr</tt> and <tt>?Pima.te</tt> give a fuller account of the data.
The "glu" data were obtained from the MASS package<ref>{{cite web|url=https://cran.r-project.org/web/packages/MASS/index.html|title=Support Functions and Datasets for Venables and Ripley's MASS}}</ref> of the [[R programming language]]. Within R, <code>?Pima.tr</code> and <code>?Pima.te</code> 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 diabetes cases is 143.1 and the standard deviation is 31.26.
Line 40: Line 40:
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.
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.


=== Script for example ===
== Application and purpose ==
A very natural use of density estimates is in the informal investigation of the properties of a given set of data. Density estimates can give a valuable indication of such features as skewness and multimodality in the data. In some cases they will yield conclusions that may then be regarded as self-evidently true, while in others all they will do is to point the way to further analysis and/or data collection.<ref>{{Cite book|title=Density Estimation for Statistics and Data Analysis|last=Silverman|first=B. W.|publisher=Chapman and Hall.|year=1986|isbn=978-0412246203|url=https://archive.org/details/densityestimatio00silv_0}}</ref>
The following R commands will create the figures shown above. These commands can be entered at the command prompt by using cut and paste.

<source lang="rsplus">
library(MASS)
data(Pima.tr)
data(Pima.te)

Pima <- rbind (Pima.tr, Pima.te)
glu <- Pima[, 'glu']

d0 <- Pima[, 'type'] == 'No'
d1 <- Pima[, 'type'] == 'Yes'
base.rate.d1 <- sum(d1) / (sum(d1) + sum(d0))

glu.density <- density (glu)
glu.d0.density <- density (glu[d0])
glu.d1.density <- density (glu[d1])

glu.d0.f <- approxfun(glu.d0.density$x, glu.d0.density$y)
glu.d1.f <- approxfun(glu.d1.density$x, glu.d1.density$y)

p.d.given.glu <- function(glu, base.rate.d1)
{
p1 <- glu.d1.f(glu) * base.rate.d1
p0 <- glu.d0.f(glu) * (1 - base.rate.d1)
p1 / (p0 + p1)
}

x <- 1:250
y <- p.d.given.glu (x, base.rate.d1)
plot(x, y, type='l', col='red', xlab='glu', ylab='estimated p(diabetes|glu)')

plot(density(glu[d0]), col='blue', xlab='glu', ylab='estimate p(glu),
p(glu|diabetes), p(glu|not diabetes)', main=NA)
lines(density(glu[d1]), col='red')
</source>

Note that the above conditional density estimator uses bandwidths that are optimal for unconditional densities. Alternatively, one could use the method of Hall, Racine and Li (2004)<ref name=hallracineli/> and the R np package<ref>{{cite web|url=https://cran.r-project.org/web/packages/np/index.html|title=The np package - An R package that provides a variety of nonparametric and semiparametric kernel methods that seamlessly handle a mix of continuous, unordered, and ordered factor data types}}</ref>
for automatic (data-driven) bandwidth selection that is
optimal for conditional density estimates; see the np vignette<ref>{{cite web|url=https://cran.r-project.org/web/packages/np/vignettes/np.pdf|title=The np Package|author1=Tristen Hayfield |author2=Jeffrey S. Racine }}</ref> for an introduction to the np package. The following R commands use the <code>npcdens()</code> function to deliver optimal smoothing. Note that the response "Yes"/"No" is a factor.
<source lang="rsplus">
library(np)

fy.x <- npcdens(type~glu, nmulti=1, data=Pima)

Pima.eval <- data.frame(type=factor("Yes"),
glu=seq(min(Pima$glu), max(Pima$glu), length=250))
plot(x, y, type='l', lty=2, col='red', xlab='glu',
ylab='estimated p(diabetes|glu)')
lines(Pima.eval$glu, predict(fy.x, newdata=Pima.eval), col="blue")
legend(0, 1, c("Unconditional bandwidth", "Conditional bandwidth"),
col=c("red", "blue"), lty=c(2, 1))
</source>

The third figure uses optimal smoothing via the method of Hall, Racine, and Li<ref name=hallracineli>{{cite journal|author1=Peter Hall |author2=Jeffrey S. Racine |author3=Qi Li |title=Cross-Validation and the Estimation of Conditional Probability Densities|journal=Journal of the American Statistical Association|volume=99|issue=468|pages=1015–1026|year=2004|url=http://econpapers.repec.org/article/besjnlasa/v_3a99_3ay_3a2004_3ap_3a1015-1026.htm |doi=10.1198/016214504000000548|citeseerx=10.1.1.217.93 }}</ref> indicating that the unconditional density bandwidth used in the second figure above yields a conditional density estimate that may be somewhat undersmoothed.

== Application and Purpose ==
A very natural use of density estimates is in the informal investigation of the properties of a given set of data. Density estimates can give valuable indication of such features as skewness and multimodality in the data. In some cases they will yield conclusions that may then be regarded as self-evidently true, while in others all they will do is to point the way to further analysis and/or data collection.<ref>{{Cite book|title=Density Estimation for Statistics and Data Analysis|last=Silverman|first=B. W.|publisher=Chapman and Hall.|year=1986|isbn=978-0412246203|location=|pages=|url=https://archive.org/details/densityestimatio00silv_0}}</ref>


[[File:Gumbel distribtion.png|thumb|300px|Histogram and density function for a Gumbel distribution <ref>[https://www.waterlog.info/cumfreq.htm A calculator for probability distributions and density functions]</ref>]]
[[File:Gumbel distribtion.png|thumb|300px|Histogram and density function for a Gumbel distribution <ref>[https://www.waterlog.info/cumfreq.htm A calculator for probability distributions and density functions]</ref>]]


An important aspect of statistics, often neglected nowadays, is the presentation of data back to the client in order to provide explanation and illustration of conclusions that may possibly have been obtained by other means. Density estimates are ideal for this purpose, for the simple reason that they are fairly easily comprehensible to non-mathematicians.
An important aspect of statistics is often the presentation of data back to the client in order to provide explanation and illustration of conclusions that may possibly have been obtained by other means. Density estimates are ideal for this purpose, for the simple reason that they are fairly easily comprehensible to non-mathematicians.


More examples illustrating the use of density estimates for exploratory and presentational purposes, including the important case of bivariate data.<ref>Geof H., Givens (2013). Computational Statistics. Wiley. p. 330. {{ISBN|978-0-470-53331-4}}.</ref>
More examples illustrating the use of density estimates for exploratory and presentational purposes, including the important case of bivariate data.<ref>Geof H., Givens (2013). Computational Statistics. Wiley. p. 330. {{ISBN|978-0-470-53331-4}}.</ref>


Density estimation is also frequently used in [[anomaly detection]] or [[novelty detection]]:<ref>{{cite journal|last1=Pimentel|first1=Marco A.F.|last2=Clifton|first2=David A.|last3=Clifton|first3=Lei|last4=Tarassenko|first4=Lionel|title=A review of novelty detection|journal=Signal Processing|date=2 January 2014|volume= 99|issue=June 2014|pages=215–249|url=|doi=10.1016/j.sigpro.2013.12.026}}</ref> if an observation lies in a very low-density region, it is likely to be an anomaly or a novelty.
Density estimation is also frequently used in [[anomaly detection]] or [[novelty detection]]:<ref>{{cite journal|last1=Pimentel|first1=Marco A.F.|last2=Clifton|first2=David A.|last3=Clifton|first3=Lei|last4=Tarassenko|first4=Lionel|title=A review of novelty detection|journal=Signal Processing|date=2 January 2014|volume= 99|issue=June 2014|pages=215–249|doi=10.1016/j.sigpro.2013.12.026}}</ref> if an observation lies in a very low-density region, it is likely to be an anomaly or a novelty.


* In [[hydrology]] the [[histogram]] and estimated density function of rainfall and river discharge data, analysed with a [[probability distribution]], are used to gain insight in their behaviour and frequency of occurrence.<ref>[https://www.waterlog.info/density.htm An illustration of histograms and probability density functions]</ref> An example is shown in the blue figure.
* In [[hydrology]] the [[histogram]] and estimated density function of rainfall and river discharge data, analysed with a [[probability distribution]], are used to gain insight in their behaviour and frequency of occurrence.<ref>[https://www.waterlog.info/density.htm An illustration of histograms and probability density functions]</ref> An example is shown in the blue figure.

==Kernel density estimation==
{{excerpt|Kernel density estimation}}


== See also ==
== See also ==
Line 120: Line 65:
* [[Generative model]]
* [[Generative model]]
* [[Order statistic#Application: Non-parametric Density Estimation|Application of Order Statistics: Non-parametric Density Estimation]]
* [[Order statistic#Application: Non-parametric Density Estimation|Application of Order Statistics: Non-parametric Density Estimation]]
* [[Probability distribution fitting]]


== References ==
== References ==
{{reflist}}
{{reflist}}
'''Sources'''
'''Sources'''
* {{cite book|author=Brian D. Ripley|title=Pattern Recognition and Neural Networks|place=Cambridge|publisher=Cambridge University Press|year=1996|url=https://books.google.com/books/about/Pattern_Recognition_and_Neural_Networks.html?id=2SzT2p8vP1oC|isbn=978-0521460866}}
* {{cite book|author=Brian D. Ripley|title=Pattern Recognition and Neural Networks|place=Cambridge|publisher=Cambridge University Press|year=1996|url=https://books.google.com/books?id=2SzT2p8vP1oC|isbn=978-0521460866}}
* [[Trevor Hastie]], [[Robert Tibshirani]], and Jerome Friedman. ''The Elements of Statistical Learning''. New York: Springer, 2001. {{isbn|0-387-95284-5}}. ''(See Chapter 6.)''
* [[Trevor Hastie]], [[Robert Tibshirani]], and Jerome Friedman. ''The Elements of Statistical Learning''. New York: Springer, 2001. {{isbn|0-387-95284-5}}. ''(See Chapter 6.)''
* Qi Li and Jeffrey S. Racine. ''Nonparametric Econometrics: Theory and Practice''. Princeton University Press, 2007, {{isbn|0-691-12161-3}}. ''(See Chapter 1.)''
* Qi Li and Jeffrey S. Racine. ''Nonparametric Econometrics: Theory and Practice''. Princeton University Press, 2007, {{isbn|0-691-12161-3}}. ''(See Chapter 1.)''
Line 138: Line 84:
{{Statistics|inference}}
{{Statistics|inference}}


[[Category:Estimation of densities]]
[[Category:Estimation of densities|*]]
[[Category:Nonparametric statistics]]
[[Category:Nonparametric statistics]]

Revision as of 15:40, 18 April 2024

Demonstration of density estimation using Kernel density estimation: The true density is a mixture of two Gaussians centered around 0 and 3, shown with a solid blue curve. In each frame, 100 samples are generated from the distribution, shown in red. Centered on each sample, a Gaussian kernel is drawn in gray. Averaging the Gaussians yields the density estimate shown in the dashed black curve.

In statistics, probability density estimation or simply 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.[1]

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.

Example

Estimated density of p (glu | diabetes=1) (red), p (glu | diabetes=0) (blue), and p (glu) (black)
Estimated probability of p(diabetes=1 | glu)
Estimated probability of p (diabetes=1 | glu)

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.[2][3]

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[4] 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.

Application and purpose

A very natural use of density estimates is in the informal investigation of the properties of a given set of data. Density estimates can give a valuable indication of such features as skewness and multimodality in the data. In some cases they will yield conclusions that may then be regarded as self-evidently true, while in others all they will do is to point the way to further analysis and/or data collection.[5]

Histogram and density function for a Gumbel distribution [6]

An important aspect of statistics is often the presentation of data back to the client in order to provide explanation and illustration of conclusions that may possibly have been obtained by other means. Density estimates are ideal for this purpose, for the simple reason that they are fairly easily comprehensible to non-mathematicians.

More examples illustrating the use of density estimates for exploratory and presentational purposes, including the important case of bivariate data.[7]

Density estimation is also frequently used in anomaly detection or novelty detection:[8] if an observation lies in a very low-density region, it is likely to be an anomaly or a novelty.

  • In hydrology the histogram and estimated density function of rainfall and river discharge data, analysed with a probability distribution, are used to gain insight in their behaviour and frequency of occurrence.[9] An example is shown in the blue figure.

Kernel density estimation

Kernel density estimation of 100 normally distributed random numbers using different smoothing bandwidths.
In statistics, kernel density estimation (KDE) is the application of kernel smoothing for probability density estimation, i.e., a non-parametric method to estimate the probability density function of a random variable based on kernels as weights. KDE answers a fundamental data smoothing problem where inferences about the population are made based on a finite data sample. In some fields such as signal processing and econometrics it is also termed the Parzen–Rosenblatt window method, after Emanuel Parzen and Murray Rosenblatt, who are usually credited with independently creating it in its current form.[10][11] One of the famous applications of kernel density estimation is in estimating the class-conditional marginal densities of data when using a naive Bayes classifier, which can improve its prediction accuracy.[12]

See also

References

  1. ^ Alberto Bernacchia, Simone Pigolotti, Self-Consistent Method for Density Estimation, Journal of the Royal Statistical Society Series B: Statistical Methodology, Volume 73, Issue 3, June 2011, Pages 407–422, https://doi.org/10.1111/j.1467-9868.2011.00772.x
  2. ^ "Diabetes in Pima Indian Women - R documentation".
  3. ^ Smith, J. W., Everhart, J. E., Dickson, W. C., Knowler, W. C. and Johannes, R. S. (1988). R. A. Greenes (ed.). "Using the ADAP learning algorithm to forecast the onset of diabetes mellitus". Proceedings of the Symposium on Computer Applications in Medical Care (Washington, 1988). Los Alamitos, CA: 261–265. PMC 2245318.{{cite journal}}: CS1 maint: multiple names: authors list (link)
  4. ^ "Support Functions and Datasets for Venables and Ripley's MASS".
  5. ^ Silverman, B. W. (1986). Density Estimation for Statistics and Data Analysis. Chapman and Hall. ISBN 978-0412246203.
  6. ^ A calculator for probability distributions and density functions
  7. ^ Geof H., Givens (2013). Computational Statistics. Wiley. p. 330. ISBN 978-0-470-53331-4.
  8. ^ Pimentel, Marco A.F.; Clifton, David A.; Clifton, Lei; Tarassenko, Lionel (2 January 2014). "A review of novelty detection". Signal Processing. 99 (June 2014): 215–249. doi:10.1016/j.sigpro.2013.12.026.
  9. ^ An illustration of histograms and probability density functions
  10. ^ Rosenblatt, M. (1956). "Remarks on Some Nonparametric Estimates of a Density Function". The Annals of Mathematical Statistics. 27 (3): 832–837. doi:10.1214/aoms/1177728190.
  11. ^ Parzen, E. (1962). "On Estimation of a Probability Density Function and Mode". The Annals of Mathematical Statistics. 33 (3): 1065–1076. doi:10.1214/aoms/1177704472. JSTOR 2237880.
  12. ^ Hastie, Trevor; Tibshirani, Robert; Friedman, Jerome H. (2001). The Elements of Statistical Learning : Data Mining, Inference, and Prediction : with 200 full-color illustrations. New York: Springer. ISBN 0-387-95284-5. OCLC 46809224.

Sources