@@ -17,7 +17,7 @@ def test_mle_easy(input_absolutes=[-14., -13., -9.]):
17
17
edges = [(0 , 1 ), (0 , 2 ), (2 , 1 )]
18
18
for a , b in edges :
19
19
noise = np .random .uniform (low = - 1. , high = 1. )
20
- diff = input_absolutes [a ] - input_absolutes [b ] + noise
20
+ diff = input_absolutes [b ] - input_absolutes [a ] + noise
21
21
g .add_edge (a , b , f_ij = diff , f_dij = 0.5 + np .abs (noise ))
22
22
23
23
output_absolutes , C = stats .mle (g , factor = 'f_ij' , node_factor = 'f_i' )
@@ -49,7 +49,7 @@ def test_mle_hard(input_absolutes=[-14., -13., -9.]):
49
49
edges = [(0 , 1 ), (0 , 2 ), (2 , 1 )]
50
50
for a , b in edges :
51
51
noise = np .random .uniform (low = - 1. , high = 1. )
52
- diff = input_absolutes [a ] - input_absolutes [b ] + noise
52
+ diff = input_absolutes [b ] - input_absolutes [a ] + noise
53
53
g .add_edge (a , b , f_ij = diff , f_dij = 0.5 + np .abs (noise ))
54
54
55
55
output_absolutes , C = stats .mle (g , factor = 'f_ij' , node_factor = 'f_i' )
@@ -74,8 +74,8 @@ def test_mle_relative(input_absolutes=[-14., -13., -9.]):
74
74
# Don't assign any absolute values
75
75
edges = [(0 , 1 ), (0 , 2 ), (2 , 1 )]
76
76
for a , b in edges :
77
- noise = np .random .uniform (low = - 1. , high = 1. )
78
- diff = input_absolutes [a ] - input_absolutes [b ] + noise
77
+ noise = np .random .uniform (low = - 0.5 , high = 0.5 )
78
+ diff = input_absolutes [b ] - input_absolutes [a ] + noise
79
79
g .add_edge (a , b , f_ij = diff , f_dij = 0.5 + np .abs (noise ))
80
80
81
81
output_absolutes , C = stats .mle (g , factor = 'f_ij' , node_factor = 'f_i' )
@@ -89,3 +89,27 @@ def test_mle_relative(input_absolutes=[-14., -13., -9.]):
89
89
assert np .abs (true_diff - mle_diff ) < 1. , f"Relative\
90
90
difference from MLE: { mle_diff } is too far from the\
91
91
input difference, { true_diff } "
92
+
93
+
94
+ def test_correlation_positive ():
95
+ """ Test that the absolute DG plots have the correct signs, and statistics within reasonable agreement to the example data in `arsenic/data/example.csv`
96
+
97
+ """
98
+ from arsenic import plotting , stats , wrangle
99
+ import os
100
+ print (os .system ('pwd' ))
101
+ import numpy as np
102
+ fe = wrangle .FEMap ('arsenic/data/example.csv' )
103
+
104
+ x_data = np .asarray ([node [1 ]['exp_DG' ] for node in fe .graph .nodes (data = True )])
105
+ y_data = np .asarray ([node [1 ]['calc_DG' ] for node in fe .graph .nodes (data = True )])
106
+ xerr = np .asarray ([node [1 ]['exp_dDG' ] for node in fe .graph .nodes (data = True )])
107
+ yerr = np .asarray ([node [1 ]['calc_dDG' ] for node in fe .graph .nodes (data = True )])
108
+
109
+ s = stats .bootstrap_statistic (x_data , y_data , xerr , yerr , statistic = 'rho' )
110
+ assert 0 < s ['mle' ] < 1 , 'Correlation must be positive for this data'
111
+
112
+ for stat in ['R2' ,'rho' ]:
113
+ s = stats .bootstrap_statistic (x_data , y_data , xerr , yerr , statistic = stat )
114
+ # all of the statistics for this example is between 0.61 and 0.84
115
+ assert 0.5 < s ['mle' ] < 0.9 , f"Correlation must be positive for this data. { stat } is { s ['mle' ]} "
0 commit comments