From 3fe5cc7ed8d6fd1951f016a794415a00ea4059a2 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Fri, 26 Jun 2015 11:59:07 +0200 Subject: [PATCH] CROSSTABS: Fixed the reporting of the standard error of Cohen's Kappa 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 for reporting this problem, and to Douglas Bonett for explaining how to fix it. --- src/language/stats/crosstabs.q | 20 +++++++------- tests/language/stats/crosstabs.at | 45 +++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 10 deletions(-) diff --git a/src/language/stats/crosstabs.q b/src/language/stats/crosstabs.q index 6e6cb20d97..ab73f96ad5 100644 --- a/src/language/stats/crosstabs.q +++ b/src/language/stats/crosstabs.q @@ -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; diff --git a/tests/language/stats/crosstabs.at b/tests/language/stats/crosstabs.at index d2e9e8ff17..559a13355f 100644 --- a/tests/language/stats/crosstabs.at +++ b/tests/language/stats/crosstabs.at @@ -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. -- 2.30.2