How to get kse or ksdensity as definable or anonymous function of x

8 views (last 30 days)
From what I can tell both kse and ksdensity are used to get a smoothly defined probability distribution function from vector of finite data. Is there a way to get MATLAB to produce the actual function as the output instead of finite set of input/output vectors? I need to be able to call on the kernal density estimator at an arbitrary point in my domain and I'd prefer not to just interpolate between the values provided. Is there a functionality of either of these two that gives the true function/estimator or do I need to write my own code to accomplish this?
  3 Comments
David Gillcrist
David Gillcrist on 1 Oct 2024
Either I have a misunderstanding about kernal density estimation, or I don't quite understand your response. Is it not the case that the result of producing a KSE (at least using a Gaussian smoothing function which is the default for kse) is a smoothly defined function?
Torsten
Torsten on 1 Oct 2024
Edited: Torsten on 1 Oct 2024
You can define the function as
f = @(y) ksdensity(x,y)
e.g.
rng('default') % For reproducibility
x = [randn(30,1); 5+randn(30,1)];
f = @(y)ksdensity(x,y);
fy = f(1.34)
fy = 0.1094
Of course, the density function will always be recomputed this way.

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!