1

if this is the source code.. how will you edit the f_oneway function line such that you dont have to manually specify the archer name each time

import numpy as np
from scipy import stats

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)

print ('P value:', p, '\n')

I tried the following but it errors out saying 'no field of name Pat'

f, p = stats.f_oneway(data[data['Archer']].Score)

help!

user8652079
  • 55
  • 2
  • 5

1 Answers1

2

I think this is it. Apparently f_oneway cannot cope with things of type array([5, 4, 4, 3, 9, 4], dtype=int64); it can process lists.

import numpy as np
from scipy import stats

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(*[list(data[data['Archer']==name].Score) for name in ['Pat', 'Jack', 'Alex']])
f, p = stats.f_oneway(*[list(data[data['Archer']==name].Score) for name in set(data['Archer'])])
print ('P value:', p, '\n')

Output:

P value: 0.0216837493201 

Edit in response to comment: The second invocation of f_oneway gives the same result as the first, without the need to list the names of the archers.

Bill Bell
  • 21,021
  • 5
  • 43
  • 58