{"success":true,"version":"v1","request":{"tool":"get_calculator_schema","calculator_id":"hardy-weinberg"},"result":{"entity_type":"calculator","id":"hardy-weinberg","calculator_id":"hardy-weinberg","canonical_url":"https://tttkmbb.com/science/hardy-weinberg","name":"Hardy-Weinberg Equilibrium Calculator","title":"Hardy-Weinberg Calculator – Allele Frequencies, Expected Genotype Counts and Chi-Square Test","category":"science","category_name":"Biology, Earth & Space","tool_name":"calculate_hardy_weinberg","featured_mcp_tool":false,"description":"Estimates the allele frequencies p and q of a two-allele locus from observed genotype counts, computes the genotype counts expected under Hardy–Weinberg equilibrium (p², 2pq, q²) and tests the deviation with a chi-square goodness-of-fit test with 1 degree of freedom.","use_when":"You have counts of the three genotypes (AA, Aa, aa) of a population sample and need allele frequencies, expected genotype numbers or a test of whether the population is in Hardy–Weinberg equilibrium.","do_not_use_when":"The locus has more than two alleles or is X-linked, you only know phenotype counts of a dominant trait (then q = √(recessive fraction) is the only estimate and no test is possible), or you need a general contingency-table test (use chi-square-test).","inputs":[{"name":"count_homozygous_dominant","label":"Homozygous dominant (AA)","type":"integer","required":true,"min":0,"max":1000000000,"description":"Number of individuals with genotype AA.","example":50},{"name":"count_heterozygous","label":"Heterozygous (Aa)","type":"integer","required":true,"min":0,"max":1000000000,"description":"Number of individuals with genotype Aa.","example":40},{"name":"count_homozygous_recessive","label":"Homozygous recessive (aa)","type":"integer","required":true,"min":0,"max":1000000000,"description":"Number of individuals with genotype aa.","example":10}],"outputs":[{"name":"total_individuals","label":"Sample size N","type":"integer","decimals":4,"description":"Sum of the three genotype counts."},{"name":"p","label":"Frequency of A (p)","type":"number","decimals":4,"description":"Dominant allele frequency (2·AA + Aa) / 2N."},{"name":"q","label":"Frequency of a (q)","type":"number","decimals":4,"description":"Recessive allele frequency 1 − p."},{"name":"observed_frequencies","label":"Observed genotype frequencies","type":"object","decimals":4,"description":"Observed fractions of AA, Aa and aa."},{"name":"expected_frequencies","label":"Expected genotype frequencies","type":"object","decimals":4,"description":"p_squared (AA), two_pq (Aa) and q_squared (aa) expected under equilibrium."},{"name":"expected_homozygous_dominant","label":"Expected AA count","type":"number","decimals":2,"description":"p² × N."},{"name":"expected_heterozygous","label":"Expected Aa count","type":"number","decimals":2,"description":"2pq × N."},{"name":"expected_homozygous_recessive","label":"Expected aa count","type":"number","decimals":2,"description":"q² × N."},{"name":"chi_square","label":"Chi-square statistic","type":"number","decimals":4,"description":"Σ (observed − expected)² / expected over the three genotypes."},{"name":"degrees_of_freedom","label":"Degrees of freedom","type":"integer","decimals":4,"description":"3 genotype classes − 1 − 1 estimated parameter (p) = 1."},{"name":"p_value","label":"p-value","type":"number","decimals":4,"description":"P(χ²₁ ≥ chi_square) = 2 × (1 − Φ(√χ²))."},{"name":"in_equilibrium","label":"In Hardy-Weinberg equilibrium","type":"boolean","decimals":4,"description":"true when p_value ≥ 0.05 (no significant deviation at α = 0.05)."},{"name":"interpretation","label":"Interpretation","type":"string","decimals":4,"description":"Plain-language conclusion of the test."}],"input_schema":{"type":"object","properties":{"count_homozygous_dominant":{"description":"Number of individuals with genotype AA.","type":"integer","minimum":0,"maximum":1000000000,"examples":[50]},"count_heterozygous":{"description":"Number of individuals with genotype Aa.","type":"integer","minimum":0,"maximum":1000000000,"examples":[40]},"count_homozygous_recessive":{"description":"Number of individuals with genotype aa.","type":"integer","minimum":0,"maximum":1000000000,"examples":[10]}},"additionalProperties":false,"required":["count_homozygous_dominant","count_heterozygous","count_homozygous_recessive"]},"output_schema":{"type":"object","properties":{"total_individuals":{"description":"Sum of the three genotype counts.","type":"integer"},"p":{"description":"Dominant allele frequency (2·AA + Aa) / 2N.","type":"number"},"q":{"description":"Recessive allele frequency 1 − p.","type":"number"},"observed_frequencies":{"description":"Observed fractions of AA, Aa and aa.","type":"object"},"expected_frequencies":{"description":"p_squared (AA), two_pq (Aa) and q_squared (aa) expected under equilibrium.","type":"object"},"expected_homozygous_dominant":{"description":"p² × N.","type":"number"},"expected_heterozygous":{"description":"2pq × N.","type":"number"},"expected_homozygous_recessive":{"description":"q² × N.","type":"number"},"chi_square":{"description":"Σ (observed − expected)² / expected over the three genotypes.","type":"number"},"degrees_of_freedom":{"description":"3 genotype classes − 1 − 1 estimated parameter (p) = 1.","type":"integer"},"p_value":{"description":"P(χ²₁ ≥ chi_square) = 2 × (1 − Φ(√χ²)).","type":"number"},"in_equilibrium":{"description":"true when p_value ≥ 0.05 (no significant deviation at α = 0.05).","type":"boolean"},"interpretation":{"description":"Plain-language conclusion of the test.","type":"string"}}},"formula":"p = (2·AA + Aa) / (2N), q = 1 − p; expected AA = p²N, Aa = 2pqN, aa = q²N; χ² = Σ (O − E)² / E, df = 1; p-value = 2 × (1 − Φ(√χ²))","method":"Hardy–Weinberg equilibrium assumes random mating and no selection, mutation, migration or drift. The test has 1 degree of freedom because p is estimated from the same data; the p-value uses the standard normal CDF exactly, since a χ² variable with 1 df is the square of a standard normal. Expected counts below 5 make the approximation unreliable (a note is added).","sources":[{"name":"Wikipedia – Hardy–Weinberg principle","url":"https://en.wikipedia.org/wiki/Hardy%E2%80%93Weinberg_principle","type":"reference","retrieved_at":"2026-09-24"},{"name":"OpenStax Biology 2e – 19.1 Population Evolution","url":"https://openstax.org/books/biology-2e/pages/19-1-population-evolution","type":"textbook","retrieved_at":"2026-09-24"}],"freshness":{"type":"static","max_age_seconds":null,"note":"Deterministic formula with fixed constants; results never go stale. Inputs supplied by the caller determine the output."},"examples":[{"name":"50 AA, 40 Aa, 10 aa","inputs":{"count_homozygous_dominant":50,"count_heterozygous":40,"count_homozygous_recessive":10},"expected":{"total_individuals":100,"p":0.7,"q":0.3,"expected_homozygous_dominant":49,"expected_heterozygous":42,"expected_homozygous_recessive":9,"expected_frequencies":{"p_squared":0.49,"two_pq":0.42,"q_squared":0.09},"chi_square":0.2268,"p_value":0.6339,"in_equilibrium":true},"url":"https://tttkmbb.com/api/v1/calculate/hardy-weinberg?count_homozygous_dominant=50&count_heterozygous=40&count_homozygous_recessive=10"},{"name":"360 AA, 480 Aa, 160 aa (exact equilibrium)","inputs":{"count_homozygous_dominant":360,"count_heterozygous":480,"count_homozygous_recessive":160},"expected":{"p":0.6,"q":0.4,"expected_homozygous_dominant":360,"expected_heterozygous":480,"expected_homozygous_recessive":160,"chi_square":0,"p_value":1,"in_equilibrium":true},"url":"https://tttkmbb.com/api/v1/calculate/hardy-weinberg?count_homozygous_dominant=360&count_heterozygous=480&count_homozygous_recessive=160"}],"faq":[{"q":"Why only 1 degree of freedom with 3 classes?","a":"One degree is lost because the counts must sum to N and another because the allele frequency p is estimated from the observed counts, leaving 3 − 2 = 1."},{"q":"Can I use phenotype counts for a recessive trait?","a":"Only to estimate q as the square root of the recessive phenotype fraction (assuming equilibrium); the chi-square test needs the three genotype counts, which this calculator requires."},{"q":"What does a significant deviation mean?","a":"The genotype proportions differ from p², 2pq, q² more than sampling error explains, pointing to non-random mating, selection, population structure or genotyping error; it does not say which."}],"tags":["hardy weinberg","allele frequency","genotype frequency","population genetics","chi square","equilibrium"],"related":[{"calculator_id":"punnett-square","reason":"Offspring ratios of a single cross instead of population frequencies."},{"calculator_id":"chi-square-test","reason":"General chi-square tests for contingency tables and other goodness-of-fit problems."},{"calculator_id":"p-value","reason":"Convert a chi-square statistic with other degrees of freedom to a p-value."}],"links":{"html":"https://tttkmbb.com/science/hardy-weinberg","markdown":"https://tttkmbb.com/science/hardy-weinberg.md","json":"https://tttkmbb.com/science/hardy-weinberg.json","api":"https://tttkmbb.com/api/v1/calculate/hardy-weinberg","schema":"https://tttkmbb.com/api/v1/calculators/hardy-weinberg","openapi":"https://tttkmbb.com/openapi.json","mcp":"https://tttkmbb.com/mcp"},"version":"v1","updated_at":"2026-09-24"},"timestamp":"2026-09-24T03:47:22Z"}