如果我有这样的df:
normalized_0 normalized_1 normalized_0 mean std
Site
0 NaN 0.798262 1.456576 0.888687 0.118194
1 0.705540 0.885226 NaN 0.761488 0.047023
2 0.669539 1.002526 1.212976 0.826657 0.077940
3 0.829826 0.968180 0.988679 0.871290 0.032367如何计算0,1,2对3的双边t检验?
我试了一下:
from scipy.stats import ttest_ind
df['ttest'] = ttest_ind(df, d.loc[3])但这行不通..。我得到的错误是:
TypeError: unsupported operand type(s) for /: 'str' and 'int'你怎么解决这个问题?
发布于 2019-08-07 18:00:30
我的答案可能完全错了,因为我只读过关于t-test的文章:)
我从您的问题中了解到的是,您有一个具有规范化值和它们的描述性统计信息的表(平均值,std)。
此表中的每个索引值都是分析的category,您希望比较类别[0, 1, 2]与[3]。
我还假设您只需要标准化的值作为输入数组,而不需要平均值或std。
selected_data = df.copy()
selected_data = selected_data[['normalized_0', 'normalized_1', 'normalized_0.1']]
selected_data['ttest'] = [ttest_ind(a=selected_data.iloc[3, :].values, \
b=selected_data.iloc[x, :].values, \
nan_policy='omit') for x in np.arange(len(selected_data))]
df.join(selected_data['ttest']) normalized_0 normalized_1 normalized_0.1 mean std ttest
Site
0 NaN 0.798262 1.456576 0.888687 0.118194 (-0.7826642930343911, 0.4909212050511221)
1 0.705540 0.885226 NaN 0.761488 0.047023 (1.4370158341444121, 0.24625840339538163)
2 0.669539 1.002526 1.212976 0.826657 0.077940 (-0.19764518466194855, 0.8529602343240825)
3 0.829826 0.968180 0.988679 0.871290 0.032367 (0.0, 1.0)a和b参数是选定列的行值。
# values of third category for example
selected_data.iloc[3, :].values
# array([0.829826, 0.96818 , 0.988679])omit在计算测试时忽略nan值(默认情况下,nan_policy的参数设置为propagate,如果存在缺失值,则返回nan )。
https://stackoverflow.com/questions/57398506
复制相似问题