how to estimate cdf from ksdensity pdf
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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!
0 commentaires
Réponses (1)
Star Strider
le 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 commentaires
Star Strider
le 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.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!