This repository has been archived on 2021-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
scientificComputing/statistics/code/cumulative.m

19 lines
654 B
Matlab

x = randn(200, 1); % generate some data
xs = sort(x); % sort the data
cdf = [1:length(x)]/length(x); % cumulative
plot(xs, cdf);
hold on;
dx = 0.01;
xx = [-4:dx:4]; % x-values for Gaussian pdf
gauss = exp(-0.5*xx.^2)/sqrt(2.0*pi); % Gaussian pdf
gausscdf = cumsum(gauss)*dx;
plot(xx, gausscdf);
hold off;
printf('data : probability of x<-1: %.2f\n', cdf(xs<-1.0)(end))
printf('gauss: probability of x<-1: %.2f\n', gausscdf(xx<-1.0)(end))
printf('\n')
printf('data : 5%% percentile at %.2f\n', xs(cdf<0.05)(end))
printf('gauss: 5%% percentile at %.2f\n', xx(gausscdf<0.05)(end))