Skip to content

Commit 9dc9fa9

Browse files
committed
fix test_load_errors and renaming
1 parent 5a25124 commit 9dc9fa9

2 files changed

Lines changed: 43 additions & 31 deletions

File tree

nbs/tests/test_99_confint.ipynb renamed to nbs/tests/test_99_confidence_intervals.ipynb

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -75,33 +75,35 @@
7575
"outputs": [],
7676
"source": [
7777
"# Dropped to 30 reps to save time. v0.2.5.\n",
78-
"reps = 30\n",
79-
"ci = 95\n",
78+
"reps=30\n",
79+
"ci=95\n",
8080
"POPULATION_N = 10000\n",
8181
"SAMPLE_N = 10\n",
8282
"\n",
8383
"# Create data for hedges g and cohens d.\n",
8484
"CONTROL_MEAN = np.random.randint(1, 1000)\n",
85-
"POP_SD = np.random.randint(1, 15)\n",
86-
"POP_D = np.round(np.random.uniform(-2, 2, 1)[0], 2)\n",
85+
"POP_SD = np.random.randint(1, 15)\n",
86+
"POP_D = np.round(np.random.uniform(-2, 2, 1)[0], 2)\n",
8787
"\n",
8888
"TRUE_STD_DIFFERENCE = CONTROL_MEAN + (POP_D * POP_SD)\n",
8989
"norm_sample_kwargs = dict(scale=POP_SD, size=SAMPLE_N)\n",
9090
"c1 = norm.rvs(loc=CONTROL_MEAN, **norm_sample_kwargs)\n",
91-
"t1 = norm.rvs(loc=CONTROL_MEAN + TRUE_STD_DIFFERENCE, **norm_sample_kwargs)\n",
91+
"t1 = norm.rvs(loc=CONTROL_MEAN+TRUE_STD_DIFFERENCE, **norm_sample_kwargs)\n",
92+
"\n",
93+
"std_diff_df = pd.DataFrame({'Control' : c1, 'Test': t1})\n",
9294
"\n",
93-
"std_diff_df = pd.DataFrame({\"Control\": c1, \"Test\": t1})\n",
9495
"\n",
9596
"\n",
9697
"# Create mean_diff data\n",
9798
"CONTROL_MEAN = np.random.randint(1, 1000)\n",
98-
"POP_SD = np.random.randint(1, 15)\n",
99-
"TRUE_DIFFERENCE = np.random.randint(-POP_SD * 5, POP_SD * 5)\n",
99+
"POP_SD = np.random.randint(1, 15)\n",
100+
"TRUE_DIFFERENCE = np.random.randint(-POP_SD*5, POP_SD*5)\n",
100101
"\n",
101102
"c1 = norm.rvs(loc=CONTROL_MEAN, **norm_sample_kwargs)\n",
102-
"t1 = norm.rvs(loc=CONTROL_MEAN + TRUE_DIFFERENCE, **norm_sample_kwargs)\n",
103+
"t1 = norm.rvs(loc=CONTROL_MEAN+TRUE_DIFFERENCE, **norm_sample_kwargs)\n",
104+
"\n",
105+
"mean_df = pd.DataFrame({'Control' : c1, 'Test': t1})\n",
103106
"\n",
104-
"mean_df = pd.DataFrame({\"Control\": c1, \"Test\": t1})\n",
105107
"\n",
106108
"\n",
107109
"# Create median_diff data\n",
@@ -110,13 +112,14 @@
110112
"\n",
111113
"skew_kwargs = dict(a=A, scale=5, size=POPULATION_N)\n",
112114
"skewpop1 = skewnorm.rvs(**skew_kwargs, loc=100)\n",
113-
"skewpop2 = skewnorm.rvs(**skew_kwargs, loc=100 + MEDIAN_DIFFERENCE)\n",
115+
"skewpop2 = skewnorm.rvs(**skew_kwargs, loc=100+MEDIAN_DIFFERENCE)\n",
114116
"\n",
115117
"sample_kwargs = dict(replace=False, size=SAMPLE_N)\n",
116118
"skewsample1 = np.random.choice(skewpop1, **sample_kwargs)\n",
117119
"skewsample2 = np.random.choice(skewpop2, **sample_kwargs)\n",
118120
"\n",
119-
"median_df = pd.DataFrame({\"Control\": skewsample1, \"Test\": skewsample2})\n",
121+
"median_df = pd.DataFrame({'Control' : skewsample1, 'Test': skewsample2})\n",
122+
"\n",
120123
"\n",
121124
"\n",
122125
"# Create two populations with a 50% overlap.\n",
@@ -125,24 +128,25 @@
125128
"\n",
126129
"pop_kwargs = dict(scale=SD, size=POPULATION_N)\n",
127130
"pop1 = norm.rvs(loc=100, **pop_kwargs)\n",
128-
"pop2 = norm.rvs(loc=100 + CD_DIFFERENCE, **pop_kwargs)\n",
131+
"pop2 = norm.rvs(loc=100+CD_DIFFERENCE, **pop_kwargs)\n",
129132
"\n",
130133
"sample_kwargs = dict(replace=False, size=SAMPLE_N)\n",
131134
"sample1 = np.random.choice(pop1, **sample_kwargs)\n",
132135
"sample2 = np.random.choice(pop2, **sample_kwargs)\n",
133136
"\n",
134-
"cd_df = pd.DataFrame({\"Control\": sample1, \"Test\": sample2})\n",
137+
"cd_df = pd.DataFrame({'Control' : sample1, 'Test': sample2})\n",
138+
"\n",
135139
"\n",
136140
"\n",
137141
"# Create several CIs and see if the true population difference lies within.\n",
138-
"error_count_cohens_d = 0\n",
139-
"error_count_hedges_g = 0\n",
140-
"error_count_mean_diff = 0\n",
141-
"error_count_median_diff = 0\n",
142+
"error_count_cohens_d = 0\n",
143+
"error_count_hedges_g = 0\n",
144+
"error_count_mean_diff = 0\n",
145+
"error_count_median_diff = 0\n",
142146
"error_count_cliffs_delta = 0\n",
143147
"\n",
144148
"for i in range(0, reps):\n",
145-
" # print(i) # for debug.\n",
149+
" print(i) # for debug.\n",
146150
" # pick a random seed\n",
147151
" rnd_sd = np.random.randint(0, 999999)\n",
148152
" load_kwargs = dict(ci=ci, random_seed=rnd_sd)\n",
@@ -151,44 +155,48 @@
151155
" cd = std_diff_data.cohens_d.results\n",
152156
" # print(\"cohen's d\") # for debug.\n",
153157
" cd_low, cd_high = float(cd.bca_low), float(cd.bca_high)\n",
154-
" if not cd_low < POP_D < cd_high:\n",
158+
" if cd_low < POP_D < cd_high is False:\n",
155159
" error_count_cohens_d += 1\n",
156160
"\n",
157161
" hg = std_diff_data.hedges_g.results\n",
158162
" # print(\"hedges' g\") # for debug.\n",
159163
" hg_low, hg_high = float(hg.bca_low), float(hg.bca_high)\n",
160-
" if not hg_low < POP_D < hg_high:\n",
164+
" if hg_low < POP_D < hg_high is False:\n",
161165
" error_count_hedges_g += 1\n",
162166
"\n",
167+
"\n",
163168
" mean_diff_data = load(data=mean_df, idx=(\"Control\", \"Test\"), **load_kwargs)\n",
164169
" mean_d = mean_diff_data.mean_diff.results\n",
165170
" # print(\"mean diff\") # for debug.\n",
166171
" mean_d_low, mean_d_high = float(mean_d.bca_low), float(mean_d.bca_high)\n",
167-
" if not mean_d_low < TRUE_DIFFERENCE < mean_d_high:\n",
172+
" if mean_d_low < TRUE_DIFFERENCE < mean_d_high is False:\n",
168173
" error_count_mean_diff += 1\n",
169174
"\n",
170-
" median_diff_data = load(data=median_df, idx=(\"Control\", \"Test\"), **load_kwargs)\n",
175+
"\n",
176+
" median_diff_data = load(data=median_df, idx=(\"Control\", \"Test\"),\n",
177+
" **load_kwargs)\n",
171178
" median_d = median_diff_data.median_diff.results\n",
172179
" # print(\"median diff\") # for debug.\n",
173180
" median_d_low, median_d_high = float(median_d.bca_low), float(median_d.bca_high)\n",
174-
" if not median_d_low < MEDIAN_DIFFERENCE < median_d_high:\n",
181+
" if median_d_low < MEDIAN_DIFFERENCE < median_d_high is False:\n",
175182
" error_count_median_diff += 1\n",
176183
"\n",
184+
"\n",
177185
" cd_data = load(data=cd_df, idx=(\"Control\", \"Test\"), **load_kwargs)\n",
178186
" cliffs = cd_data.cliffs_delta.results\n",
179187
" # print(\"cliff's delta\") # for debug.\n",
180188
" low, high = float(cliffs.bca_low), float(cliffs.bca_high)\n",
181-
" if not low < 0.5 < high:\n",
189+
" if low < 0.5 < high is False:\n",
182190
" error_count_cliffs_delta += 1\n",
183191
"\n",
184192
"\n",
185193
"max_errors = int(np.ceil(reps * (100 - ci) / 100))\n",
186194
"\n",
187-
"assert error_count_cohens_d <= max_errors\n",
188-
"assert error_count_hedges_g <= max_errors\n",
189-
"assert error_count_mean_diff <= max_errors\n",
190-
"assert error_count_median_diff <= max_errors\n",
191-
"assert error_count_cliffs_delta <= max_errors"
195+
"assert error_count_cohens_d <= max_errors\n",
196+
"assert error_count_hedges_g <= max_errors\n",
197+
"assert error_count_mean_diff <= max_errors\n",
198+
"assert error_count_median_diff <= max_errors\n",
199+
"assert error_count_cliffs_delta <= max_errors\n"
192200
]
193201
},
194202
{
@@ -205,6 +213,10 @@
205213
"display_name": "python3",
206214
"language": "python",
207215
"name": "python3"
216+
},
217+
"language_info": {
218+
"name": "python",
219+
"version": "3.10.12"
208220
}
209221
},
210222
"nbformat": 4,

nbs/tests/test_load_errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_wrong_params_combinations():
3535

3636
assert error_msg in str(excinfo.value)
3737

38-
error_msg = "`proportional` and `delta` cannot be True at the same time."
38+
error_msg = "`proportional` and `delta2` cannot be True at the same time."
3939
with pytest.raises(ValueError) as excinfo:
4040
my_data = load(
4141
dummy_df,

0 commit comments

Comments
 (0)