title: Gaussian kernel density estimation in R
body: <p>I am having trouble understanding how to implement a Gaussian kernel density estimation of the following dataset in R. I appreciate if you can help me understand the mechanism of how to do it. I am currently trying to get a formula for the bell shaped curves at the bottom of the following picture. As you can see there is one bell shaped curve for each data point. (Note the picture does not represent the data I am using.)</p>
  <p><a href="https://i.stack.imgur.com/8DNEw.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8DNEw.gif" alt="enter image description here" /></a></p>
  <p>This is my data:</p>
  <p><code>x&lt;-c(4.09, 4.46, 4.61, 4.30, 4.03, 5.22, 4.21, 4.07, 4.02, 4.58, 4.66, 4.05, 4.23, 5.51, 4.03, 4.72, 4.47, 4.50, 5.80, 4.30, 4.09, 4.78, 4.18, 4.45, 4.40, 5.60, 4.37, 4.42, 4.88, 4.20, 4.45, 4.10, 4.43, 4.58, 4.40, 4.38)</code>
  (x has 36 elements)</p>
  <p>This is the kernel density estimator:</p>
  <p><a href="https://i.stack.imgur.com/Oq2Vk.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Oq2Vk.gif" alt="enter image description here" /></a></p>
  <p>(If you can't see the image, it's from this page <a href="http://sfb649.wiwi.hu-berlin.de/fedc_homepage/xplore/tutorials/xlghtmlnode33.html" rel="nofollow noreferrer">http://sfb649.wiwi.hu-berlin.de/fedc_homepage/xplore/tutorials/xlghtmlnode33.html</a>)</p>
  <p>where K(u)=
  <a href="https://i.stack.imgur.com/vSmRQ.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vSmRQ.gif" alt="enter image description here" /></a></p>
  <p>is the Gaussian kernel function and h=.1516 is the bandwidth selected by Scott.</p>
  <p>So, plugging in we get f hat (x) = 1/(36*.1516) (1/sqrt(2pi))[e^(-1/2 ((4.09-x)/.1516)^2 + e^(-1/2 ((4.46-x)/.1516)^2 + ... + e^(-1/2 ((4.38-x)/.1516)^2]</p>
  <p>Ok. So we have a function of x. But how do we get the equation of each of the bell shaped curves in the above diagram? If we plug in, for example, 4.09, into f hat (x) we get a number, not a curve/function/distribution. Can someone help me understand the procedure to find the equation for the bell shaped curve/kernel density estimate?</p>