CROSSTABS: Fixed the reporting of the standard error of Cohen's Kappa
authorJohn Darrington <john@darrington.wattle.id.au>
Fri, 26 Jun 2015 09:59:07 +0000 (11:59 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Fri, 26 Jun 2015 10:02:02 +0000 (12:02 +0200)
The Standard error assuming the null hypothesis was being reported
when the standard error NOT assuming the null hypothesis ought to
have been.

Thanks to Joanne Ingram <joanne.ingram@ed.ac.uk> for reporting this
problem, and to Douglas Bonett <dgbonett@ucsc.edu> for explaining
how to fix it.

src/language/stats/crosstabs.q
tests/language/stats/crosstabs.at

index 6e6cb20d9750b2c517c1d886a107f639db394c4e..ab73f96ad5bea6b37bb481b488b39fdf33c79202 100644 (file)
@@ -2600,6 +2600,7 @@ calc_symmetric (struct crosstabs_proc *proc, struct pivot_table *pt,
   /* Cohen's kappa. */
   if (proc->statistics & (1u << CRS_ST_KAPPA) && pt->ns_rows == pt->ns_cols)
     {
+      double ase_under_h0;
       double sum_fii, sum_rici, sum_fiiri_ci, sum_fijri_ci2, sum_riciri_ci;
       int i, j;
 
@@ -2628,24 +2629,23 @@ calc_symmetric (struct crosstabs_proc *proc, struct pivot_table *pt,
 
       v[8] = (pt->total * sum_fii - sum_rici) / (pow2 (pt->total) - sum_rici);
 
-      ase[8] = sqrt ((pow2 (pt->total) * sum_rici
-                     + sum_rici * sum_rici
-                     - pt->total * sum_riciri_ci)
-                    / (pt->total * (pow2 (pt->total) - sum_rici) * (pow2 (pt->total) - sum_rici)));
-#if 0
-      t[8] = v[8] / sqrt (pt->total * (((sum_fii * (pt->total - sum_fii))
+      ase_under_h0 = sqrt ((pow2 (pt->total) * sum_rici
+                           + sum_rici * sum_rici
+                           - pt->total * sum_riciri_ci)
+                          / (pt->total * (pow2 (pt->total) - sum_rici) * (pow2 (pt->total) - sum_rici)));
+      
+      ase[8] = sqrt (pt->total * (((sum_fii * (pt->total - sum_fii))
                                / pow2 (pow2 (pt->total) - sum_rici))
                               + ((2. * (pt->total - sum_fii)
                                   * (2. * sum_fii * sum_rici
                                      - pt->total * sum_fiiri_ci))
-                                 / cube (pow2 (pt->total) - sum_rici))
+                                 / pow3 (pow2 (pt->total) - sum_rici))
                               + (pow2 (pt->total - sum_fii)
                                  * (pt->total * sum_fijri_ci2 - 4.
                                     * sum_rici * sum_rici)
                                  / pow4 (pow2 (pt->total) - sum_rici))));
-#else
-      t[8] = v[8] / ase[8];
-#endif
+
+      t[8] = v[8] / ase_under_h0;
     }
 
   return 1;
index d2e9e8ff179baa72a653b5287792d53a8d834668..559a13355ff970323782a52e692c643ebf905454 100644 (file)
@@ -1442,6 +1442,51 @@ Ordinal by Ordinal,Somers' d,Symmetric,.209,,3.338,.001
 ])
 AT_CLEANUP
 
+AT_SETUP([CROSSTABS Cohens Kappa])
+
+dnl Example from Wood J. M. 
+dnl "Understanding and Computing Cohen's Kappa: A Tutorial"
+dnl WebPsychEmpiricist. Oct 3 2007
+AT_DATA([kappa.sps], [dnl
+SET FORMAT=F8.3.
+
+data list notable list /p1 * p2 * w *.
+begin data.
+0 0 18
+1 0 1
+0 1 1
+end data.
+
+weight by w.
+
+crosstabs /table = p1 by p2
+       statistics = kappa
+       .
+])
+
+AT_CHECK([pspp -O format=csv kappa.sps], [0], [dnl
+Table: Summary.
+,Cases,,,,,
+,Valid,,Missing,,Total,
+,N,Percent,N,Percent,N,Percent
+p1 * p2,20.000,100.0%,.000,0.0%,20.000,100.0%
+
+Table: p1 * p2 [[count]].
+,p2,,
+p1,.000,1.000,Total
+.000,18.000,1.000,19.000
+1.000,1.000,.000,1.000
+Total,19.000,1.000,20.000
+
+Table: Symmetric measures.
+Category,Statistic,Value,Asymp. Std. Error,Approx. T,Approx. Sig.
+Measure of Agreement,Kappa,-.053,.037,-.235,
+N of Valid Cases,,20.000,,,
+])
+
+AT_CLEANUP
+
+
 AT_SETUP([CROSSTABS many statistics])
 AT_DATA([crosstabs.sps], [dnl
 SET FORMAT=F8.4.