scipy.stats單因素方差分析

###調包進行單因素方差分析
import numpy as np
from scipy import stats
'''###第一種數據形式type=numpy.recarray
data = np.rec.array([
('Pat', 5),
('Pat', 4),
('Pat', 4),
('Pat', 3),
('Pat', 9),
('Pat', 4),
('Jack', 4),
('Jack', 8),
('Jack', 7),
('Jack', 5),
('Jack', 1),
('Jack', 5),
('Alex', 9),
('Alex', 8),
('Alex', 8),
('Alex', 10),
('Alex', 5),
('Alex', 10)], dtype = [('Archer','|U5'),('Score', '<i8')])
f, p = stats.f_oneway(data[data['Archer'] == 'Pat'].Score,
                      data[data['Archer'] == 'Jack'].Score,
                      data[data['Archer'] == 'Alex'].Score)
'''
'''第二種數據形式dataframe
data=pd.read_excel(r'C:/Users/LHL/Desktop/方差分析.xlsx')

f, p = stats.f_oneway(data[data['X'] == 'A1']['Y'],
                      data[data['X'] == 'A2']['Y'],
                      data[data['X'] == 'A3']['Y'],
                      data[data['X'] == 'A4']['Y'])
''' 

print ('One-way ANOVA')
print ('=============')
 
print ('F value:', f)
print ('P value:', p, '\n')

結果:
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章