Skip to content
v0.1.3latest release121 skills4 categories6 sub-categories247 tested scripts397 reference docsContact us
scripts/pick_test.py
#!/usr/bin/env python3
"""Pick the right hypothesis test from the data types and the question (Six Sigma roadmap).

Answers: test, null hypothesis, assumptions to check, non-parametric alternative, run_test.py command and
the Minitab menu path.

Usage:
    python pick_test.py --y continuous --x 2-groups
    python pick_test.py --y continuous --x 2-groups --paired --not-normal
    python pick_test.py --y proportion --x k-groups
    python pick_test.py --y continuous --x none --compare variance
    python pick_test.py --y continuous --x continuous

Y: continuous | proportion (pass/fail) | count (defects)
X: none (compare with a target) | 2-groups | k-groups | continuous
Exit codes: 0 recommendation printed, 2 combination not covered.
"""

import argparse
import sys

T = {
    ("continuous", "none", "mean"): ("1-sample t-test", "mean = target", "normal data (or n >= 30), independent",
                                     "1-sample Wilcoxon / sign test (median)", "t1", "Stat > Basic Statistics > 1-Sample t"),
    ("continuous", "none", "variance"): ("Chi-square test for one variance", "sigma = target", "normal data (sensitive to non-normality)",
                                         "Bonett method (Minitab 1 Variance)", None, "Stat > Basic Statistics > 1 Variance"),
    ("continuous", "2-groups", "mean"): ("2-sample t-test (Welch, unequal variances)", "mean1 = mean2", "normal in each group (or n >= 15 each), independent groups",
                                         "Mann-Whitney test (medians)", "t2", "Stat > Basic Statistics > 2-Sample t"),
    ("continuous", "2-groups-paired", "mean"): ("Paired t-test", "mean difference = 0", "differences approximately normal; same units measured twice",
                                                "Wilcoxon signed-rank on the differences", "paired", "Stat > Basic Statistics > Paired t"),
    ("continuous", "2-groups", "variance"): ("F-test for two variances (normal) or Levene's test", "sigma1 = sigma2", "F-test needs normal data; Levene is robust",
                                             "Levene / Brown-Forsythe", "var2", "Stat > Basic Statistics > 2 Variances"),
    ("continuous", "k-groups", "mean"): ("One-way ANOVA", "all means equal", "normal residuals, equal variances (check with Levene), independent",
                                         "Kruskal-Wallis (or Mood's median for outliers)", "anova", "Stat > ANOVA > One-Way"),
    ("continuous", "k-groups", "variance"): ("Bartlett's (normal) or Levene's test", "all variances equal", "Bartlett needs normal data",
                                             "Levene", None, "Stat > ANOVA > Test for Equal Variances"),
    ("continuous", "continuous", "mean"): ("Correlation and simple regression", "slope = 0 (no linear relation)", "linear relation, normal residuals with constant variance",
                                           "Spearman rank correlation", None, "Stat > Regression > Fitted Line Plot"),
    ("proportion", "none", "mean"): ("1-proportion test (exact binomial)", "p = target", "independent trials, fixed n",
                                     "-", None, "Stat > Basic Statistics > 1 Proportion"),
    ("proportion", "2-groups", "mean"): ("2-proportion test (Fisher's exact for small counts)", "p1 = p2", "independent samples; n*p >= 5 for the normal approximation",
                                         "Fisher's exact test", "prop2", "Stat > Basic Statistics > 2 Proportions"),
    ("proportion", "2-groups-paired", "mean"): ("McNemar's test", "no change in proportion", "same units classified twice",
                                                "-", None, "Stat > Tables > Cross Tabulation (McNemar)"),
    ("proportion", "k-groups", "mean"): ("Chi-square test of association", "proportion independent of group", "expected count >= 5 in at least 80% of cells",
                                         "Fisher's exact (2x2) / combine categories", "chi2", "Stat > Tables > Chi-Square Test for Association"),
    ("proportion", "continuous", "mean"): ("Binary logistic regression", "X has no effect on the odds", "independent observations, enough events",
                                           "-", None, "Stat > Regression > Binary Logistic Regression"),
    ("count", "none", "mean"): ("1-sample Poisson rate test", "rate = target", "counts per equal opportunity, independent events",
                                "-", None, "Stat > Basic Statistics > 1-Sample Poisson Rate"),
    ("count", "2-groups", "mean"): ("2-sample Poisson rate test", "rate1 = rate2", "Poisson counts, known exposure",
                                    "-", None, "Stat > Basic Statistics > 2-Sample Poisson Rate"),
    ("count", "k-groups", "mean"): ("Chi-square goodness of fit / Poisson regression", "rates equal across groups", "expected counts >= 5",
                                    "-", "chi2", "Stat > Tables > Chi-Square Goodness-of-Fit"),
}


