public void print ( final PrintStream out , final ICodingAnnotationStudy study ) { if ( study . getRaterCount ( ) > 2 ) throw new IllegalArgumentException ( "Contingency tables are only applicable for two rater studies." ) ; //TODO: measure length of cats. maybe cut them. Map < Object , Integer > categories = new LinkedHashMap < Object , Integer > ( ) ; for ( Object cat : study . getCategories ( ) ) categories . put ( cat , categories . size ( ) ) ; int [ ] [ ] frequencies = new int [ study . getCategoryCount ( ) ] [ study . getCategoryCount ( ) ] ; for ( ICodingAnnotationItem item : study . getItems ( ) ) { int cat1 = categories . get ( item . getUnit ( 0 ) . getCategory ( ) ) ; int cat2 = categories . get ( item . getUnit ( 1 ) . getCategory ( ) ) ; frequencies [ cat1 ] [ cat2 ] ++ ; } final String DIVIDER = "\t" ; for ( Object category : categories . keySet ( ) ) out . print ( DIVIDER + category ) ; out . print ( DIVIDER + "Σ") ; out . println ( ) ; int i = 0 ; int [ ] colSum = new int [ study . getCategoryCount ( ) ] ; for ( Object category1 : categories . keySet ( ) ) { out . print ( category1 ) ; int rowSum = 0 ; for ( int j = 0 ; j < categories . size ( ) ; j ++ ) { out . printf ( DIVIDER + "%3d" , frequencies [ i ] [ j ] ) ; rowSum += frequencies [ i ] [ j ] ; colSum [ j ] += frequencies [ i ] [ j ] ; } out . printf ( DIVIDER + "%3d" , rowSum ) ; out . println ( ) ; i ++ ; } out . print ( "Σ") ; int rowSum = 0 ; for ( int j = 0 ; j < categories . size ( ) ; j ++ ) { out . printf ( DIVIDER + "%3d" , colSum [ j ] ) ; rowSum += colSum [ j ] ; } out . printf ( DIVIDER + "%3d" , rowSum ) ; out . println ( ) ; }
Print the contingency matrix for the given coding study .