pythonarraysp-valueprobability-distribution

Scipy.Stats Error. Why is the function stats.combine_pvalues not accepting my weights for Stouffer method?


I have two dictionaries,


import scipy.stats
import numpy as np
import pandas as pd

exp_pvalues={'SC_1': array([0.96612999, 0.30348366]),
 'SC_2': array([0.66871158, 0.0011381 ]),
 'SC_3': array([0.66871158, 0.0011381 , 0.96612999, 0.30348366]),
 'SC_4': array([0.66871158, 0.0011381 , 0.46018094, 0.30348366]),
 'SC_5': array([0.66871158, 0.0011381 , 0.18113085, 0.04860657]),
 'SC_6': array([6.68711583e-01, 1.13809558e-03, 0.00000000e+00, 8.54560803e-07]),
 'SC_7': array([6.68711583e-001, 1.13809558e-003, 8.47561031e-131, 1.28484156e-018])}


weights_final={'SC_1': array([0.5, 0.5]),
 'SC_2': array([0.5, 0.5]),
 'SC_3': array([0.25, 0.25, 0.25, 0.25]),
 'SC_4': array([0.49751244, 0.49751244, 0.00248756, 0.00248756]),
 'SC_5': array([0.47619048, 0.47619048, 0.02380952, 0.02380952]),
 'SC_6': array([0.32786885, 0.32786885, 0.01639344, 0.32786885]),
 'SC_7': array([0.38461538, 0.38461538, 0.07692308, 0.15384615])}

The following function works for everything single other method but stouffers. The outputs changed as well when weights were included so why is this stouffers function failing?

combined_pvalues_Stouffer_weighted = {}

for key, values in exp_pvalues.items():
      test_stat, combined_pval= stats.combine_pvalues(values, method='stouffer', weights 
       = weights_final)
      combined_pvalues_Stouffer_weighted[key] =   combined_pval


ValueError: pvalues and weights must be of the same size.


Solution

  • You need weights_final[key] in your code

    combined_pvalues_Stouffer_weighted = {}
    
    for key, values in exp_pvalues.items():
          test_stat, combined_pval= stats.combine_pvalues(values, method='stouffer', weights 
           = weights_final[key])
          combined_pvalues_Stouffer_weighted[key] =   combined_pval