Module Sample.KDE

module KDE: sig .. end

type bandwidth = 
| Silverman (*Use rule-of-thumb for choosing the bandwidth. It defaults to 0.9 * min(SD, IQR / 1.34) * n^-0.2.*)
| Scott (*Same as Silverman, but with a factor, equal to 1.06.*)
Bandwidth selection rules.
type kernel = 
| Gaussian
val estimate_pdf : ?kernel:kernel ->
?bandwidth:bandwidth ->
?n_points:int -> float array -> float array * float array
O(n * points) Simple kernel density estimator. Returns an array of uniformly spaced points from the sample range at which the density function was estimated, and the estimates at these points.

Example

        open Pareto
        let open Distributions.Normal in
        let vs = sample ~size:100 standard in
        let (points, pdf) = Sample.KDE.estimate_pdf ~points:10 vs in begin
          (* Output an ASCII density plot. *)
          Array.iteri (fun i d ->
              let count = int_of_float (d *. 20.) in
              printf "%9.5f " points.(i);
              for i = 0 to count do
                print_char (if i = count then '.' else ' ');
              done;

              print_newline ();
            ) pdf
        end
      

References

  1. B.W. Silverman, "Density Estimation for Statistics and Data Analysis", Vol. 26, Monographs on Statistics and Applied Probability, Chapman and Hall, London, 1986.