在美国的反倾销调查中,美国商务部使用SAS软件进行倾销幅度的计算。在Differential Price Analysis(目标倾销分析)过程中,DOC使用Cohen’s D统计方法,来测试应诉企业的美国销售价格是否在不同的季度、不同的区域/州、以及不同的客户之间具有明显差异。
以下代码显示了如何在Python中如何Cohen’s D 的计算:
#*-* coding: utf-8 import numpy as np def cohen_d(base, test, std_pooled=True): '''Calculate Cohen's D for two list of data. ''' mean_base = np.mean(base) mean_test = np.mean(test) std_base = np.std(base) std_test = np.std(test) if not std_pooled: # TODO pass else: std_pooled = np.sqrt((std_base ** 2 + std_test ** 2)/2) d = (mean_base - mean_test) / std_pooled d = abs(d) return d if __name__ == "__main__": '''Usage example. ''' base = [1,2,3,4,5] test = [2,4,6,8,10] d = cohen_d(base, test) print(d) # 1.3416407865
Leave a Reply