def main():
    ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
    ap.add_argument("--y", required=True, choices=["continuous", "proportion", "count"])
    ap.add_argument("--x", required=True, choices=["none", "2-groups", "k-groups", "continuous"])
    ap.add_argument("--compare", choices=["mean", "variance"], default="mean", help="location (mean/median) or spread")
    ap.add_argument("--paired", action="store_true", help="the same units measured under both conditions")
    ap.add_argument("--not-normal", action="store_true", help="data are clearly non-normal / small samples with outliers")
    a = ap.parse_args()
    x = a.x + ("-paired" if a.paired and a.x == "2-groups" else "")
    key = (a.y, x, a.compare if a.y == "continuous" else "mean")
    if key not in T:
        print(f"error: no standard test for Y={a.y}, X={x}, compare={a.compare}", file=sys.stderr)
        return 2
    test, h0, assume, alt, cmd, menu = T[key]
    if a.not_normal and alt not in ("-", "") and a.y == "continuous":
        print(f"Recommended: {alt}   (non-normal data; parametric choice would be {test})")
    else:
        print(f"Recommended: {test}")
    print(f"  H0: {h0}   (H1: not equal, or one-sided if the question is directional and fixed before the data)")
    print(f"  Assumptions: {assume}")
    print(f"  Non-parametric alternative: {alt}")
    print(f"  Minitab: {menu}")
    if cmd:
        print(f"  Run it: python scripts/run_test.py {cmd} ...")
    print("  Report the effect size and confidence interval, not only the p-value; check the sample size is enough "
          "to detect the difference that matters.")
    return 0


if __name__ == "__main__":
    sys.exit(main())
More in Quality Management & ISO 9001

8d-problem-solving-report-writer

Write and review 8D problem-solving reports for customer complaints and serious nonconformities (automotive and aerospace practice: Ford Global 8D, VDA, GM, Stellantis formats): D0 emergency response, D1 cross-functional team and champion, D2 problem description with 5W2H and is / is-not and no cause in the statement, D3 interim containment within 24 hours with verification and clean point, D4 verified occurrence and escape (non-detection) root causes plus systemic cause, D5 permanent corrective actions for each cause verified before implementation, D6 implementation, validation with production data and removal of containment, D7 PFMEA, control plan and read-across to similar products, D8 closure and recognition. Checks an 8D discipline by discipline for missing content, human-error root causes, missing escape cause or action, late containment and dates out of order.

acceptance-sampling-plan-selector

Select and evaluate acceptance sampling plans for incoming, in-process and final inspection: ANSI/ASQ Z1.4 / ISO 2859-1 single sampling under normal inspection (code letter from lot size and inspection level I, II, III, S-1 to S-4; sample size, Ac and Re from AQL, following the table's arrows to the correct plan; 100% when n reaches the lot size; AQLs above 10 per 100 units), operating characteristic curves (Pa at any quality, producer's quality level, indifference point, LTPD, AOQ and AOQL, binomial or hypergeometric), plans designed from producer and consumer risk, and c = 0 zero-acceptance plans. Covers AQL choice by defect class, switching rules between normal, tightened and reduced inspection, when sampling is not appropriate, and random sampling.

approved-supplier-list-manager

Manage and audit an approved supplier list (ASL) / external provider register for ISO 9001 8.4.1, IATF 16949 8.4 and AS9100 8.4.1: supplier status (approved, conditional, probation, pending, disqualified), scope of approval by commodity and process, risk class, certification and expiry, re-evaluation intervals by risk, conditions with end dates, single-source contingency, approver and customer-directed sources. Audits the list for expired or expiring certificates, overdue re-evaluations, conditional or probation status past its decision date, high-risk suppliers without the required certification, single-source suppliers without backup and missing approvers, and checks purchase orders for suppliers that are off-list, disqualified or pending, or buying outside the approved scope. Covers ERP blocks, PO requirements, off-list and emergency purchases.

apqp-phase-planner

Plan and track Advanced Product Quality Planning (AIAG APQP 3rd edition, IATF 16949) for a new or changed automotive part: back-schedule the five phases (plan and define, product design, process design, product and process validation, launch and feedback) from the start-of-production date by program complexity, with overlap, PPAP lead and safe-launch period; list the deliverables and gate for each phase (DFMEA, DVP&R, feasibility, process flow, PFMEA, control plans, MSA, Ppk, run at rate, PPAP, safe launch, lessons learned); adjust for build-to-print suppliers; flag compressed timelines and late or untracked deliverables against a status list. Covers gate reviews, red/yellow/green status reporting, run at rate and safe-launch exit criteria.

as9100-gap-analyzer

Run an AS9100D / EN 9100:2018 gap analysis for aviation, space and defence suppliers on the requirements added to ISO 9001: on-time delivery and conformity focus, management representative, ethics and human-factors awareness, operational planning and operational risk management, configuration management, product safety, counterfeit-part prevention, special requirements, critical items and key characteristics, external provider register and flow-down, FOD prevention, tooling and NC program control, special process validation, first article inspection (AS9102), traceability, in-service data and nonconforming product control. Generates and scores a worksheet, grades missing core controls as major, and checks invalid n/a claims. Covers AS9101/AS9104, OASIS, AS9102 FAI forms, counterfeit standards (AS5553, AS6174, AS6081), NADCAP and the planned IA9100 transition.

audit-report-writer

Write internal, supplier and pre-certification audit reports with the content ISO 19011:2018 6.5 expects: audit objectives, scope, criteria with revisions, dates, team and auditees, method and sampling statement, specific strengths, findings table and three-part finding details (requirement, evidence, statement), conclusion on the degree of fulfilment of criteria, diverging opinions, follow-up deadlines and distribution. Builds a Markdown report from a JSON audit record, generates the conclusion from the findings (major / minor / none) and flags reports missing required content or findings without clause or evidence. Covers conclusion wording, closing meetings, response expectations and verifying corrective actions.