    1   package baseCode.math.metaanalysis;
    2
    3   import junit.framework.TestCase;
    4   import baseCode.math.metaanalysis.CorrelationEffectMetaAnalysis;
    5   import cern.colt.list.DoubleArrayList;
    6
    7   /***
    8    * Tests based on Cooper and Hedges. Values recomputed by hand in some cases to fix roundoff error in the textbook.
    9    * <hr>
    10   * <p>
    11   * Copyright (c) 2004 Columbia University
    12   *
    13   * @author pavlidis
    14   * @version $Id: TestCorrelationEffectMetaAnalysis.java,v 1.2 2005/04/07 20:48:52 pavlidis Exp $
    15   */
    16  public class TestCorrelationEffectMetaAnalysis extends TestCase {
    17
    18     CorrelationEffectMetaAnalysis zf;
    19     CorrelationEffectMetaAnalysis zr;
    20     CorrelationEffectMetaAnalysis uf;
    21     CorrelationEffectMetaAnalysis ur;
    22
    23     DoubleArrayList ds3n;
    24     DoubleArrayList ds3r;
    25
    26     /*
    27      * @see TestCase#setUp()
    28      */
    29     protected void setUp() throws Exception {
    30        super.setUp();
    31
    32        // From Appendix A of Cooper and Hedges: Data Set III.
    33        ds3n = new DoubleArrayList( new double[] {
    34              10, 20, 13, 22, 28, 12, 12, 36, 19, 12, 36, 75, 33, 121, 37, 14,
    35              40, 16, 14, 20
    36        } );
    37
    38        ds3r = new DoubleArrayList( new double[] {
    39              0.68, 0.56, 0.23, 0.64, 0.49, -0.04, 0.49, 0.33, 0.58, 0.18, -0.11,
    40              0.27, 0.26, 0.40, 0.49, 0.51, 0.40, 0.34, 0.42, 0.16
    41        } );
    42
    43        zf = new CorrelationEffectMetaAnalysis( true, true );
    44        zr = new CorrelationEffectMetaAnalysis( false, true );
    45        uf = new CorrelationEffectMetaAnalysis( true, false );
    46        ur = new CorrelationEffectMetaAnalysis( false, false );
    47     }
    48
    49     /*
    50      * @see TestCase#tearDown()
    51      */
    52     protected void tearDown() throws Exception {
    53        super.tearDown();
    54     }
    55
    56     public void testRunZFVar() {
    57        zf.run( ds3r, ds3n );
    58        double actualReturn = zf.getV();
    59        double expectedReturn = 0.0019;
    60        assertEquals( "return value", expectedReturn, actualReturn, 0.001 );
    61     }
    62
    63     public void testRunZFEffect() {
    64        zf.run( ds3r, ds3n );
    65        double actualReturn = zf.getE();
    66        double expectedReturn = 0.379;
    67        assertEquals( "return value", expectedReturn, actualReturn, 0.01 );
    68     }
    69
    70     public void testRunZFZscore() {
    71        zf.run( ds3r, ds3n );
    72        double actualReturn = zf.getZ();
    73        double expectedReturn = 8.748; // the value in the book (8.64) suffers from some serious roundoff errors.
    74        assertEquals( "return value", expectedReturn, actualReturn, 0.01 );
    75     }
    76
    77     public void testRunUFVar() {
    78        uf.run( ds3r, ds3n );
    79
    80        double actualReturn = uf.getV();
    81        double expectedReturn = 0.00118;
    82
    83        assertEquals( "return value", expectedReturn, actualReturn, 0.0001 );
    84     }
    85
    86     public void testRunUFEffect() {
    87        uf.run( ds3r, ds3n );
    88
    89        double actualReturn = uf.getE();
    90
    91        double expectedReturn = 0.39779;
    92        assertEquals( "return value", expectedReturn, actualReturn, 0.001 );
    93     }
    94
    95     public void testRunUFZscore() {
    96        uf.run( ds3r, ds3n );
    97
    98        double actualReturn = uf.getZ();
    99
    100       double expectedReturn = 11.56;
    101       assertEquals( "return value", expectedReturn, actualReturn, 0.01 );
    102    }
    103
    104
    105    public void testRunZRQval() {
    106       zr.run( ds3r, ds3n );
    107       double actualReturn = zr.getQ();
    108       double expectedReturn = 20.94;
    109       assertEquals( "return value", expectedReturn, actualReturn, 0.1 );
    110    }
    111
    112    public void testRunZRBSV() {
    113       zr.run( ds3r, ds3n );
    114       double actualReturn = zr.getBsv();
    115       double expectedReturn = 0.0041;
    116       assertEquals( "return value", expectedReturn, actualReturn, 0.0001 );
    117    }
    118
    119
    120
    121 //   public void testRunZRZscore() {
    122 //      zr.run( ds3r, ds3n );
    123 //      double actualReturn = zr.getZ();
    124 //      double expectedReturn = 0;
    125 //      assertEquals( "return value", expectedReturn, actualReturn, 0.00001 );
    126 //   }
    127
    128
    129 //
    130    public void testRunURBSV() {
    131       ur.run( ds3r, ds3n );
    132       double actualReturn = ur.getBsv();
    133       double expectedReturn = 0.0085;
    134       assertEquals( "return value", expectedReturn, actualReturn, 0.0001 );
    135    }
    136 //
    137 //   public void testRunURZscore() {
    138 //      ur.run( ds3r, ds3n );
    139 //      double actualReturn = ur.getZ();
    140 //      double expectedReturn = 0;
    141 //      assertEquals( "return value", expectedReturn, actualReturn, 0.0001 );
    142 //   }
    143
    144 }