{"skills":[{"name":"Combine group averages using the actual counts","description":"Recover the overall mean from non-overlapping groups while exposing missing means and groups that have no observations.","content":"# Combine group averages using the actual counts\n\nRecover the overall mean from non-overlapping groups while exposing missing means and groups that have no observations.\n\n## When to use this skill\n\n- Someone has the mean and the count for each group and wants the overall mean.\n- A report averages the group averages, and the overall figure looks wrong.\n- One group's mean is missing, or a group has no observations.\n\n## When not to use it\n\n- Combining medians, percentiles or other summaries that are not arithmetic means. These cannot be rebuilt from group values; the underlying data is needed.\n- Survey estimates that need design weights or a margin of error. Use the survey's own weighting method.\n\n## What you need\n\n- Each group\u2019s name, mean and non-negative observation count, all in the same units.\n- Confirmation that the groups partition the population and the means use comparable observations.\n\n## Ask before you start\n\nIf any of these are missing or unclear, ask before doing the work.\n\n- What is the count behind each group's mean? A headcount for a different measure gives the wrong weight.\n- Do the groups overlap, or could any person or item appear in more than one group?\n- Are the group means exact or rounded, and in what unit?\n\n## Method\n\n1. Verify the groups do not overlap and that each count is the number of observations behind that particular mean. A headcount for a different measure is an invalid weight.\n2. Check units: every mean in the same unit, such as minutes or pounds, and every count a number of observations rather than a percentage.\n3. Multiply each group mean by its count and add the products. Total the counts separately and divide once, at the end.\n4. A zero-count group contributes nothing. If a group with a positive count has no mean, the combined mean is unknown. A negative or missing count needs clarification.\n5. If the group means are rounded, label the result as reconstructed from the reported means. Keep full precision and round the result only after dividing.\n6. Show each group's contribution, the total count and the overall mean. If someone has been using the simple average of the means, show both so the difference is visible.\n\n## Checks before you deliver\n\n- Averaging the displayed means gives every group the same weight even when their sizes differ.\n- Using percentages as counts mixes units. Ask for the underlying counts or appropriate weights.\n- Treating a missing mean as zero, or quietly dropping that group, changes the population and the result.\n- Combining medians as if they were means. The overall median cannot be recovered from group medians.\n\n## How to present the result\n\nLead with the overall mean, its unit and the number of observations behind it. Then give a table with one row per group: count, mean and contribution (count times mean), with a totals row. Note any group left out and why, and say whether the result is rebuilt from rounded means.\n\n## Worked example\n\n**Request:** Combine the non-overlapping groups in minutes. Their means are exact.\n\n**Supplied material:**\n\n```text\ngroup|count|mean\nNorth|3|4\nSouth|9|8\nEast|0|blank\n```\n\n**Answer:** The overall wait was 7 minutes across 12 respondents. North contributed 12 person-minutes and South 72. East had no respondents.\n\n## Structured output for tests\n\nFor an ordinary job, answer in the format above and point back to the supplied evidence. Use this structure only for the test cases published with this skill, or when someone asks for structured JSON.\n\nReturn observations as the sum of all supplied valid counts, mean as the combined numeric result rounded to two decimal places (null if undefined), and missing_groups as names of positive-count groups without a mean, in source order.\n\n## Sources\n\n- [NIST Dataplot: weighted mean](https:\/\/www.itl.nist.gov\/div898\/software\/dataplot\/refman2\/ch2\/weigmean.pdf): NIST gives the weighted mean as the sum of each value times its weight divided by the sum of the weights, and notes that weighted means are often used for frequency data. Group counts are the weights here.\n- [The Open University (OpenLearn): the mean of a combined batch](https:\/\/www.open.edu\/openlearn\/science-maths-technology\/prices-location-and-spread\/content-section-4.1): The Open University recovers each batch's sum as mean times size, adds the sums and divides by the combined size, calling the result a weighted mean. It notes the method works for arithmetic means and that little could be done with medians.\n\nTest cases and an answer checker for this skill: https:\/\/skills.raq.com\/skills\/combine-group-averages\n","scope":"contextual","trigger_keywords":["Combine group averages using the actual counts","combine-group-averages","combine group averages","What is the overall average if I only have each group\u2019s average and size?","What is the overall average if I only have each group\u2019s average and size","combine these averages","pooled average","overall mean across groups"],"is_private":true,"is_active":true,"scripts":[{"name":"combine-group-averages-check","description":"Compare a saved JSON answer with a published test. Pass tests\/case-1\/expected.json (or another case) and the path to your answer.","language":"python","filename":"combine-group-averages-check.py","content":"from pathlib import Path\nimport runpy\n\nrunpy.run_path(str(Path(__file__).parent \/ 'tests' \/ 'check.py'), run_name='__main__')\n","supporting_files":[{"path":"SKILL.md","content":"---\nname: combine-group-averages\ndescription: \"Combine group means into one overall mean using each group's count, and flag groups with missing means or no observations. Use when someone has averages for teams, regions, shifts, classes or survey segments and wants the overall average, or suspects an average of averages is wrong.\"\nlicense: CC-BY-4.0\nmetadata:\n  author: Raq.com\n  version: \"2026-11-22\"\n  homepage: https:\/\/skills.raq.com\/skills\/combine-group-averages\n---\n\n# Combine group averages using the actual counts\n\nRecover the overall mean from non-overlapping groups while exposing missing means and groups that have no observations.\n\n## When to use this skill\n\n- Someone has the mean and the count for each group and wants the overall mean.\n- A report averages the group averages, and the overall figure looks wrong.\n- One group's mean is missing, or a group has no observations.\n\n## When not to use it\n\n- Combining medians, percentiles or other summaries that are not arithmetic means. These cannot be rebuilt from group values; the underlying data is needed.\n- Survey estimates that need design weights or a margin of error. Use the survey's own weighting method.\n\n## What you need\n\n- Each group\u2019s name, mean and non-negative observation count, all in the same units.\n- Confirmation that the groups partition the population and the means use comparable observations.\n\n## Ask before you start\n\nIf any of these are missing or unclear, ask before doing the work.\n\n- What is the count behind each group's mean? A headcount for a different measure gives the wrong weight.\n- Do the groups overlap, or could any person or item appear in more than one group?\n- Are the group means exact or rounded, and in what unit?\n\n## Method\n\n1. Verify the groups do not overlap and that each count is the number of observations behind that particular mean. A headcount for a different measure is an invalid weight.\n2. Check units: every mean in the same unit, such as minutes or pounds, and every count a number of observations rather than a percentage.\n3. Multiply each group mean by its count and add the products. Total the counts separately and divide once, at the end.\n4. A zero-count group contributes nothing. If a group with a positive count has no mean, the combined mean is unknown. A negative or missing count needs clarification.\n5. If the group means are rounded, label the result as reconstructed from the reported means. Keep full precision and round the result only after dividing.\n6. Show each group's contribution, the total count and the overall mean. If someone has been using the simple average of the means, show both so the difference is visible.\n\n## Checks before you deliver\n\n- Averaging the displayed means gives every group the same weight even when their sizes differ.\n- Using percentages as counts mixes units. Ask for the underlying counts or appropriate weights.\n- Treating a missing mean as zero, or quietly dropping that group, changes the population and the result.\n- Combining medians as if they were means. The overall median cannot be recovered from group medians.\n\n## How to present the result\n\nLead with the overall mean, its unit and the number of observations behind it. Then give a table with one row per group: count, mean and contribution (count times mean), with a totals row. Note any group left out and why, and say whether the result is rebuilt from rounded means.\n\n## Worked example\n\n**Request:** Combine the non-overlapping groups in minutes. Their means are exact.\n\n**Supplied material:**\n\n```text\ngroup|count|mean\nNorth|3|4\nSouth|9|8\nEast|0|blank\n```\n\n**Answer:** The overall wait was 7 minutes across 12 respondents. North contributed 12 person-minutes and South 72. East had no respondents.\n\n## Structured output for tests\n\nFor an ordinary job, answer in the format above and point back to the supplied evidence. Use this structure only for the test cases published with this skill, or when someone asks for structured JSON.\n\nReturn observations as the sum of all supplied valid counts, mean as the combined numeric result rounded to two decimal places (null if undefined), and missing_groups as names of positive-count groups without a mean, in source order.\n\n## Sources\n\n- [NIST Dataplot: weighted mean](https:\/\/www.itl.nist.gov\/div898\/software\/dataplot\/refman2\/ch2\/weigmean.pdf): NIST gives the weighted mean as the sum of each value times its weight divided by the sum of the weights, and notes that weighted means are often used for frequency data. Group counts are the weights here.\n- [The Open University (OpenLearn): the mean of a combined batch](https:\/\/www.open.edu\/openlearn\/science-maths-technology\/prices-location-and-spread\/content-section-4.1): The Open University recovers each batch's sum as mean times size, adds the sums and divides by the combined size, calling the result a weighted mean. It notes the method works for arithmetic means and that little could be done with medians.\n\nTest cases and an answer checker for this skill: https:\/\/skills.raq.com\/skills\/combine-group-averages\n"},{"path":"LICENSE.txt","content":"Original Raq.com instructions and synthetic examples: CC BY 4.0.\nhttps:\/\/creativecommons.org\/licenses\/by\/4.0\/\nAttribution: Raq.com, https:\/\/skills.raq.com\/skills\/combine-group-averages\nReferenced third-party materials retain their own terms.\n"},{"path":"examples\/worked-example.md","content":"# Respondent wait times\n\nCombine the non-overlapping groups in minutes. Their means are exact.\n\n## Supplied material\n\ngroup|count|mean\nNorth|3|4\nSouth|9|8\nEast|0|blank\n\n## Worked answer\n\nThe overall wait was 7 minutes across 12 respondents. North contributed 12 person-minutes and South 72. East had no respondents.\n\n## Reasoning\n\nNorth contributes 12 person-minutes and South contributes 72, spread across 12 respondents.\n"},{"path":"tests\/check.py","content":"\"\"\"Check a saved agent answer locally with Python 3 (standard library only).\"\"\"\nimport json\nimport math\nimport sys\nfrom pathlib import Path\n\n\ndef compare(expected, actual, path=\"$\", accepted=None):\n    if isinstance(expected, bool) or isinstance(actual, bool):\n        if expected is not actual:\n            yield path\n    elif isinstance(expected, (int, float)) and isinstance(actual, (int, float)):\n        if not math.isclose(expected, actual, rel_tol=0, abs_tol=1e-8):\n            yield path\n    elif isinstance(expected, dict) and isinstance(actual, dict):\n        for key in sorted(set(expected) | set(actual)):\n            if key not in expected or key not in actual:\n                yield f\"{path}.{key}\"\n            elif not any(\n                not list(compare(option, actual[key]))\n                for option in (accepted or {}).get(key, [])\n            ):\n                yield from compare(expected[key], actual[key], f\"{path}.{key}\")\n    elif isinstance(expected, list) and isinstance(actual, list):\n        if len(expected) != len(actual):\n            yield f\"{path} (length)\"\n        for i, (left, right) in enumerate(zip(expected, actual)):\n            yield from compare(left, right, f\"{path}[{i}]\")\n    elif type(expected) != type(actual) or expected != actual:\n        yield path\n\n\ndef main():\n    if len(sys.argv) != 3:\n        raise SystemExit(\"Usage: python3 check.py expected.json answer.json\")\n    try:\n        expected, actual = [json.loads(Path(p).read_text(encoding=\"utf-8\")) for p in sys.argv[1:]]\n        alternatives = Path(sys.argv[1]).with_name(\"accepted.json\")\n        accepted = json.loads(alternatives.read_text(encoding=\"utf-8\")) if alternatives.is_file() else {}\n    except (ValueError, OSError) as error:\n        raise SystemExit(str(error))\n    differences = list(compare(expected, actual, accepted=accepted))\n    if differences:\n        raise SystemExit(\"Different fields: \" + \", \".join(differences))\n    print(\"Pass\")\n\n\nif __name__ == \"__main__\":\n    main()\n"},{"path":"tests\/README.md","content":"Give your agent SKILL.md and one request.txt in a fresh session. Keep the expected answer aside. Save the reply as answer.json, then run this from the tests folder:\n\n    python3 check.py case-1\/expected.json answer.json\n\nEach case also has an explanation. Where accepted.json exists, the checker accepts the alternatives listed there.\n"},{"path":"tests\/case-1\/request.txt","content":"Combine the non-overlapping groups in minutes. Their means are exact.\nReturn only the JSON specified in SKILL.md for this test.\n\ngroup|count|mean\nNorth|3|4\nSouth|9|8\nEast|0|blank\n"},{"path":"tests\/case-1\/expected.json","content":"{\n    \"observations\": 12,\n    \"mean\": 7,\n    \"missing_groups\": []\n}\n"},{"path":"tests\/case-1\/explanation.txt","content":"North contributes 12 person-minutes and South contributes 72, spread across 12 respondents.\n"},{"path":"tests\/case-2\/request.txt","content":"Combine waiting times in seconds for the full day.\nReturn only the JSON specified in SKILL.md for this test.\n\nshift|count|mean\nDay|20|11\nNight|5|blank\n"},{"path":"tests\/case-2\/expected.json","content":"{\n    \"observations\": 25,\n    \"mean\": null,\n    \"missing_groups\": [\n        \"Night\"\n    ]\n}\n"},{"path":"tests\/case-2\/explanation.txt","content":"Dropping the night shift or assigning zero would change the population and the mean.\n"}],"is_active":true,"is_approved":false}]}]}