Sobes.tech
Middle+

What is the G test?

sobes.tech AI

Answer from AI

The G-test (or G-ratio, likelihood ratio test) is a statistical test used to verify hypotheses about frequency distributions in categorical data. In QA, it can compare defect distribution by categories (type, priority) across different builds, environments, or testing approaches to determine if differences are statistically significant. It is an alternative to Pearson's chi-squared test, especially useful with small samples.

Main steps:

  1. Formulate null ($H_0$) and alternative ($H_1$) hypotheses.
    • $H_0$: No significant difference in frequency distribution.
    • $H_1$: Significant difference exists.
  2. Create a contingency table with observed frequencies.
  3. Calculate expected frequencies assuming $H_0$.
  4. Calculate G-statistic: $G = 2 \sum_{i} O_i \ln(O_i/E_i)$ where $O_i$ is observed, $E_i$ is expected.
  5. Degrees of freedom: $(R-1)(C-1)$ for $R \times C$ table.
  6. Compare G with critical value or p-value. If G > critical or p < alpha, reject $H_0$.

Example in QA: Compare defect types distribution in two environments.

Type Env A Env B
Functional 50 30
UI/UX 20 15
Performance 10 5

Calculate expected frequencies and G-value.

Python example:

import numpy as np
from scipy.stats import chi2_contingency

observed = np.array([[50, 30], [20, 15], [10, 5]])

# G-test
g_statistic, p_value, dof, expected = chi2_contingency(observed, lambda_='log-likelihood')

print(f"G-statistic: {g_statistic:.4f}")
print(f"P-value: {p_value:.4f}")
print(f"Degrees of freedom: {dof}")
print("Expected frequencies:")
print(expected)

# Significance test
alpha = 0.05
if p_value < alpha:
    print("Result: Reject null hypothesis - significant difference")
else:
    print("Result: Cannot reject null hypothesis - no significant difference")