-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Edited scipy/stats/stats.py via GitHub #87
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2148,15 +2148,15 @@ def f_oneway(*args): | |
.. [2] Heiman, G.W. Research Methods in Statistics. 2002. | ||
|
||
""" | ||
na = len(args) # ANOVA on 'na' groups, each in it's own array | ||
tmp = map(np.array,args) | ||
args = map(np.asarray,args) # convert to an numpy array | ||
na = len(args) # ANOVA on 'na' groups, each in it's own array | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line discards its result |
||
alldata = np.concatenate(args) | ||
bign = len(alldata) | ||
sstot = ss(alldata)-(square_of_sums(alldata)/float(bign)) | ||
ssbn = 0 | ||
for a in args: | ||
ssbn = ssbn + square_of_sums(array(a))/float(len(a)) | ||
ssbn = ssbn - (square_of_sums(alldata)/float(bign)) | ||
ssbn += square_of_sums(a)/float(len(a)) | ||
ssbn -= (square_of_sums(alldata)/float(bign)) | ||
sswn = sstot-ssbn | ||
dfbn = na-1 | ||
dfwn = bign - na | ||
|
@@ -2167,7 +2167,6 @@ def f_oneway(*args): | |
return f, prob | ||
|
||
|
||
|
||
def pearsonr(x, y): | ||
"""Calculates a Pearson correlation coefficient and the p-value for testing | ||
non-correlation. | ||
|
@@ -3544,32 +3543,32 @@ def kruskal(*args): | |
.. [1] http://en.wikipedia.org/wiki/Kruskal-Wallis_one-way_analysis_of_variance | ||
|
||
""" | ||
if len(args) < 2: | ||
args = map(np.asarray,args) # convert to a numpy array | ||
na = len(args) # Kruskal-Wallis on 'na' groups, each in it's own array | ||
if na < 2: | ||
raise ValueError("Need at least two groups in stats.kruskal()") | ||
n = map(len,args) | ||
all = [] | ||
for i in range(len(args)): | ||
all.extend(args[i].tolist()) | ||
ranked = list(rankdata(all)) | ||
T = tiecorrect(ranked) | ||
args = list(args) | ||
for i in range(len(args)): | ||
args[i] = ranked[0:n[i]] | ||
del ranked[0:n[i]] | ||
rsums = [] | ||
for i in range(len(args)): | ||
rsums.append(np.sum(args[i],axis=0)**2) | ||
rsums[i] = rsums[i] / float(n[i]) | ||
ssbn = np.sum(rsums,axis=0) | ||
totaln = np.sum(n,axis=0) | ||
h = 12.0 / (totaln*(totaln+1)) * ssbn - 3*(totaln+1) | ||
df = len(args) - 1 | ||
|
||
alldata = np.concatenate(args) | ||
|
||
ranked = rankdata(alldata) # Rank the data | ||
T = tiecorrect(ranked) # Correct for ties | ||
if T == 0: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The individual ranked lists don't need to be stored |
||
raise ValueError('All numbers are identical in kruskal') | ||
|
||
j = np.insert(np.cumsum(n),0,0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. n is still a list here, so j = np.cumsum([0]+n) should work |
||
ssbn = 0 | ||
for i in range(na): | ||
ssbn += square_of_sums(ranked[j[i]:j[i+1]])/float(n[i]) # Compute sum^2/n for each group | ||
|
||
totaln = np.sum(n) | ||
h = 12.0 / (totaln*(totaln+1)) * ssbn - 3*(totaln+1) | ||
df = len(args) - 1 | ||
h = h / float(T) | ||
return h, chisqprob(h,df) | ||
|
||
|
||
|
||
def friedmanchisquare(*args): | ||
""" | ||
Computes the Friedman test for repeated measurements | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after comma