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

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

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

问题

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

  1. import scipy.stats
  2. import numpy as np
  3. import pandas as pd
  4. exp_pvalues={'SC_1': array([0.96612999, 0.30348366]),
  5. 'SC_2': array([0.66871158, 0.0011381 ]),
  6. 'SC_3': array([0.66871158, 0.0011381, 0.96612999, 0.30348366]),
  7. 'SC_4': array([0.66871158, 0.0011381, 0.46018094, 0.30348366]),
  8. 'SC_5': array([0.66871158, 0.0011381, 0.18113085, 0.04860657]),
  9. 'SC_6': array([6.68711583e-01, 1.13809558e-03, 0.00000000e+00, 8.54560803e-07]),
  10. 'SC_7': array([6.68711583e-001, 1.13809558e-003, 8.47561031e-131, 1.28484156e-018])}
  11. weights_final={'SC_1': array([0.5, 0.5]),
  12. 'SC_2': array([0.5, 0.5]),
  13. 'SC_3': array([0.25, 0.25, 0.25, 0.25]),
  14. 'SC_4': array([0.49751244, 0.49751244, 0.00248756, 0.00248756]),
  15. 'SC_5': array([0.47619048, 0.47619048, 0.02380952, 0.02380952]),
  16. 'SC_6': array([0.32786885, 0.32786885, 0.01639344, 0.32786885]),
  17. 'SC_7': array([0.38461538, 0.38461538, 0.07692308, 0.15384615])}

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

  1. combined_pvalues_Stouffer_weighted = {}
  2. for key, values in exp_pvalues.items():
  3. test_stat, combined_pval= stats.combine_pvalues(values, method='stouffer', weights
  4. = weights_final)
  5. combined_pvalues_Stouffer_weighted[key] = combined_pval
  6. ValueError: pvalues and weights must be of the same size.
英文:

I have two dictionaries,

  1. import scipy.stats
  2. import numpy as np
  3. import pandas as pd
  4. exp_pvalues={'SC_1': array([0.96612999, 0.30348366]),
  5. 'SC_2': array([0.66871158, 0.0011381 ]),
  6. 'SC_3': array([0.66871158, 0.0011381 , 0.96612999, 0.30348366]),
  7. 'SC_4': array([0.66871158, 0.0011381 , 0.46018094, 0.30348366]),
  8. 'SC_5': array([0.66871158, 0.0011381 , 0.18113085, 0.04860657]),
  9. 'SC_6': array([6.68711583e-01, 1.13809558e-03, 0.00000000e+00, 8.54560803e-07]),
  10. 'SC_7': array([6.68711583e-001, 1.13809558e-003, 8.47561031e-131, 1.28484156e-018])}
  11. weights_final={'SC_1': array([0.5, 0.5]),
  12. 'SC_2': array([0.5, 0.5]),
  13. 'SC_3': array([0.25, 0.25, 0.25, 0.25]),
  14. 'SC_4': array([0.49751244, 0.49751244, 0.00248756, 0.00248756]),
  15. 'SC_5': array([0.47619048, 0.47619048, 0.02380952, 0.02380952]),
  16. 'SC_6': array([0.32786885, 0.32786885, 0.01639344, 0.32786885]),
  17. '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?

  1. combined_pvalues_Stouffer_weighted = {}
  2. for key, values in exp_pvalues.items():
  3. test_stat, combined_pval= stats.combine_pvalues(values, method='stouffer', weights
  4. = weights_final)
  5. combined_pvalues_Stouffer_weighted[key] = combined_pval
  6. ValueError: pvalues and weights must be of the same size.

答案1

得分: 1

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

英文:

You need weights_final[key] in your code

  1. combined_pvalues_Stouffer_weighted = {}
  2. for key, values in exp_pvalues.items():
  3. test_stat, combined_pval= stats.combine_pvalues(values, method='stouffer', weights
  4. = weights_final[key])
  5. 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:

确定