Last active
July 28, 2017 19:34
-
-
Save zverbatim/a8990e6dcbfd7b6ba1a62281269c97d2 to your computer and use it in GitHub Desktop.
collection of function useful for doing statistical analysis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pearson correlation coeficient | |
# x, y are two arrays | |
np.corrcoef(x,y)[0,1] | |
def ecdf(list): | |
""" | |
Empirical cumulative distribution function | |
Afterwards can be called | |
plt.plot(x, y, marker='.') | |
""" | |
x = np.sort(list) | |
y = np.arange(1, len(list) + 1) / len(list) | |
return x, y | |
def bootsrap_replicate(list, fx): | |
""" | |
Apply a function (np.mean, np.std) to a newly sampled list with replacement | |
Used to make large simulated mesurements (of the applied) function for determining the | |
normal distribution of an event | |
""" | |
bootstrap_list = np.random.choice(list, len(list)) | |
return fx(bootstrap_list) | |
def permutation_sample(a, b): | |
""" | |
Generate a permutation sample from two arrays | |
""" | |
# Concatenate the data sets: data | |
data = np.concatenate((a, b)) | |
# Permute the concatenated array: permuted_data | |
permuted_data = np.random.permutation(data) | |
# Split the permuted array into two: | |
sample_1 = permuted_data[:len(a)] | |
sample_2 = permuted_data[len(a):] | |
return sample_1, sample_2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment