Analysis of variance for a Latin square Created 2026-10-14 Updated 2026-10-25
For one response per cell in an order- Latin square, fit an intercept and additive row, column and treatment effects with sum-to-zero constraints. Each factor contributes statistical degrees of freedom; the residual has . The centered factor spaces are mutually orthogonal, so sequential sums of squares do not depend on fitting order. With an additional orthogonal symbol factor from a Graeco-Latin square, residual statistical degrees of freedom become . Exact F-tests require independent equal-variance normal errors; unmodeled interactions can invalidate the error term.
Latin square 2026-10-14
A Latin square of order is a array of symbols, each occurring once in each row and column. Used as a row-column design, its symbols label treatments. Centered treatment indicators are orthogonal to both row and column indicators, because every row-treatment and column-treatment pair occurs once. This balance separates additive effects from two nuisance directions.
Latin square enumeration 2026-10-25
Enumerating every Latin square of a specified order, without identifying row, column or symbol permutations as the same output. Arbitrary square generation visits candidates. Restricting every row to a permutation reduces this to candidates. Both counts follow by independent choices for positions or rows; neither count is the number of valid Latin squares.
Latin squares on the same array are mutually orthogonal when every ordered pair of symbols from any two squares occurs exactly once on superposition. Pairwise balance makes the centered symbol-indicator spaces orthogonal in an additive linear regression model.
A randomized complete block design groups similar experimental units into experimental blocks and places every treatment once in each experimental block, independently randomizing treatment allocation within experimental blocks. Blocking removes background between-block variation from within-block treatment comparisons. A balanced incomplete block design has treatments and experimental blocks of size , with each treatment occurring in experimental blocks and every distinct treatment pair together in experimental blocks. Counting treatment occurrences and co-occurrences gives and .
A Latin square of order places each of treatment symbols once in every row and every column of a array. This controls two nuisance directions. A Graeco-Latin square superposes two mutually orthogonal Latin squares: each square is Latin, and each ordered pair of symbols from the two squares occurs exactly once. The two symbol factors can then be fitted together with row and column effects. Random permutations of row labels, column labels and treatment symbols provide a suitable randomized allocation without destroying these balances.
For the operator experiment, fit the additive normal linear model
Here account for the two fabric directions, and is the operator effect. Additivity, independent equal-variance errors and the normal assumption supply the exact F-test; there is only one observation per cell, so an unrestricted interaction model is not available.
In the analysis of variance for a Latin square, the three centered factor spaces each have dimension . Together with the intercept the model has rank ten, leaving residual statistical degrees of freedom. The corrected total has . The completed calculation is
Under the null hypothesis , the operator F-statistic is
The upper five-percent critical value for is , so the operator effect is not significant at five percent in this model.
The decision is independent of the order of fitting rows, columns and operators. To prove the required orthogonality, let be any centered row coefficients and any centered operator coefficients. Their observation-space inner product is , since every operator occurs once in each row. The same calculation applies to columns and operators, and all row-column pairs occur once as well. Thus the three centered spaces are mutually orthogonal; their projections commute and sequential sums of squares equal adjusted sums of squares in every fitting order.
With machines included, the layout is a Graeco-Latin square: the machine symbols are Latin, and all sixteen operator-machine pairs occur exactly once. Fit
in addition to the earlier constraints. The machine space contributes three new statistical degrees of freedom and is orthogonal to the previous factor spaces, so the operator sum of squares remains . The residual sum of squares and statistical degrees of freedom become
Hence
This exceeds but not . Therefore the operator effect is now significant at five percent, but not at one percent. Adjustment for machines has removed substantial residual variation without altering the operator numerator. This illustrates why a balanced nuisance factor can change precision and significance even when it does not change the estimated treatment contrasts.
For an rectangle, let be the symbols absent from column . Each has size . Across all columns, each symbol is absent exactly times, because it appears once in each existing row. For any set of columns, count incidences between those columns and their missing symbols. There are incidences, while each distinct symbol in the union contributes at most . Therefore .
Hall's theorem supplies distinct representatives, one per column, forming an additional row with all symbols. This extends the rectangle without any column repetition. Repeat with rows, then successively until there are rows. Hence every finite latin rectangle extends to a Latin square by adding the required rows.
Choose each row from the permutations of the symbols:
squaresRows :: Int -> [[[Int]]]
squaresRows n
  | n < 0     = error "negative order"
  | otherwise = cp (replicate n (perms [1..n]))

latinRows :: Int -> [[[Int]]]
latinRows = filter valid . squaresRows
Every Latin square remains a candidate, because each of its rows is one of those permutations. Conversely every candidate has valid rows, so only its columns still need checking. There are candidates instead of : at order four, rather than more than four billion. The improvement is substantial but does not make exhaustive generation practical at arbitrary orders. One can replace valid by a column-only test here, since row validity is guaranteed by construction.
Build a Latin square row by row, maintaining the symbols already used in each column. While choosing a row, remove each selected symbol from the row's available pool and reject any symbol already used in that column. The invariant proves every complete output valid. Conversely every valid target row survives the checks, proving completeness by induction. A partial branch may still have no completion; avoiding complete invalid outputs does not mean every explored list prefix is extendable.