# Statistics console The quick start of Atlas Plot Pro, and the project of its [tutorial](https://youseful.software/delphi/atlas-plot-pro.html#tutorial). A console program that runs every function of `TAtlasStats` on small data sets whose answers can be worked out by hand, then draws a heat map and a box plot into files without creating a window: - quantiles, mean and sample standard deviation of 1..10 given in shuffled order; - box statistics of 1..9 plus 40: quartiles, whiskers at 1.5 IQR, one outlier; - a four-bin histogram with half-open bins and a closed last bin, `BinOf`, and Sturges' rule when the bin count is 0; - Pearson correlation, an exact quadratic recovered by `PolynomialFit` (also outside the data) and the low R squared of a straight line through the same points; - exponential smoothing with alpha 0.5; - a fit that `EAtlasPlotError` rejects because two points cannot fix a parabola; - `TAtlasHeatMap` with an empty (NaN) cell and a fixed 50..100 scale saved as `heatmap.png`, and `TAtlasBoxPlot` with two services saved as `boxplot.svg`. Every result is compared with the expected value; a mismatch raises and the exit code is 1. ## Build and run Open `StatisticsConsole.dpr` in Delphi 13; the IDE creates the project file. Add the Atlas Plot Pro `src` folder and the Atlas Plot `src` folder to the project's search path, then build and run for Win32 or Win64. No packages need to be installed. The program needs no input. It checks its own results and stops with an error if any of them differs from the output below. ## Expected output ``` Quantiles of 1..10 in shuffled order Q1 3.25 median 5.50 Q3 7.75 mean 5.50 sd 3.0277 ok: first quartile interpolates between ranks 3 and 4 ok: median of an even count is the middle pair average ok: mean and sample standard deviation Box statistics of 1..9 and one slow value, 40 box 3.25..7.75 whiskers 1..9 1 outlier(s) ok: quartiles ok: whiskers stop at the last value within 1.5 IQR ok: 40 is the only outlier Histogram of 1 2 2 3 3 3 4 4 5 in four bins [1, 2): 1 [2, 3): 2 [3, 4): 3 [4, 5]: 3 ok: bins are half open, the last one closed ok: BinOf finds the bin; outside the range is -1 ok: Bins = 0 applies Sturges' rule: ceil(log2 9) + 1 = 5 Correlation and least-squares fits r = 0.80 ok: Pearson r of a partly ordered pair is 0.8 quadratic: degree 2, R squared 1.0000, value at 10 = 171.0000 ok: the parabola is recovered, also outside the data straight line: R squared 0.3047 ok: a line explains less than a third of a parabola Exponential smoothing of 10 20 20 0 with alpha 0.5 10.00 15.00 17.50 8.75 ok: each value moves halfway towards the input Invalid input raises EAtlasPlotError ok: a fit with too few distinct arguments is rejected Charts rendered without a window ok: heatmap.png written ok: NaN is an empty cell; 75 is halfway on the 50..100 scale ok: boxplot.svg names both categories ok: the chart keeps the statistics of each sample All results verified. ``` Next to the executable you find `heatmap.png` (480 × 300: three node rows, four hour columns, white-to-black cells with their percentages in contrasting text, a light grey empty cell for node-b at 06 and a 50..100 colour scale on the right) and `boxplot.svg` (two boxes; the 60 ms Gateway request is drawn as an outlier circle). ## What to change first - Put your own measurements into the arrays and replace the `Expect` calls with `Writeln`; every function raises `EAtlasPlotError` on NaN, infinite or empty input, so wrap them in `try ... except on EAtlasPlotError` when the data comes from outside. - Change the degree passed to `PolynomialFit` (1 to 6) and compare `RSquared`. - The heat map stores percentages (91, not 0.91) because `ValueFormat` is a `FormatFloat` mask, and `FormatFloat` prints a `%` sign as it is without multiplying by 100. - Change the extensions passed to `SaveToFile`: `.png`, `.bmp`, `.emf` and `.svg` are supported.