Mendelian crosses with gamete probabilities, recombination, Monte Carlo offspring and a chi-square test.
running...
The science
Mendel’s first law: each parent passes one allele of each gene, chosen at random, so a heterozygote Bb makes B and b gametes with probability ½ each. Offspring genotype probabilities are the product of the two gamete probabilities, which is exactly what the Punnett square tabulates. With B dominant, Bb × Bb gives 3 dominant : 1 recessive.
For two genes on different chromosomes (r = 0.5) the genes assort independently and BbLl × BbLl gives 9:3:3:1. When two genes are physically linked on the same chromosome, recombination fraction r is the chance that crossing over has swapped them in a gamete: parental gametes occur with probability (1−r)/2 each and recombinants with r/2 each. In a test cross this makes r the observed fraction of recombinant offspring (r = 0.01 corresponds to a map distance of 1 centimorgan).
Chance matters: a finite sample never matches the ratio exactly. The chi-square statistic χ² = Σ (O − E)² / E compares observed counts to expectation; the p-value is the probability of a deviation at least that large if the model were right (computed from the regularised incomplete gamma function). p < 0.05 suggests the model does not fit. The test is unreliable when any expected count is below about 5.
Simplifications: complete dominance, no mutation, no sex linkage, equal viability, and the same r in both parents (real r differs between the sexes). Critter models, chromosomes and meadow are Blender 5.2 assets; the loci drawn are the parent genotype (linked genes share a chromosome when r < 0.5). Critter colours only illustrate the phenotype classes.