`>> x = [randn(30,1); 5+randn(30,1)]; >> [f,xi] = ksdensity(x); >> sum(f) ans = 5.5376 `

I ran the `ksdensity`

function in MATLAB above. After getting the density values, I summed them up. I've got 5.5376, but I expected 1. What am I missing here? Is there any good introductory book that explains the mechanics of the kernel density estimation in line with the `ksdensity`

function?

**Contents**hide

#### Best Answer

it integrates to one, not sums to one.

`trapz(xi, f)`

should return something close to 1.

### Similar Posts:

- Solved – Best practices for density estimation of discrete & continuous random variables
- Solved – Best practices for density estimation of discrete & continuous random variables
- Solved – Calculating Hellinger Divergence from Results of Kernel Density Estimates in Matlab
- Solved – F-distribution of data in Matlab
- Solved – Manually fitting a mixture distribution in matlab