    1   package baseCode.math.metaanalysis;
    2
    3   import junit.framework.TestCase;
    4   import baseCode.math.metaanalysis.MeanDifferenceMetaAnalysis;
    5   import cern.colt.list.DoubleArrayList;
    6
    7   /***
    8    * <hr>
    9    * <p>
    10   * Copyright (c) 2004 Columbia University
    11   *
    12   * @author pavlidis
    13   * @version $Id: TestMeanDifferenceMetaAnalysis.java,v 1.1 2005/03/17 13:58:42 pavlidis Exp $
    14   */
    15  public class TestMeanDifferenceMetaAnalysis extends TestCase {
    16
    17     MeanDifferenceMetaAnalysis uf;
    18     MeanDifferenceMetaAnalysis ur;
    19
    20     DoubleArrayList ds2nc;
    21     DoubleArrayList ds2cv;
    22     DoubleArrayList ds2d;
    23
    24  //   DenseDoubleMatrix2DNamed catheter;
    25  //   DoubleArrayList catheterNumT;
    26  //   DoubleArrayList catheterNumC;
    27
    28     /*
    29      * @see TestCase#setUp()
    30      */
    31     protected void setUp() throws Exception {
    32        super.setUp();
    33
    34        // data set 2 from Appendix A of Cooper and Hedges. They give us the conditoinal variances (standard errors)
    35        // instead of the raw ns.
    36
    37        // these are actually the standard errors (sqrt var)
    38        ds2cv = new DoubleArrayList( new double[] {
    39              0.125, 0.147, 0.167, 0.373, 0.369, 0.103, 0.103, 0.220, 0.164,
    40              0.251, 0.302, 0.223, 0.289, 0.290, 0.159, 0.167, 0.139, 0.094,
    41              0.174
    42        } );
    43        // convert into variances.
    44        for ( int i = 0; i < ds2cv.size(); i++ ) {
    45           ds2cv.setQuick( i, Math.pow( ds2cv.getQuick( i ), 2 ) );
    46        }
    47
    48        ds2d = new DoubleArrayList( new double[] {
    49              0.03, 0.12, -0.14, 1.18, 0.26, -0.06, -0.02, -0.32, 0.27, 0.80,
    50              0.54, 0.18, -0.02, 0.23, -0.18, -0.06, 0.3, 0.07, -0.07
    51        } );
    52
    53        uf = new MeanDifferenceMetaAnalysis( true );
    54        ur = new MeanDifferenceMetaAnalysis( false );
    55
    56    //    DoubleMatrixReader f = new DoubleMatrixReader();
    57
    58        // Catheter data set swiped from rmeta.
    59        //      Name : Name of principal author
    60        //      n.trt : number of coated catheters
    61        //      n.ctrl : number of standard catheters
    62        //      col.trt : number of coated catheters colonised
    63        //                   by bacteria
    64        //      col.ctrl : number of standard catheters colonised
    65        //                   by bacteria
    66        //      inf.trt : number of coated catheters resulting in
    67        //                   bloodstream infection
    68        //      inf.ctrl : number of standard catheters resulting in
    69        //                   bloodstream infection
    70        //
    71        //      Veenstra D et al (1998) "Efficacy of Antiseptic Impregnated
    72        //      Central Venous Catheters in Preventing Nosocomial Infections: A
    73        //      Meta-analysis" JAMA 281:261-267
    74
    75  //      catheter = ( DenseDoubleMatrix2DNamed ) f.read( AbstractTestFilter.class
    76  //            .getResourceAsStream( "/data/catheter.txt" ) );
    77  //
    78  //      catheterNumT = new DoubleArrayList(catheter.getColByName("n.trt"));
    79  //      catheterNumC = new DoubleArrayList(catheter.getColByName("n.ctrl"));
    80
    81
    82     }
    83
    84     /*
    85      * @see TestCase#tearDown()
    86      */
    87     protected void tearDown() throws Exception {
    88        super.tearDown();
    89     }
    90
    91     public void testRunFixedVar() {
    92        uf.run( ds2d, ds2cv );
    93        double actualReturn = uf.getV();
    94        double expectedReturn = 0.00133;
    95        assertEquals( "return value", expectedReturn, actualReturn, 0.0001 );
    96     }
    97
    98     public void testRunFixedE() {
    99        uf.run( ds2d, ds2cv );
    100       double actualReturn = uf.getE();
    101       double expectedReturn = 0.06;
    102       assertEquals( "return value", expectedReturn, actualReturn, 0.001 );
    103    }
    104
    105    public void testRunFixedQ() {
    106       uf.run( ds2d, ds2cv );
    107       double actualReturn = uf.getQ();
    108       double expectedReturn = 35.83;
    109       assertEquals( "return value", expectedReturn, actualReturn, 0.01 );
    110    }
    111
    112    public void testRunFixedZ() {
    113       uf.run( ds2d, ds2cv );
    114       double actualReturn = uf.getZ();
    115       double expectedReturn = 1.65;
    116       assertEquals( "return value", expectedReturn, actualReturn, 0.01 );
    117    }
    118
    119    // note we are using the weighted variance model of 18-3.
    120    public void testRunRandomVar() {
    121       ur.run( ds2d, ds2cv );
    122       double actualReturn = ur.getV();
    123       double expectedReturn = 0.0031136;
    124       assertEquals( "return value", expectedReturn, actualReturn, 0.0001 );
    125    }
    126
    127    public void testRunRandomE() {
    128       ur.run( ds2d, ds2cv );
    129       double actualReturn = ur.getE();
    130       double expectedReturn = 0.0893;
    131       assertEquals( "return value", expectedReturn, actualReturn, 0.001 );
    132    }
    133
    134    public void testRunRandomBSV() {
    135       ur.run( ds2d, ds2cv );
    136       double actualReturn = ur.getBsv();
    137       double expectedReturn = 0.026; // using eqn 18-23
    138       assertEquals( "return value", expectedReturn, actualReturn, 0.001 );
    139    }
    140
    141    public void testRunRandomZ() {
    142       ur.run( ds2d, ds2cv );
    143       double actualReturn = ur.getZ();
    144       double expectedReturn = 1.60;
    145       assertEquals( "return value", expectedReturn, actualReturn, 0.01 );
    146    }
    147
    148 }