Frequency Table Generation
Grouping numerical observations into class intervals and calculating absolute, relative and cumulative frequencies using Sturges’ rule and a 120-observation dataset.
Purpose of a frequency distribution
A frequency table summarizes numerical observations by their distinct values or by class intervals. Köker Frequency Table 1.0 is a C# application that produces grouped frequency, relative-frequency, and cumulative-frequency tables from numerical observations entered by the user. Sample size, minimum, maximum, range, class count, class width, and class midpoints are computed as successive parts of the same statistical procedure.
The class count can be entered directly or estimated using Sturges' rule. Two-decimal rounding is available, and a sample dataset containing 120 observations demonstrates interval construction and the resulting distribution. The procedure comprises data acquisition, calculation of descriptive quantities, class construction, counting, and cumulative aggregation.
Mathematical definitions
Let X = (x₁, x₂, …, xₙ) be a dataset containing n observations. Let x_min and x_max denote its extrema and R = x_max − x_min its range. A grouped frequency distribution divides the data domain into k class intervals. Each interval has a lower boundary, an upper boundary, a midpoint, an absolute frequency, and a relative frequency.
n : number of observations
k : number of classes
R : x_max − x_min
h : class width
f_i : count in class i
p_i : f_i / n
m_i : midpoint of class i
F_j : Σ(i=1..j) f_i
P_j : F_j / n
G_j : n − F_jThe fundamental counting identities are Σ f_i = n and Σ p_i = 1. The cumulative frequency is the number of observations at or below the threshold represented by the corresponding completed classes. Taking F₀ = 0, the final ascending cumulative count is Fₖ = n. At the same threshold, the complementary count is G_j = n − F_j.
When classes have equal width, class frequencies can be compared directly. When widths differ, density histograms use the height f_i / (n h_i), so that each bar's area represents the class's relative frequency.
Selecting the class count
Sturges' rule
Sturges' rule relates the approximate number of classes to the logarithm of the sample size:
k ≈ 1 + log₂(n)
k ≈ 1 + 3.321928 × log₁₀(n)The application's automatic calculation uses a base-10 logarithm with coefficient 3.3 and takes the integer part of the positive result. A dataset of n = 120 observations consequently produces k = 7. The class count can alternatively be specified by the user. Both choices feed the same subsequent counting procedure.
The class count controls the resolution at which a distribution is presented. Fewer classes aggregate nearby observations into broader intervals, whereas more classes expose local concentrations. Sturges' rule supplies a reproducible starting point for this decision.
Scott and Freedman–Diaconis widths
Two alternative statistical rules for histogram width are:
Scott: h = 3.49 × s × n^(−1/3)
Freedman–Diaconis: h = 2 × IQR × n^(−1/3)Here s is the standard deviation and IQR is the interquartile range. Scott's rule uses standard deviation to represent scale, whereas Freedman–Diaconis uses the central spread of the observations. Both rules first estimate a width; an associated class count can subsequently be derived from R/h. Sturges' rule remains the class-count method in the frequency-table application.
Class boundaries and interval width
Class construction begins by computing R = x_max − x_min. After selecting k, the application calculates the width with an increment corresponding to two-decimal measurement resolution:
h = (R + 0.01) / kThe width may then be rounded to two decimal places. The lower boundary of the first class starts at the minimum observation. Every subsequent lower boundary advances by one class width. In the two-decimal boundary representation, the first upper boundary is one hundredth below the second lower boundary; subsequent upper boundaries advance by the same width.
An alternative mathematical representation defines internal classes as half-open intervals [a_i, a_{i+1}) and includes the largest observation in the final class. This convention assigns each observation to exactly one class. Decimal-resolution boundaries and half-open intervals can express a consistent grouping through different numerical conventions.
A class midpoint is the arithmetic mean of its lower and upper boundaries:
m_i = (a_i + b_i) / 2The midpoint locates the class on the measurement axis. It is a representative interval value rather than an assertion about the location of every observation within that interval.
Computing frequencies
Absolute frequency
Once class boundaries are available, each observation contributes to the count of its corresponding class. Under an inclusive-boundary representation, the membership condition is a_i ≤ x ≤ b_i. A complete, nonoverlapping partition ensures that the sum of all class counts equals the number of observations.
Scanning all observations separately for each class requires O(nk) counting time and O(k) counter space. Obtaining minimum and maximum requires O(n) time, while cumulative aggregation requires O(k) time. For equal-width intervals, direct arithmetic calculation of the class index can represent the counting process in O(n + k) time. Both strategies compute the same fundamental statistical quantity: observations per class.
Relative frequency
The relative frequency of a class is the ratio between its count and the sample size:
p_i = f_i / n
Σ p_i = 1Multiplication by 100 gives the percentage frequency. Relative frequencies provide a common scale for distributions having different sample sizes. Display rounding can affect the sum of shown decimal values; the integer counts remain the basis of the distribution.
Cumulative frequency
The ascending cumulative frequency is a running sum of class counts. Including a zero initial threshold creates k+1 cumulative values for k classes:
F₀ = 0
F_j = F_(j−1) + f_j
P_j = F_j / nThe complementary cumulative distribution counts observations remaining above the same threshold:
G_j = n − F_j
Q_j = G_j / n
F_j + G_j = n
P_j + Q_j = 1These identities connect the lower-tail and upper-tail views of a single distribution. Threshold definitions determine whether equality belongs to the completed class or the remaining portion of the observations.
Calculation algorithm
The conversion from raw observations to grouped frequency tables follows a fixed sequence. The following English pseudocode summarizes the statistical operations:
INPUT observations, requestedClassCount, useSturges, roundToTwoDecimals
count ← observations.length
minimum ← min(observations)
maximum ← max(observations)
range ← maximum − minimum
IF useSturges THEN
classCount ← integerPart(1 + 3.3 × log10(count))
ELSE
classCount ← requestedClassCount
END IF
classWidth ← (range + 0.01) / classCount
IF roundToTwoDecimals THEN
classWidth ← round(classWidth, 2)
END IF
boundaries ← buildClassBoundaries(minimum, classWidth, classCount)
frequencies ← countObservations(observations, boundaries)
relativeFrequencies ← frequencies / count
cumulativeFrequencies ← prefixSums(frequencies)
relativeCumulative ← cumulativeFrequencies / count
complementaryCumulative ← count − cumulativeFrequencies
OUTPUT classBoundaries, classMidpoints, frequencies,
relativeFrequencies, cumulativeFrequencies,
relativeCumulative, complementaryCumulativeThe pseudocode describes the core calculation with English algorithmic identifiers. Reading values, determining the class count, constructing boundaries, counting observations, and aggregating cumulative totals are successive stages. The application also provides a sample-data selection and tabular presentation of the calculated quantities.
Computing the distribution of 120 observations
The supplied example dataset contains 120 numerical observations. Its minimum is 2.85, maximum is 3.93, and range is 1.08. The Sturges calculation selects k = 7, and two-decimal rounding produces a class width of h = 0.16.
The first class covers 2.85–3.00, contains three observations and has a midpoint of 2.925 and relative frequency of 0.0250. The second covers 3.01–3.16; its midpoint is 3.085, with 11 observations and relative frequency 0.0917. The third class, 3.17–3.32, contains 32 observations (0.2667) and has midpoint 3.245. Another 32 observations (0.2667) occupy the fourth class, 3.33–3.48, whose midpoint is 3.405.
The fifth class spans 3.49–3.64, with midpoint 3.565, 25 observations and relative frequency 0.2083. The sixth spans 3.65–3.80, with midpoint 3.725, 13 observations and relative frequency 0.1083. The final class, 3.81–3.96, has midpoint 3.885 and contains four observations (0.0333). Absolute frequencies sum to 120, and the relative frequencies displayed to four decimal places sum to 1.0000. Because the observations are represented to two decimal places, the displayed upper and lower endpoints of adjacent classes differ by 0.01.
The first two classes contain 14 observations, while the third and fourth together contain 64, approximately 53.33% of the sample. The last two classes account for 17 observations. The grouped representation makes these concentrations visible without reexamining individual measurements.
Deriving the cumulative distribution
Class frequencies are 3, 11, 32, 32, 25, 13, 4. Ascending cumulative counts at successive boundaries are 0, 3, 14, 46, 78, 103, 116, 120; complementary counts at the same boundaries are 120, 117, 106, 74, 42, 17, 4, 0. At each boundary, the ascending and complementary counts sum to 120.
At the end of the fourth class, the ascending total is 78, leaving 42 observations above that threshold. Their corresponding proportions are 78/120 = 0.65 and 42/120 = 0.35. The final ascending count is 120, and the final complementary count is zero. The cumulative sequence also supports approximate analysis of quantiles and concentration around the center of the distribution.
Interpreting the frequency table
A frequency distribution converts raw measurements into a reproducible counting representation. Absolute frequency expresses the number of observations within a class; relative frequency represents its share of the dataset; cumulative frequency expresses the observations reached by a threshold. Used together, these quantities describe concentrations, tails, and the progression of total frequency across classes.
Grouping replaces observation-level detail with interval-level detail. The selected class count and width consequently establish the resolution of the statistical representation. Comparing tables built with several class counts can reveal how the presentation changes with the aggregation scale. When the original observations are retained, class boundaries and frequencies can be recomputed at the desired resolution.
The statistical foundations are developed in Probability and Statistics: Distributions, Sampling and Regression; Frequency Table and Sturges' Rule give definitions, while C# Programming supplies the programming-language background.
Class Boundaries and Interpretation of Grouped Data
Class intervals in a grouped frequency table must assign every observation to exactly one class. With [0,10), [10,20), and [20,30], a value of 10 belongs to the second class and 20 to the third. The closed endpoint of the final class must be explicit; ambiguous boundaries can either duplicate or discard observations.
Sturges' rule, k = 1 + log₂(n), offers an initial approximation to the number of classes. It is not universally suitable for very large samples or strongly skewed and multimodal data. The Freedman–Diaconis width, h = 2 IQR n^(-1/3), is less sensitive to outliers, but requires a fallback when the IQR is zero. For unequal class widths, histogram heights should be proportional to frequency / class width, not raw frequency.
For validation, the sum of absolute frequencies must equal the sample size and relative frequencies must sum to one within numerical tolerance. Missing, out-of-range, and invalid observations should be counted explicitly; silently excluding them changes the denominator.
References
- Freedman, David; Diaconis, Persi. “On the histogram as a density estimator: L² theory.” Zeitschrift für Wahrscheinlichkeitstheorie und Verwandte Gebiete, 57, 453–476, 1981. DOI: 10.1007/BF01025868.
- Köker, Muhammet Ali. Development of Frequency Table Calculation Software in C# [original Turkish report: C# Programlama Dili ile Frekans Tablosu Bulma Yazılımı Geliştirme]. Probability and Statistics course project report.
- Microsoft. Math.Round Method. .NET API documentation. https://learn.microsoft.com/dotnet/api/system.math.round
- NumPy. histogram_bin_edges — Bin Width Selection. https://numpy.org/doc/stable/reference/generated/numpy.histogram_bin_edges.html
- Scott, David W. “On optimal and data-based histograms.” Biometrika, 66(3), 605–610, 1979. DOI: 10.1093/biomet/66.3.605.
- Sturges, Herbert A. “The Choice of a Class Interval.” Journal of the American Statistical Association, 21(153), 65–66, 1926. DOI: 10.1080/01621459.1926.10502161.