matlab - Fitting an empirical CDF curve to find exact vaue -


i trying find exact value of number using empirical cdf. what's best way exact value? can use fitting tool , estimate using fitted function?

[f,x] = ecdf(samples); 

i.e how find best function fits empirical cdf exact cdf of number want?

these samples:

enter image description here

you can approximate value of f(x) finding shape (σ) , location (μ) parameters best fit curve in least squares sense.

here's "example" set of noisy "test data" normal distribution (similar sampled data):

>> % ytest = f(xtest, mutest, sigtest)  % sample test data >> xtest = linspace(-10, 10, 100);  % independent variable linearly spaced >> mutest = rand(1, 1) - 0.5;  % random location parameter >> sigtest = 1 + rand(1, 1);  % random shape parameter >> ytest = normcdf(x, mutest, sigtest) + rand(1, 100) / 10;  % distribution mutest =     0.2803 sigtest =     1.6518 

now can use fminsearch find shape , location parameters assuming normal distribution. need provide objective function want fminsearch minimize create an anonymous function norm of residuals between ideal normal cumulative distribution function , test data. function has 2-dimensions, [μ, σ] pass vector. need provide fminsearch initial guess.

>> % objective function normal distribution >> % mu(1) = location parameter (mean) >> % mu(2) = shape parameter (standard deviation) >> obj_func = @(mu)norm(normcdf(xtest, mu(1), mu(2)) - ytest) >> mu0 = [0, 1];  % initial guesses mean , stdev >> mu = fminsearch(obj_func, mu0); >> sigma = mu(2);  % best fit standard deviation >> mu = mu(1)  % best fit mean mu =    -0.0386 sigma     1.7399 

now can predict cdf in empirical data using x, μ , σ using normcdf function

>> y = normcdf(x, mu, sigma) 

enter image description here

matlab offers many types of probability distributions. if don't know type of distribution data has, recommend using weibull, has generic form - replace normcdf wblcdf.

>> % objective function weibull distribution >> % mu(1) = location parameter (mean) >> % mu(2) = shape parameter (standard deviation) >> obj_func = @(mu)norm(wblcdf(xtest, mu(1), mu(2)) - ytest) >> mu0 = [0, 1];  % initial guesses mean , stdev >> mu = fminsearch(obj_func, mu0); >> sigma = mu(2);  % best fit standard deviation >> mu = mu(1)  % best fit mean >> y = wblcdf(x, mu, sigma) 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

Sound is not coming out while implementing Text-to-speech in Android activity -