2020-10-05 03:19:18 +00:00
|
|
|
# Titan Robotics Team 2022: CorrelationTest submodule
|
|
|
|
# Written by Arthur Lu
|
|
|
|
# Notes:
|
|
|
|
# this should be imported as a python module using 'from tra_analysis import CorrelationTest'
|
|
|
|
# setup:
|
|
|
|
|
|
|
|
__version__ = "1.0.0"
|
|
|
|
|
|
|
|
__changelog__ = """changelog:
|
|
|
|
1.0.0:
|
|
|
|
- ported analysis.CorrelationTest() here
|
|
|
|
- removed classness
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = (
|
|
|
|
"Arthur Lu <learthurgo@gmail.com>",
|
|
|
|
)
|
|
|
|
|
|
|
|
__all__ = [
|
|
|
|
]
|
|
|
|
|
|
|
|
import scipy
|
|
|
|
from scipy import stats
|
|
|
|
|
2021-01-27 03:46:29 +00:00
|
|
|
def anova_oneway(*args): #expects arrays of samples
|
2020-10-05 03:19:18 +00:00
|
|
|
|
|
|
|
results = scipy.stats.f_oneway(*args)
|
|
|
|
return {"f-value": results[0], "p-value": results[1]}
|
|
|
|
|
2021-01-27 03:46:29 +00:00
|
|
|
def pearson(x, y):
|
2020-10-05 03:19:18 +00:00
|
|
|
|
|
|
|
results = scipy.stats.pearsonr(x, y)
|
|
|
|
return {"r-value": results[0], "p-value": results[1]}
|
|
|
|
|
2021-01-27 03:46:29 +00:00
|
|
|
def spearman(a, b = None, axis = 0, nan_policy = 'propagate'):
|
2020-10-05 03:19:18 +00:00
|
|
|
|
|
|
|
results = scipy.stats.spearmanr(a, b = b, axis = axis, nan_policy = nan_policy)
|
|
|
|
return {"r-value": results[0], "p-value": results[1]}
|
|
|
|
|
2021-01-27 03:46:29 +00:00
|
|
|
def point_biserial(x, y):
|
2020-10-05 03:19:18 +00:00
|
|
|
|
|
|
|
results = scipy.stats.pointbiserialr(x, y)
|
|
|
|
return {"r-value": results[0], "p-value": results[1]}
|
|
|
|
|
2021-01-27 03:46:29 +00:00
|
|
|
def kendall(x, y, initial_lexsort = None, nan_policy = 'propagate', method = 'auto'):
|
2020-10-05 03:19:18 +00:00
|
|
|
|
|
|
|
results = scipy.stats.kendalltau(x, y, initial_lexsort = initial_lexsort, nan_policy = nan_policy, method = method)
|
|
|
|
return {"tau": results[0], "p-value": results[1]}
|
|
|
|
|
2021-01-27 03:46:29 +00:00
|
|
|
def kendall_weighted(x, y, rank = True, weigher = None, additive = True):
|
2020-10-05 03:19:18 +00:00
|
|
|
|
|
|
|
results = scipy.stats.weightedtau(x, y, rank = rank, weigher = weigher, additive = additive)
|
|
|
|
return {"tau": results[0], "p-value": results[1]}
|
|
|
|
|
2021-01-27 03:46:29 +00:00
|
|
|
def mgc(x, y, compute_distance = None, reps = 1000, workers = 1, is_twosamp = False, random_state = None):
|
2020-10-05 03:19:18 +00:00
|
|
|
|
|
|
|
results = scipy.stats.multiscale_graphcorr(x, y, compute_distance = compute_distance, reps = reps, workers = workers, is_twosamp = is_twosamp, random_state = random_state)
|
|
|
|
return {"k-value": results[0], "p-value": results[1], "data": results[2]} # unsure if MGC test returns a k value
|