aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRadeen Abree <radeen.abree0515@gmail.com>2021-01-13 13:42:24 -0500
committerHolden Rohrer <hr@hrhr.dev>2021-01-17 17:40:27 -0500
commit70fc32cc8eb0b45f3688df4a4b8aa29441bc3826 (patch)
tree52896b18f8c4b4024ef5231bac56e79c7563f0db
parent77efaa26921efb916e68f2eaa28c9d54d0017a32 (diff)
wrote stats.py for pval analysis
-rw-r--r--py/stats.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/py/stats.py b/py/stats.py
new file mode 100644
index 0000000..b79e56f
--- /dev/null
+++ b/py/stats.py
@@ -0,0 +1,38 @@
+from data2 import trials
+from scipy.stats import cramervonmises
+from bisect import bisect_left
+from random import random
+
+def distance(pit1, pit2):
+ out = ((pit2[1]-pit1[1])**2 + (pit2[0]-pit1[0])**2)**(1/2)
+ if (out == 0):
+ return 100
+ else:
+ return out
+
+def cdf(a,nnsim,tup):
+ return [bisect_left(nnsim, x)/len(nnsim) for x in a]
+
+def calcpval(trialno):
+ size = trials[trialno].size[0]
+ pits = len(trials[trialno].pits)
+
+ nnsim = []
+ for j in range(10000):
+ curpits = []
+ for k in range(pits):
+ curpits.append([random()*size,random()*size])
+ for pit in curpits:
+ l = size
+ for pit2 in curpits:
+ l = min(l,distance(pit,pit2))
+ nnsim.append(l)
+
+ nnsim.sort()
+
+ nnreal = trials[trialno].nearest_neighbor()
+ stat = cramervonmises(nnreal,cdf,(nnsim,()))
+ return stat.pvalue
+
+for n in range(len(trials)):
+ print(calcpval(n))