🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
💼 Servicesℹ️ About✉️ ContactView Pricing Plansfrom $10

Phi Coefficient — Correlation Between Two Binary Variables

Foundations of StatisticsDescriptive Statistics🟢 Free Lesson

Phi Coefficient

Descriptive Statistics

When Both Variables Are Yes-or-No Questions

Most real-world data is binary: yes/no, pass/fail, true/false. The phi coefficient takes two binary variables and produces a single correlation value that tells you whether they tend to agree — and by how much.

Key things the phi coefficient helps you understand:

  • Binary association — Whether two dichotomous variables move together or in opposite directions.
  • Chi-square bridge — Phi is directly derived from the chi-square statistic (φ² = χ²/n), linking test of independence to effect size.
  • Symmetric and bounded — φ ranges from -1 to +1, just like Pearson's r, and φ(A,B) = φ(B,A).

For 2×2 tables, phi is the simplest and most elegant measure of association — nothing more, nothing less.


What is the Phi Coefficient?

Definition

The phi coefficient (φ) measures the association between two binary variables using a 2×2 contingency table.


python
import numpy as np
from scipy import stats

# 2x2 contingency table
#               Y=0    Y=1
# X=0           a      b
# X=1           c      d

table = np.array([[30, 10],   # X=0: Y=0=30, Y=1=10
                   [15, 45]])  # X=1: Y=0=15, Y=1=45

chi2, p_value, dof, expected = stats.chi2_contingency(table)
n = table.sum()
phi = np.sqrt(chi2 / n)

print(f"2x2 Table:\n{table}")
print(f"\nChi-square = {chi2:.4f}")
print(f"Phi (φ)    = {phi:.4f}")
print(f"p-value    = {p_value:.6f}")

Relationship to Chi-Square

python
# Verify: phi² = chi²/n
phi_squared = chi2 / n
print(f"φ² = {phi_squared:.4f}")
print(f"φ  = {np.sqrt(phi_squared):.4f}")

Interpretation

φ ValueInterpretation
0.00 – 0.10Negligible association
0.10 – 0.30Weak association
0.30 – 0.50Moderate association
0.50+Strong association
python
# Manual calculation
a, b, c, d = table[0,0], table[0,1], table[1,0], table[1,1]
phi_manual = (a*d - b*c) / np.sqrt((a+b)*(c+d)*(a+c)*(b+d))
print(f"Manual φ = {phi_manual:.4f}")

Phi Coefficient in Machine Learning

ML ApplicationPhi UsageWhy
Binary classificationPhi coefficient of confusion matrixBalanced accuracy metric
Feature selectionBinary vs binary associationQuick screening
Medical MLDisease vs symptom associationClinical feature selection
python
import numpy as np
from sklearn.metrics import confusion_matrix
from sklearn.datasets import make_classification
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split

X, y = make_classification(n_samples=500, n_features=5, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

model = LogisticRegression(random_state=42)
model.fit(X_train, y_train)
y_pred = model.predict(X_test)

tn, fp, fn, tp = confusion_matrix(y_test, y_pred).ravel()
phi = (tp*tn - fp*fn) / np.sqrt((tp+fp)*(tp+fn)*(tn+fp)*(tn+fn))
print(f"Confusion matrix: TP={tp}, TN={tn}, FP={fp}, FN={fn}")
print(f"Phi coefficient: {phi:.4f}")
print("Phi = 1 is perfect, 0 is random, -1 is opposite")

Key Takeaways

Phi measures association between two binary variables — requires a 2×2 contingency table and nothing else.

φ ranges from -1 to +1 — sign indicates the direction of association, just like Pearson's r.

φ² = χ²/n — directly related to the chi-square statistic, making it a natural effect size for the chi-square test of independence.

Only for 2×2 tables — for larger tables, graduate to Cramér's V, which generalizes phi to any r×c table.

"Two binary variables, one elegant number — phi is Pearson's r when everything is a yes-or-no question."


Extended Learning: Beyond the Basics

Key Concepts Summary

This lesson covers fundamental concepts that serve as building blocks for more advanced topics. Master these basics before moving to intermediate and advanced material.

Prerequisite Knowledge

Before studying this topic in depth, ensure you understand:

  • Basic definitions and terminology
  • Core formulas and their derivations
  • Common applications in real-world scenarios
  • Typical pitfalls and misconceptions

Step-by-Step Walkthrough

Let us work through a complete example to solidify understanding:

Step 1: Identify the problem type. Determine which category this problem falls into and which approach is most appropriate.

Step 2: Apply the relevant formula. Substitute known values into the appropriate equation, paying attention to units and constraints.

Step 3: Simplify and solve. Work through the algebra step by step, checking each intermediate result.

Step 4: Verify the answer. Check that the solution satisfies the original conditions and makes logical sense.

Common Mistakes to Avoid

  1. Misidentifying the problem type — Always start by categorizing the problem
  2. Incorrect formula application — Verify the formula applies to your specific case
  3. Unit errors — Always check units are consistent throughout
  4. Sign errors — Pay careful attention to positive and negative values
  5. Rounding too early — Keep full precision until the final answer
  6. Forgetting constraints — Check that solutions satisfy all given conditions

Real-World Applications

Understanding this concept is essential for:

  • Advanced problem solving in examinations
  • Building intuition for more complex topics
  • Developing analytical thinking skills
  • Applying mathematical reasoning to practical situations

Practice Exercises

  1. Basic: Solve 5 problems of increasing difficulty using the core concept.
  2. Intermediate: Apply the concept to word problems with multiple steps.
  3. Advanced: Combine this concept with 2-3 other topics in a comprehensive problem.
  4. Challenge: Create your own problem that requires this concept plus additional knowledge.

Interview and Exam Tips

  • Common question patterns: Identify which exam or interview formats test this topic
  • Time management: Practice completing problems within time constraints
  • Common traps: Know the typical mistakes examiners set as distractors
  • Verification strategy: Develop a quick method to check your answer

Related Topics

Quick Reference Card

ConceptFormula/RuleKey InsightCommon Use
Core DefinitionSee main textUnderstand the intuitionFoundation for all applications
Key FormulaSee main textMemorize the derivationDirect problem solving
Special CaseSee main textRecognize when it appliesSimplifies complex problems
Edge CaseSee main textKnow the limitationsAvoids errors

Further Reading

For students who want to go deeper:

  • Standard textbooks on the subject
  • Research papers applying this concept
  • Online courses with video explanations
  • Practice problem collections with detailed solutions
CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-11-14

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert Statistics Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement