Scipy.Stats错误。为什么函数stats.combine_pvalues不接受我用于Stouffer方法的权重?

huangapple go评论57阅读模式
英文:

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

问题

我有两个字典,下面是要翻译的代码部分:

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])}

以下函数适用于除Stouffer之外的所有单独方法,但在包括权重时输出也发生了变化,那么为什么这个Stouffer函数失败了?

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.
英文:

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.

答案1

得分: 1

你的代码中需要使用weights_final[key]

英文:

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

huangapple
  • 本文由 发表于 2023年2月10日 03:05:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/75403301.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定