how to estimate cdf from ksdensity pdf
Mostra commenti meno recenti
I have a quick question about ksdensity. For a given variable I derive distribution by binning into a specified number of bins, calculating the number of samples in each bin. For example, I used 10 bins to get the pdfs
To sample distributions, those pdf's are converted to cdf's, I draw random values from 0-1 so sample that cdf at bin center i. This allows to only get back the values at each bin center which for contionous variable is not what I want. Thus I then sample uniformatly from i-1 to i+1.
I was wondering if I can used ksdensity to do this as the more robust soluton. So essentially finding CDF from PDF that was estimated using Kernel Desnity?
Thank you!
Risposte (1)
Star Strider
il 14 Nov 2018
There is an option for ksdensity to return the cdf:
x = [randn(30,1); 5+randn(30,1)];
[f,xi] = ksdensity(x);
figure
plot(xi,f)
grid
title('PDF')
[f,xi] = ksdensity(x, 'Function','cdf');
figure
plot(xi,f)
grid
title('CDF')
Experiment with your own distribution. This is discontinuous, so you may need to use the interp1 function for intermediate values.
4 Commenti
jenka
il 14 Nov 2018
Star Strider
il 14 Nov 2018
My pleasure.
I am not certain that it is possible to create random numbers from an empirical distribution. Looking through the documentation, you would have to fit a specific distribution to your data with the fitdist (link) function. If that provided an acceptable approximation, you could then generate random numbers from it using the random function. I am not aware that any other option exists.
jenka
il 14 Nov 2018
Star Strider
il 14 Nov 2018
O.K. I am not certain what m and n are, and without more information, I continue to guess at the appropriate solution. I alluded (and linked) to interp1 earlier.
You can calculate the probabilities, then weight them appropriately.
Example —
rn = repelem(xi, fix(f/min(f))); % Generate Random Values
figure
histogram(rn, numel(f)) % Plot Histogram
That will reproduce the PDF of the distribution.
Experiment to get the result you want.
Categorie
Scopri di più su Exploration and Visualization in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!