Grouping Random Numbers

This notebook represents simulated large amount of data from normal
distribution. Data are grouped into clases of equal length.

by R. Omorjan
>shortformat;
Number of raw data
>n = 500
500
Number of classes (groups)
>m = 15
15
Population mean value
>mu = 5
5
Population standard deviation
>sigma = 0.5
0.5
Random vector of data from normal distribution with given mu,sigma

(simulated sample)
>x = mu + sigma*normal([1,n]);
Sample mean and standard deviation
>mean(x), dev(x)
5.04187
0.504366
>..
Generating vector of class end-points xx and the apropriated
frequencies yy
>{xx,yy} = histo(x,m);
>xx
[ 3.77562  3.95712  4.13861  4.32011  4.50161  4.68311  4.8646  5.0461
5.2276  5.40909  5.59059  5.77209  5.95359  6.13508  6.31658  6.49808 ]
>yy
[ 5  14  24  26  54  69  59  69  58  52  30  25  9  5  1 ]
Middle class points
>xxm = (xx[1:m]+xx[2:m+1])/2
[ 3.86637  4.04787  4.22936  4.41086  4.59236  4.77385  4.95535  5.13685
5.31835  5.49984  5.68134  5.86284  6.04433  6.22583  6.40733 ]
Sample mean and standard deviation based on grouped data
>mean(xxm,yy), dev(xxm,yy)
5.03957
0.502982
Interval between groupes
>d = (max(x)-min(x))/m
0.181497
Normalized frequencies
>yyn = yy/sum(yy)/d
[ 0.0550973  0.154272  0.264467  0.286506  0.59505  0.760342  0.650148
0.760342  0.639128  0.573011  0.330584  0.275486  0.0991751  0.0550973
0.0110195 ]
Plotting and comparing the empirical distribution with theoretical
normal distribution
>clg
Bar graph (histogram)
>plot2d(xx,yyn,a=mu-3sigma,b=mu+3sigma,c=0,d=1.1max(yyn),bar=1,style="\/");
Connected meadle points of bars
>plot2d(xxm,yyn,add=1,thickness=2);
Apropriate normal distribution (area under the bars and normal
curve equal to 1)
>plot2d("qnormal(x,mu,sigma)",add=1,thickness=2,color=10);
>insimg;

Grouping Random Numbers

Using nonscaled normal distribution and function histogram (area
under the curves do not equals to 1)
>plot2d("qnormal(x,mu,sigma)*sum(yy)*d", ...
>  a=mu-3sigma,b=mu+3sigma,c=0,d=1.1max(yy),thickness=2,color=10); ...
>  plot2d(histo(x,m,<bar),>add); insimg;

Grouping Random Numbers