Sub topic 13
Attribute Agreement Analysis and Cohen's Kappa
This chapter assumes you know the gage R&R vocabulary from earlier chapters (repeatability, reproducibility, and the idea that a measurement system has its own error). It also assumes you can read a proportion and a simple 2×2 table. No new statistics beyond that are needed.
Why variance components do not work here
Gage R&R with ANOVA needs a continuous measurement. You can split a diameter reading into part variation, repeatability and reproducibility because the values have a mean and a variance.
Many inspections do not produce numbers. An inspector looks at a weld and says "pass" or "fail". A reviewer grades a scratch as "none", "minor" or "major". A call-center auditor tags a call as "compliant" or "not compliant". These are attribute measurements, which give a category instead of a number. There is no variance to decompose.
The same questions still apply:
- Does one appraiser give the same answer when judging the same item twice? This is the attribute version of repeatability.
- Do different appraisers give the same answer for the same item? This is the attribute version of reproducibility.
- Does the answer match the truth? This is the attribute version of bias.
Attribute agreement analysis answers these with agreement statistics instead of variance components.
Designing an attribute study
The design mirrors a crossed gage R&R study, with a few changes.
- Pick the items. Use 30 to 50 items. Choose them deliberately rather than at random. Include clearly good items, clearly bad items, and a fair share of borderline items. A sample of only obvious cases makes every system look perfect.
- Establish a reference. Have an expert, or a better instrument, assign each item a known correct category (the standard). Without it you can measure only consistency, not accuracy.
- Choose appraisers. Use at least 2, and preferably 3, of the people who actually do the inspection.
- Replicate. Each appraiser rates every item at least twice (2 to 3 trials).
- Blind and randomize. Appraisers must not know the reference, their earlier answers, or other appraisers' answers. Change the item order between trials, and leave enough time between trials that memory does not help.
Record each rating with the appraiser, trial and item identifier.
The four comparisons
A standard attribute study report has four levels of agreement. Each answers a different question.
| Comparison | Question it answers | Variable analog |
|---|---|---|
| Within appraiser | Does each person agree with their own earlier ratings? | Repeatability |
| Each appraiser vs standard | Is each person correct? | Bias per operator |
| Between appraisers | Do people agree with each other? | Reproducibility |
| All appraisers vs standard | Is the whole team consistent and correct? | Overall system |
Read them in order. If the within-appraiser result is poor, the other three cannot be good, because an appraiser who contradicts themselves cannot agree with anyone else.
Percent agreement and why it is not enough
The simplest statistic is percent agreement: the share of items on which two ratings match. It is easy to explain, but it hides a problem.
Two raters who guess will agree some of the time by luck. If 95% of items are good and both raters say "pass" almost always, they will agree on about 90% of items even if neither looked at the part. Percent agreement does not separate real agreement from agreement by chance.
Cohen's kappa
Cohen's kappa corrects for chance. It compares the observed agreement with the agreement you would expect if each rater assigned categories independently, keeping their own overall rates:
kappa = (po − pe) / (1 − p_e)
- p_o is the observed proportion of agreement.
- p_e is the expected agreement by chance: for each category, multiply the two raters' proportions for that category, then add these products over all categories.
Interpret the value as follows:
- kappa = 1 means perfect agreement.
- kappa = 0 means agreement is no better than chance.
- kappa below 0 means agreement is worse than chance, which usually points to a systematic problem such as a swapped label.
The code below is the function from this tutorial's plan, applied to a small example.
def cohens_kappa(rater_a, rater_b):
"""Cohen's kappa for two raters giving categorical ratings to the same items."""
n = len(rater_a)
categories = set(rater_a) | set(rater_b)
observed = sum(a == b for a, b in zip(rater_a, rater_b)) / n
expected = sum(
(rater_a.count(c) / n) * (rater_b.count(c) / n) for c in categories
)
return (observed - expected) / (1 - expected)
a = ["pass", "pass", "fail", "pass", "fail", "fail", "pass", "pass"]
b = ["pass", "fail", "fail", "pass", "fail", "pass", "pass", "pass"]
print(round(cohens_kappa(a, b), 3))The output is 0.467. Here is the arithmetic:
- The raters agree on 6 of 8 items, so p_o = 0.75.
- Rater A says "pass" 5 times and "fail" 3 times. Rater B has the same counts.
- p_e = (5/8)² + (3/8)² = 0.531.
- kappa = (0.75 − 0.531) / (1 − 0.531) = 0.467.
Percent agreement looks decent at 75%, but after removing chance agreement the result is only moderate.
Guidelines for the value
Common guidance, such as the AIAG MSA manual, treats the result like this:
| Kappa | Reading |
|---|---|
| Above 0.75 | Good agreement |
| 0.40 to 0.75 | Marginal, acceptable only for some uses |
| Below 0.40 | Poor agreement, the system needs improvement |
These cut-offs are conventions, not laws. A system that screens safety-critical parts needs a stricter standard than one that sorts cosmetic grades. Set the threshold from the cost of a wrong call, and write it down before the study.
A guard you should add
The function divides by 1 - expected. If both raters use a single identical category for every item, expected is 1 and the division fails. That situation means the study design is faulty, because there is no variation among the items. Fix the sample rather than the code.
Kappa's known weaknesses
Kappa is useful but easy to misread. These are the common errors.
Prevalence sensitivity. When one category is very common, kappa can be low even though observed agreement is high. Suppose 100 parts are rated by two inspectors. Both say "pass" on 93, they split on 6 (3 each way), and both say "fail" on 1. Observed agreement is 0.94. Each inspector passes 96% of parts, so p_e = 0.96² + 0.04² = 0.9232. Then kappa = (0.94 − 0.9232) / (1 − 0.9232) = 0.219, which is poor. The statistic is telling you that, given how rarely anything fails, the inspectors have shown little skill at spotting the rare failures. This is another reason to include enough bad and borderline items in the sample.
Only two raters. Cohen's kappa compares one pair. With three appraisers you either compute kappa for each pair or use Fleiss' kappa, which extends the idea to many raters.
All disagreements count equally. For ordinal categories such as "none, minor, major", confusing "none" with "major" is worse than confusing "minor" with "major". Weighted kappa gives partial credit to near misses. For ordinal ratings you can also use Kendall's coefficient, which uses the order of the categories.
Sampling error. With 30 to 50 items, a kappa estimate has a wide confidence interval. A kappa of 0.80 with an interval of 0.55 to 0.95 does not demonstrate "good". Report the interval when you can, and compare the lower bound with your criterion.
Accuracy against the standard
Kappa measures consistency between raters. When you have a reference standard, add rates that show which way the errors go, because the two kinds of error usually have different costs.
- Effectiveness: the share of ratings that match the standard.
- Miss rate: the share of truly bad items that were accepted. The customer receives a defect.
- False alarm rate: the share of truly good items that were rejected. This causes scrap and rework.
def vs_standard(rating, standard, bad="fail"):
n = len(standard)
correct = sum(r == s for r, s in zip(rating, standard))
bad_total = sum(s == bad for s in standard)
good_total = n - bad_total
miss = sum(s == bad and r != bad for r, s in zip(rating, standard))
false_alarm = sum(s != bad and r == bad for r, s in zip(rating, standard))
return {
"effectiveness": correct / n,
"miss_rate": round(miss / bad_total, 3),
"false_alarm_rate": round(false_alarm / good_total, 3),
}
standard = ["pass", "pass", "fail", "pass", "fail", "fail", "pass", "pass"]
b = ["pass", "fail", "fail", "pass", "fail", "pass", "pass", "pass"]
print(vs_standard(b, standard))The output is {'effectiveness': 0.75, 'miss_rate': 0.333, 'false_alarm_rate': 0.2}. Appraiser B let one of the three bad items through and rejected one of the five good items.
Reading the result and acting on it
The decision path follows the order of the four comparisons.
Typical corrective actions are the same as for variable systems, adapted to judgments:
- Write operational definitions with photographs of boundary cases, such as the smallest scratch that fails.
- Improve the conditions of viewing: lighting, magnification, fixtures, and time per item.
- Retrain the appraisers who disagree with the standard.
- Replace the human judgment with an instrument where possible, and then run a variable gage R&R on it.
If the standard itself is questionable, for example because experts disagree, fix that first. A system cannot be accurate against a wrong reference.
Exercise
Two inspectors rate 100 parts. Both say "pass" on 90 parts and both say "fail" on 4 parts. Inspector A passes and Inspector B fails 3 parts. Inspector A fails and Inspector B passes 3 parts. Compute percent agreement and Cohen's kappa.
Show answer
Observed agreement is (90 + 4) / 100 = 0.94. Inspector A passes 93 parts (90 + 3) and fails 7. Inspector B passes 93 parts (90 + 3) and fails 7. So p_e = 0.93² + 0.07² = 0.8649 + 0.0049 = 0.8698. Kappa = (0.94 − 0.8698) / (1 − 0.8698) = 0.0702 / 0.1302 = 0.539. Agreement is high at 94%, but kappa is only marginal because most parts are good and much of the agreement is expected by chance.
Exercise
An appraiser agrees with the standard on 36 of 40 items. The standard has 10 bad items, and the appraiser accepted 3 of them. Give the effectiveness, miss rate and false alarm rate.
Show answer
Effectiveness is 36 / 40 = 0.90. Miss rate is 3 / 10 = 0.30. There are 4 wrong ratings in total, and 3 of them are misses, so 1 is a false alarm. There are 30 good items, so the false alarm rate is 1 / 30 = 0.033. Despite 90% effectiveness, the 30% miss rate is likely unacceptable because defects reach the customer.