// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/ICategorySpecificAgreement.java
// public interface ICategorySpecificAgreement
// {
//     /**
//      * Calculates the inter-rater agreement for the given category.
//      * 
//      * @see ICategorySpecificAgreement
//      */
//     /*
//      * TODO @throws NullPointerException if the study is null or the given category is null.
//      * 
//      * @throws ArrayIndexOutOfBoundsException if the study does not contain the given category.
//      * 
//      * @throws ArithmeticException if the study does not contain annotations for the given category.
//      */
//     public double calculateCategoryAgreement(final Object category);
// }


import java.util.Iterator;
import org.dkpro.statistics.agreement.ICategorySpecificAgreement;
import junit.framework.TestCase;
/*
 * Copyright 2014
 * Ubiquitous Knowledge Processing (UKP) Lab
 * Technische Universität Darmstadt
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.dkpro.statistics.agreement.coding;




/**
 * Tests based on Fleiss (1971) for measuring {@link FleissKappaAgreement}.<br>
 * <br>
 * References:
 * <ul>
 * <li>Fleiss, J.L.: Measuring nominal scale agreement among many raters. Psychological Bulletin
 * 76(5):378-381, 1971.</li>
 * </ul>
 * 
 * @author Christian M. Meyer
 */
public class Fleiss1971Test
    extends TestCase
{

    
    public void testAgreement()
    {
        ICodingAnnotationStudy study = createExample();
        assertEquals(30, study.getItemCount());

        FleissKappaAgreement kappa = new FleissKappaAgreement(study);
        assertEquals(0.5556, kappa.calculateObservedAgreement(), 0.001);
        assertEquals(0.2201, kappa.calculateExpectedAgreement(), 0.001);
        double agreement = kappa.calculateAgreement();
        assertEquals(0.430, agreement, 0.001);

        // Var = 0.000759 = 2/n*m(m-1) * (AE - (2m-3)AE^2 + 2(m-2)AE / (1-AE)^2)
        // SE = 0.028
        // TODO
        /*
         * double se = raw.standardError(agreement); double[] ci = raw.confidenceInterval(agreement,
         * se, RawAgreement.CONFIDENCE_95); assertEquals(0.028, se, 0.001); assertEquals(0.610,
         * ci[0], 0.001); assertEquals(0.789, ci[1], 0.001);
         */
    }

    
    public void testCategoryAgreement()
    {
        ICodingAnnotationStudy study = createExample();

// Path: dkpro-statistics-agreement/src/main/java/org/dkpro/statistics/agreement/ICategorySpecificAgreement.java
// public interface ICategorySpecificAgreement
// {
//     /**
//      * Calculates the inter-rater agreement for the given category.
//      * 
//      * @see ICategorySpecificAgreement
//      */
//     /*
//      * TODO @throws NullPointerException if the study is null or the given category is null.
//      * 
//      * @throws ArrayIndexOutOfBoundsException if the study does not contain the given category.
//      * 
//      * @throws ArithmeticException if the study does not contain annotations for the given category.
//      */
//     public double calculateCategoryAgreement(final Object category);
// }


// Path: dkpro-statistics-agreement/src/test/java/org/dkpro/statistics/agreement/coding/Fleiss1971Test.java
import java.util.Iterator;
import org.dkpro.statistics.agreement.ICategorySpecificAgreement;
import junit.framework.TestCase;

/*
 * Copyright 2014
 * Ubiquitous Knowledge Processing (UKP) Lab
 * Technische Universität Darmstadt
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.dkpro.statistics.agreement.coding;




/**
 * Tests based on Fleiss (1971) for measuring {@link FleissKappaAgreement}.<br>
 * <br>
 * References:
 * <ul>
 * <li>Fleiss, J.L.: Measuring nominal scale agreement among many raters. Psychological Bulletin
 * 76(5):378-381, 1971.</li>
 * </ul>
 * 
 * @author Christian M. Meyer
 */
public class Fleiss1971Test
    extends TestCase
{

    
    public void testAgreement()
    {
        ICodingAnnotationStudy study = createExample();
        assertEquals(30, study.getItemCount());

        FleissKappaAgreement kappa = new FleissKappaAgreement(study);
        assertEquals(0.5556, kappa.calculateObservedAgreement(), 0.001);
        assertEquals(0.2201, kappa.calculateExpectedAgreement(), 0.001);
        double agreement = kappa.calculateAgreement();
        assertEquals(0.430, agreement, 0.001);

        // Var = 0.000759 = 2/n*m(m-1) * (AE - (2m-3)AE^2 + 2(m-2)AE / (1-AE)^2)
        // SE = 0.028
        // TODO
        /*
         * double se = raw.standardError(agreement); double[] ci = raw.confidenceInterval(agreement,
         * se, RawAgreement.CONFIDENCE_95); assertEquals(0.028, se, 0.001); assertEquals(0.610,
         * ci[0], 0.001); assertEquals(0.789, ci[1], 0.001);
         */
    }

    
    public void testCategoryAgreement()
    {
        ICodingAnnotationStudy study = createExample();

        ICategorySpecificAgreement catAgreement = new FleissKappaAgreement(study);