簡體   English   中英

嘗試計算p_value時收到錯誤消息

[英]Receiving error message when trying to calculate p_value

得到一個“ TypeError:/:'generator'和'int'的不受支持的操作數類型”,

問題是當我嘗試計算p_value時,不確定我在做什么錯。 如果我的問題有點模糊,請原諒我

import numpy as np
import random
beer = [27, 19, 20, 20, 23, 17, 21, 24, 31, 26, 28, 20, 27, 19, 25, 31, 24, 28, 24, 29, 21, 21, 18, 27, 20]
water = [21, 19, 13, 22, 15, 22, 15, 22, 20, 12, 24, 24, 21, 19, 18, 16, 23, 20]

#running a permutation test
def permutation_test():
  combined = beer + water
  random.shuffle(combined)

#slice function to create 2 groups of the same length as the beer test group
  split = len(beer)
  group_one,group_two = combined[:split], combined[split:] #first25, last25
  return np.mean(group_one)-np.mean(group_two)

#monte carlo method to run the permutation test 100 000 times  
iterate = [permutation_test() for _ in range(100000)]

#calculating effect size, standard score
effect_size = np.median(beer) - np.median(water)
standard_score = (effect_size - np.mean(iterate))/np.std(iterate)

#calculating p-value to assess whether the observed effect size is an anomaly
p_value = np.mean(test >= effect_size for test in iterate)
print(standard_score, p_value)

您的列表理解表達式未正確定義:

使用它來解決問題:

 p_value = np.mean([(test >= effect_size) for test in iterate])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM