/* Written for @bky JMP Blog Post Jan 5, 2019 1:48 pm title Weighted Kappas. References used for this script are: https://www.medcalc.org/manual/kappa.php https://en.wikipedia.org/wiki/Cohen%27s_kappa and verified with example on slides 56-58 01/07/2019 ver1 - tested on JMP14.2 does not have calculated errors and Confidence Intervals */ Names default to Here(1); f1 = Function({dtab}, print(dtab << get name); dt = Data Table( dtab << get Name); dt << journal; //now do the calculations idx = dt << get rows where(:Cell =="Count"); ccols = dt << get column names("Continuous", "string"); cmat = dt[idx,ccols]; idx = dt << get rows where(:Cell =="Expected"); emat = dt[idx,ccols]; tot = sum(cmat); xmat = cmat/tot ; mmat = emat/tot; nr= nrow(xmat); nc = ncol(xmat); if(nr!=nc, Throw("Wrong Dimensionality") ); wk = Identity(nr); pk0 = 0; pke = 0; pl0 = 0; ple = 0; pq0 = 0; pqe = 0; for(i=1, i<=nr, i++, for(j=1, j<=nr, j++, pk0 += xmat[i,j]*wk[i,j]; pke += mmat[i,j]*wk[i,j]; pl0 += xmat[i,j]* ( 1 - abs(i-j)/(nr - 1) ); ple += mmat[i,j]* ( 1 - abs(i-j)/(nr - 1) ); pq0 += xmat[i,j]* ( 1 - ( (i-j)/(nr - 1) )^2 ); pqe += mmat[i,j]* ( 1 - ( (i-j)/(nr - 1) )^2 ); ) ); k = (pk0 - pke) / (1 - pke); kl = (pl0 - ple) / (1 - ple); kq = (pq0 - pqe) / (1 - pqe); show(k, kl, kq); //add the calculation to the Contingency Report Caption( " kappa = " || char(k,5,3) ||" kL = " || char(kl, 5, 3) ); ); //end f1 dt0 = Current Data Table(); tsub = subscribe to data table list(, On Open(f1)); Contingency( Contingency Table( Expected( 1 ) ), Agreement Statistic( 1 ), << Make Into Data Table ); Unsubscribe to Data Table List(tsub);