Beispiel #1
0
int DL(gsl_vector * esVector, gsl_vector * varVector, 
	gsl_vector * metaResultsVector , gsl_combination * comb, 
	const ST_double sumOfFixedWeights,
	const ST_double sumOfFixedWeights2 ) {
	
	ST_double tau2_DL;
	ST_double sumOfRandomDLWeights = 0.0;
	ST_double sumOfRandomDLWeightedEffects = 0.0;
	ST_double sumOfRandomDLWeightedSquares = 0.0;

	ST_uint4 nStudies = (ST_uint4) esVector->size ;
	ST_uint4 i , subsetLength;
	
	subsetLength = (ST_uint4) gsl_combination_k(comb);
	
	if (subsetLength < 2) {
		SF_error("Never here with one study! Please debug C code");
		return(-4);
	}
	else {
                tau2_DL = GSL_MAX((MARES(5) - MARES(4)) /
                        (sumOfFixedWeights - (sumOfFixedWeights2 / sumOfFixedWeights) ) , 0.0 );
		gsl_vector_set(metaResultsVector, 7, tau2_DL);

                for(i=0; i<subsetLength ; i++) {
                        sumOfRandomDLWeights += 1.0 / (gsl_vector_get(varVector, c(i)) + tau2_DL);
                        sumOfRandomDLWeightedEffects += gsl_vector_get(esVector, c(i))
                                / (gsl_vector_get(varVector, c(i)) + tau2_DL);
                }

                /* Summary ES REM-DL */
		gsl_vector_set(metaResultsVector, 2, 
			sumOfRandomDLWeightedEffects / sumOfRandomDLWeights);

                /* Var of summary ES REM-DL */
		gsl_vector_set(metaResultsVector, 3, 
			1.0 / sumOfRandomDLWeights);
	
	}
	return 0;
}
Beispiel #2
0
int WriteOut(gsl_vector * metaResultsVector, ST_long j, gsl_combination * comb) {
	
	ST_retcode	rc;
	ST_uint4	i, subsetLength = gsl_combination_k(comb);
	char 		digits[52]="abcdefghijklmnopqrstuvwxywABCDEFGHIJKLMNOPQRSTUVWXYZ";
	char 		buf[80] ,temp[80];
	
	if((rc = SF_vstore(3, j, MARES(0)))) return(rc);  /* ES_FEM */
	if((rc = SF_vstore(4, j, MARES(1)))) return(rc);  /* var_FEM */
	if((rc = SF_vstore(5, j, MARES(2)))) return(rc);  /* ES_REM */
	if((rc = SF_vstore(6, j, MARES(3)))) return(rc);  /* var_REM */
	if((rc = SF_vstore(7, j, MARES(4)))) return(rc);  /* df */
	if (MARES(4) > 0.0) {
		if((rc = SF_vstore(8, j, MARES(5)))) return(rc);  /* Q */
		if((rc = SF_vstore(9, j, MARES(6)))) return(rc);  /* I2 */
	}
	else {
		if((rc = SF_vstore(8, j, SV_missval ))) return(rc);  /* Q */
		if((rc = SF_vstore(9, j, SV_missval ))) return(rc);  /* I2 */
	}
	if((rc = SF_vstore(10, j, MARES(7)))) return(rc);  /* tau2 */
	
	if (subsetLength>80) {
		SF_error("Exceeded 80 characters for subset description");
		SF_error("I will not print the string variable coding the subsets");
	}
	else {
		for(i=0; i<subsetLength; i++) {
			buf[i]=digits[c(i)];
			if (i==subsetLength-1) {
				buf[i+1]='\0';
			}
		}
	}
	
	if((rc = SF_sstore(11, j, buf))) return(rc);  


	return 0;
}
Beispiel #3
0
int MetaAnalysis(gsl_vector * esVector, gsl_vector * varVector, 
	gsl_vector * metaResultsVector, gsl_combination * comb) {
	
	ST_retcode	rc;
	ST_uint4 	i, nStudies, subsetLength;
	
	ST_double sumOfFixedWeights = 0.0;
	ST_double sumOfFixedWeights2= 0.0;
	ST_double sumOfFixedWeightedEffects = 0.0;
	ST_double sumOfFixedWeightedSquares = 0.0;
	
	
	nStudies = (ST_uint4) esVector->size;

	subsetLength = gsl_combination_k(comb);
	
        
/* note the definition of c(i) in the beginning */	
	if (subsetLength > 1.0) {
		for(i=0; i< subsetLength ; i++) {
			sumOfFixedWeights += 1.0 / (gsl_vector_get(varVector, c(i) ));
			sumOfFixedWeights2 += 1.0 / gsl_pow_2( (gsl_vector_get(varVector, c(i) )) );
			sumOfFixedWeightedEffects += gsl_vector_get(esVector, c(i))
				/ (gsl_vector_get(varVector, c(i)));
		}
	
		/* ES_FEM */
		gsl_vector_set(metaResultsVector, 0,
			sumOfFixedWeightedEffects / sumOfFixedWeights);
		/* var_FEM*/
		gsl_vector_set(metaResultsVector, 1, 1.0 / sumOfFixedWeights);
		/* df */
		gsl_vector_set(metaResultsVector, 4, subsetLength-1.0);

		/* Q */
		for(i=0; i< subsetLength ; i++) {
			sumOfFixedWeightedSquares +=   		/* see the definition of MARES */
				gsl_pow_2(gsl_vector_get(esVector, c(i)) - MARES(0))
				/ gsl_vector_get(varVector,c(i));
		}
		gsl_vector_set(metaResultsVector, 5, sumOfFixedWeightedSquares);

		/* I2 */
		gsl_vector_set(metaResultsVector, 6, GSL_MAX(0.0, 1.0 - MARES(4) / MARES(5)) );
	
		/****REM****/
		/* sets ES_REM var_REM and tau2 */
		if ((rc = DL(esVector, varVector, metaResultsVector, comb,
			sumOfFixedWeights, sumOfFixedWeights2) )) return(rc);
	}
	else {
		gsl_vector_set(metaResultsVector, 2, MARES(0));
		gsl_vector_set(metaResultsVector, 3, MARES(1));
		gsl_vector_set(metaResultsVector, 5, 0.0);   /* Q will set to missing later */
		gsl_vector_set(metaResultsVector, 6, 0.0 );   /* I2 will set to missing later */
		gsl_vector_set(metaResultsVector, 7, 0.0 );     /* no tau2 */
		
	}
	return 0;
	

}
Beispiel #4
0
static VALUE rb_gsl_combination_k(VALUE obj)
{
  gsl_combination *c = NULL;
  Data_Get_Struct(obj, gsl_combination, c);
  return INT2FIX(gsl_combination_k(c));
}