View Javadoc

    1   package baseCode.math.metaanalysis;
    2
    3   import cern.colt.list.DoubleArrayList;
    4   import cern.jet.stat.Descriptive;
    5   import cern.jet.stat.Probability;
    6
    7   /***
    8    * Meta-analysis methods from chapter 18 of Cooper and Hedges, sections 2.1 and 3.1
    9    * <p>
    10   * These methods use the standardized mean difference statistic d:
    11   *
    12   * <pre>
    13   * d_i = ( X_i &circ; t - X_i &circ; c ) / s_i
    14   * </pre>
    15   *
    16   * where X <sub>i </sub> <sup>t </sup> is the mean of the treatment group in the ith study, X <sub>i </sub> <sup>ct
    17   * </sup> is the mean of the control group in the treatment group in the ith study, and s <sub>i </sub> is the pooled
    18   * standard deviation of the two groups. Essentially this is a t statistic.
    19   * <hr>
    20   * <p>
    21   * Copyright (c) 2004 Columbia University
    22   *
    23   * @author pavlidis
    24   * @version $Id: MeanDifferenceMetaAnalysis.java,v 1.1 2005/01/04 00:32:27 pavlidis Exp $
    25   */
    26  public class MeanDifferenceMetaAnalysis extends MetaAnalysis {
    27
    28     private boolean fixed = true;
    29
    30     private double z; // z score
    31     private double p; // probability
    32     private double q; // q-score;
    33     private double e; // unconditional effect;
    34     private double v; // unconditional variance;
    35     private double n; // total sample size
    36     private double bsv; // between-studies variance component;
    37
    38     /***
    39      * @param b
    40      */
    41     public MeanDifferenceMetaAnalysis( boolean fixed ) {
    42        this.fixed = fixed;
    43     }
    44
    45     public double run( DoubleArrayList effects, DoubleArrayList controlSizes,
    46           DoubleArrayList testSizes ) {
    47        DoubleArrayList weights;
    48        DoubleArrayList conditionalVariances;
    49        this.n = Descriptive.sum( controlSizes ) + Descriptive.sum( testSizes );
    50
    51        conditionalVariances = samplingVariances( effects, controlSizes, testSizes );
    52        weights = metaFEWeights( conditionalVariances );
    53        this.q = super.qStatistic( effects, conditionalVariances, super
    54              .weightedMean( effects, weights ) );
    55
    56        if ( !fixed ) { // adjust the conditional variances and weights.
    57           this.bsv = metaREVariance( effects, conditionalVariances, weights );
    58
    59           for ( int i = 0; i < conditionalVariances.size(); i++ ) {
    60              conditionalVariances.setQuick( i, conditionalVariances.getQuick( i )
    61                    + bsv );
    62           }
    63
    64           weights = metaFEWeights( conditionalVariances );
    65        }
    66
    67        this.e = super.weightedMean( effects, weights );
    68        this.v = super.metaVariance( conditionalVariances );
    69        this.z = Math.abs( e ) / Math.sqrt( v );
    70        this.p = Probability.errorFunctionComplemented( z );
    71        return p;
    72     }
    73
    74
    75     /***
    76      *
    77      * @param effects
    78      * @param cvar Conditional variances.
    79      * @return
    80      */
    81     public double run( DoubleArrayList effects,
    82           DoubleArrayList cvar ) {
    83        DoubleArrayList weights;
    84        DoubleArrayList conditionalVariances;
    85     //   this.n = Descriptive.sum( controlSizes ) + Descriptive.sum( testSizes );
    86
    87        conditionalVariances = cvar.copy();
    88        weights = metaFEWeights( conditionalVariances );
    89        this.q = super.qStatistic( effects, conditionalVariances, super
    90              .weightedMean( effects, weights ) );
    91
    92        if ( !fixed ) { // adjust the conditional variances and weights.
    93           this.bsv = metaREVariance( effects, conditionalVariances, weights );
    94
    95           for ( int i = 0; i < conditionalVariances.size(); i++ ) {
    96              conditionalVariances.setQuick( i, conditionalVariances.getQuick( i )
    97                    + bsv );
    98           }
    99
    100          weights = metaFEWeights( conditionalVariances );
    101       }
    102
    103       this.e = super.weightedMean( effects, weights );
    104       this.v = super.metaVariance( conditionalVariances );
    105       this.z = Math.abs( e ) / Math.sqrt( v );
    106       this.p = Probability.errorFunctionComplemented( z );
    107       return p;
    108    }
    109
    110
    111
    112    /***
    113     * CH eqn 18-7
    114     *
    115     * @param d effect size
    116     * @param nC number of samples in control group
    117     * @param nT number of samples in test group
    118     * @return
    119     */
    120    public double samplingVariance( double d, double nC, double nT ) {
    121       return ( nT + nC ) / ( nT * nC ) + d * d / 2 * ( nT + nC );
    122    }
    123
    124    /***
    125     * Run eqn 18-7 on a set of effect sizes.
    126     *
    127     * @param effects
    128     * @param controlSizes
    129     * @param testSizes
    130     * @return
    131     */
    132    public DoubleArrayList samplingVariances( DoubleArrayList effects,
    133          DoubleArrayList controlSizes, DoubleArrayList testSizes ) {
    134       if ( effects.size() != controlSizes.size()
    135             || controlSizes.size() != testSizes.size() )
    136             throw new IllegalArgumentException( "Unequal sample sizes." );
    137
    138       DoubleArrayList answer = new DoubleArrayList( controlSizes.size() );
    139       for ( int i = 0; i < controlSizes.size(); i++ ) {
    140          answer.add( samplingVariance( effects.getQuick( i ), controlSizes
    141                .getQuick( i ), testSizes.getQuick( i ) ) );
    142       }
    143       return answer;
    144    }
    145
    146
    147    public double getP() {
    148       return p;
    149    }
    150
    151    public double getQ() {
    152       return q;
    153    }
    154
    155    public double getZ() {
    156       return z;
    157    }
    158
    159    public double getE() {
    160       return e;
    161    }
    162
    163    public double getV() {
    164       return v;
    165    }
    166
    167    public double getN() {
    168       return n;
    169    }
    170
    171    public double getBsv() {
    172       return bsv;
    173    }
    174
    175 }