|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| MeanDifferenceMetaAnalysis.java | 33.3% | 45.7% | 58.3% | 45.7% |
|
||||||||||||||
| 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 ˆ t - X_i ˆ 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 | 16 |
public MeanDifferenceMetaAnalysis( boolean fixed ) { |
| 42 | 16 |
this.fixed = fixed;
|
| 43 |
} |
|
| 44 |
|
|
| 45 | 0 |
public double run( DoubleArrayList effects, DoubleArrayList controlSizes, |
| 46 |
DoubleArrayList testSizes ) {
|
|
| 47 | 0 |
DoubleArrayList weights; |
| 48 | 0 |
DoubleArrayList conditionalVariances; |
| 49 | 0 |
this.n = Descriptive.sum( controlSizes ) + Descriptive.sum( testSizes );
|
| 50 |
|
|
| 51 | 0 |
conditionalVariances = samplingVariances( effects, controlSizes, testSizes ); |
| 52 | 0 |
weights = metaFEWeights( conditionalVariances ); |
| 53 | 0 |
this.q = super.qStatistic( effects, conditionalVariances, super |
| 54 |
.weightedMean( effects, weights ) ); |
|
| 55 |
|
|
| 56 | 0 |
if ( !fixed ) { // adjust the conditional variances and weights. |
| 57 | 0 |
this.bsv = metaREVariance( effects, conditionalVariances, weights );
|
| 58 |
|
|
| 59 | 0 |
for ( int i = 0; i < conditionalVariances.size(); i++ ) { |
| 60 | 0 |
conditionalVariances.setQuick( i, conditionalVariances.getQuick( i ) |
| 61 |
+ bsv ); |
|
| 62 |
} |
|
| 63 |
|
|
| 64 | 0 |
weights = metaFEWeights( conditionalVariances ); |
| 65 |
} |
|
| 66 |
|
|
| 67 | 0 |
this.e = super.weightedMean( effects, weights ); |
| 68 | 0 |
this.v = super.metaVariance( conditionalVariances ); |
| 69 | 0 |
this.z = Math.abs( e ) / Math.sqrt( v );
|
| 70 | 0 |
this.p = Probability.errorFunctionComplemented( z );
|
| 71 | 0 |
return p;
|
| 72 |
} |
|
| 73 |
|
|
| 74 |
|
|
| 75 |
/**
|
|
| 76 |
*
|
|
| 77 |
* @param effects
|
|
| 78 |
* @param cvar Conditional variances.
|
|
| 79 |
* @return
|
|
| 80 |
*/
|
|
| 81 | 8 |
public double run( DoubleArrayList effects, |
| 82 |
DoubleArrayList cvar ) {
|
|
| 83 | 8 |
DoubleArrayList weights; |
| 84 | 8 |
DoubleArrayList conditionalVariances; |
| 85 |
// this.n = Descriptive.sum( controlSizes ) + Descriptive.sum( testSizes );
|
|
| 86 |
|
|
| 87 | 8 |
conditionalVariances = cvar.copy(); |
| 88 | 8 |
weights = metaFEWeights( conditionalVariances ); |
| 89 | 8 |
this.q = super.qStatistic( effects, conditionalVariances, super |
| 90 |
.weightedMean( effects, weights ) ); |
|
| 91 |
|
|
| 92 | 8 |
if ( !fixed ) { // adjust the conditional variances and weights. |
| 93 | 4 |
this.bsv = metaREVariance( effects, conditionalVariances, weights );
|
| 94 |
|
|
| 95 | 4 |
for ( int i = 0; i < conditionalVariances.size(); i++ ) { |
| 96 | 76 |
conditionalVariances.setQuick( i, conditionalVariances.getQuick( i ) |
| 97 |
+ bsv ); |
|
| 98 |
} |
|
| 99 |
|
|
| 100 | 4 |
weights = metaFEWeights( conditionalVariances ); |
| 101 |
} |
|
| 102 |
|
|
| 103 | 8 |
this.e = super.weightedMean( effects, weights ); |
| 104 | 8 |
this.v = super.metaVariance( conditionalVariances ); |
| 105 | 8 |
this.z = Math.abs( e ) / Math.sqrt( v );
|
| 106 | 8 |
this.p = Probability.errorFunctionComplemented( z );
|
| 107 | 8 |
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 | 0 |
public double samplingVariance( double d, double nC, double nT ) { |
| 121 | 0 |
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 | 0 |
public DoubleArrayList samplingVariances( DoubleArrayList effects,
|
| 133 |
DoubleArrayList controlSizes, DoubleArrayList testSizes ) {
|
|
| 134 | 0 |
if ( effects.size() != controlSizes.size()
|
| 135 |
|| controlSizes.size() != testSizes.size() ) |
|
| 136 | 0 |
throw new IllegalArgumentException( "Unequal sample sizes." ); |
| 137 |
|
|
| 138 | 0 |
DoubleArrayList answer = new DoubleArrayList( controlSizes.size() );
|
| 139 | 0 |
for ( int i = 0; i < controlSizes.size(); i++ ) { |
| 140 | 0 |
answer.add( samplingVariance( effects.getQuick( i ), controlSizes |
| 141 |
.getQuick( i ), testSizes.getQuick( i ) ) ); |
|
| 142 |
} |
|
| 143 | 0 |
return answer;
|
| 144 |
} |
|
| 145 |
|
|
| 146 |
|
|
| 147 | 0 |
public double getP() { |
| 148 | 0 |
return p;
|
| 149 |
} |
|
| 150 |
|
|
| 151 | 1 |
public double getQ() { |
| 152 | 1 |
return q;
|
| 153 |
} |
|
| 154 |
|
|
| 155 | 2 |
public double getZ() { |
| 156 | 2 |
return z;
|
| 157 |
} |
|
| 158 |
|
|
| 159 | 2 |
public double getE() { |
| 160 | 2 |
return e;
|
| 161 |
} |
|
| 162 |
|
|
| 163 | 2 |
public double getV() { |
| 164 | 2 |
return v;
|
| 165 |
} |
|
| 166 |
|
|
| 167 | 0 |
public double getN() { |
| 168 | 0 |
return n;
|
| 169 |
} |
|
| 170 |
|
|
| 171 | 1 |
public double getBsv() { |
| 172 | 1 |
return bsv;
|
| 173 |
} |
|
| 174 |
|
|
| 175 |
} |
|
||||||||||