@@ -149,7 +149,7 @@ def test_estimate_strata_dist(bootstrap_election_model, rng):
149
149
150
150
def test_generate_nonreporting_bounds (bootstrap_election_model , rng ):
151
151
nonreporting_units = pd .DataFrame (
152
- [[0.1 , 1.2 , 75 ], [0.8 , 0.8 , 24 ], [ 0. 1 , 0.01 , 0 ], [- 0.2 , 0.8 , 99 ], [- 0.3 , 0.9 , 100 ]],
152
+ [[0.1 , 1.2 , 75 ], [0.1 , 0.01 , 0 ], [- 0.2 , 0.8 , 99 ], [- 0.3 , 0.9 , 100 ]],
153
153
columns = ["results_normalized_margin" , "turnout_factor" , "percent_expected_vote" ],
154
154
)
155
155
@@ -162,35 +162,29 @@ def test_generate_nonreporting_bounds(bootstrap_election_model, rng):
162
162
assert lower [0 ] == pytest .approx (- 0.175 )
163
163
assert upper [0 ] == pytest .approx (0.325 )
164
164
165
- assert lower [1 ] == pytest .approx (- 0.568 )
166
- assert upper [1 ] == pytest .approx (0.952 )
167
-
168
165
# if expected vote is close to 0 or 1 we set the bounds to be the extreme case
169
- assert lower [2 ] == bootstrap_election_model .y_unobserved_lower_bound
170
- assert upper [2 ] == bootstrap_election_model .y_unobserved_upper_bound
166
+ assert lower [1 ] == bootstrap_election_model .y_unobserved_lower_bound
167
+ assert upper [1 ] == bootstrap_election_model .y_unobserved_upper_bound
171
168
172
- assert lower [3 ] == pytest .approx (- 0.208 )
173
- assert upper [3 ] == pytest .approx (- 0.188 )
169
+ assert lower [2 ] == pytest .approx (- 0.208 )
170
+ assert upper [2 ] == pytest .approx (- 0.188 )
174
171
175
- assert lower [4 ] == bootstrap_election_model .y_unobserved_lower_bound
176
- assert upper [4 ] == bootstrap_election_model .y_unobserved_upper_bound
172
+ assert lower [3 ] == bootstrap_election_model .y_unobserved_lower_bound
173
+ assert upper [3 ] == bootstrap_election_model .y_unobserved_upper_bound
177
174
178
175
lower , upper = bootstrap_election_model ._generate_nonreporting_bounds (nonreporting_units , "turnout_factor" )
179
176
180
177
assert lower [0 ] == pytest .approx (0.96 )
181
178
assert upper [0 ] == pytest .approx (4.8 )
182
179
183
- assert lower [1 ] == pytest .approx (1.081081081 )
184
- assert upper [1 ] == pytest .approx (80 ) # this is 80 since we divide 0.8 / 0.01 (it's clipped)
185
-
186
- assert lower [2 ] == bootstrap_election_model .z_unobserved_lower_bound
187
- assert upper [2 ] == bootstrap_election_model .z_unobserved_upper_bound
180
+ assert lower [1 ] == bootstrap_election_model .z_unobserved_lower_bound
181
+ assert upper [1 ] == bootstrap_election_model .z_unobserved_upper_bound
188
182
189
- assert lower [3 ] == pytest .approx (0.536912752 )
190
- assert upper [3 ] == pytest .approx (1.632653061 )
183
+ assert lower [2 ] == pytest .approx (0.536912752 )
184
+ assert upper [2 ] == pytest .approx (1.632653061 )
191
185
192
- assert lower [4 ] == bootstrap_election_model .z_unobserved_lower_bound
193
- assert upper [4 ] == bootstrap_election_model .z_unobserved_upper_bound
186
+ assert lower [3 ] == bootstrap_election_model .z_unobserved_lower_bound
187
+ assert upper [3 ] == bootstrap_election_model .z_unobserved_upper_bound
194
188
195
189
# changing parameters
196
190
bootstrap_election_model .y_unobserved_lower_bound = - 0.8
@@ -202,17 +196,14 @@ def test_generate_nonreporting_bounds(bootstrap_election_model, rng):
202
196
assert lower [0 ] == pytest .approx (- 0.125 )
203
197
assert upper [0 ] == pytest .approx (0.275 )
204
198
205
- assert lower [1 ] == pytest . approx ( - 0.416 )
206
- assert upper [1 ] == pytest . approx ( 0.8 )
199
+ assert lower [1 ] == bootstrap_election_model . y_unobserved_lower_bound
200
+ assert upper [1 ] == bootstrap_election_model . y_unobserved_upper_bound
207
201
208
- assert lower [2 ] == bootstrap_election_model . y_unobserved_lower_bound
209
- assert upper [2 ] == bootstrap_election_model . y_unobserved_upper_bound
202
+ assert lower [2 ] == pytest . approx ( - 0.206 )
203
+ assert upper [2 ] == pytest . approx ( - 0.19 )
210
204
211
- assert lower [3 ] == pytest .approx (- 0.206 )
212
- assert upper [3 ] == pytest .approx (- 0.19 )
213
-
214
- assert lower [4 ] == bootstrap_election_model .y_unobserved_lower_bound
215
- assert upper [4 ] == bootstrap_election_model .y_unobserved_upper_bound
205
+ assert lower [3 ] == bootstrap_election_model .y_unobserved_lower_bound
206
+ assert upper [3 ] == bootstrap_election_model .y_unobserved_upper_bound
216
207
217
208
bootstrap_election_model .y_unobserved_lower_bound = 0.8
218
209
bootstrap_election_model .y_unobserved_upper_bound = 1.2
@@ -222,17 +213,14 @@ def test_generate_nonreporting_bounds(bootstrap_election_model, rng):
222
213
assert lower [0 ] == pytest .approx (1.411764706 )
223
214
assert upper [0 ] == pytest .approx (1.846153846 )
224
215
225
- assert lower [1 ] == pytest .approx (2.352941176 )
226
- assert upper [1 ] == pytest .approx (5.714285714 )
227
-
228
- assert lower [2 ] == bootstrap_election_model .z_unobserved_lower_bound
229
- assert upper [2 ] == bootstrap_election_model .z_unobserved_upper_bound
216
+ assert lower [1 ] == bootstrap_election_model .z_unobserved_lower_bound
217
+ assert upper [1 ] == bootstrap_election_model .z_unobserved_upper_bound
230
218
231
- assert lower [3 ] == pytest .approx (0.733944954 )
232
- assert upper [3 ] == pytest .approx (0.898876404 )
219
+ assert lower [2 ] == pytest .approx (0.733944954 )
220
+ assert upper [2 ] == pytest .approx (0.898876404 )
233
221
234
- assert lower [4 ] == bootstrap_election_model .z_unobserved_lower_bound
235
- assert upper [4 ] == bootstrap_election_model .z_unobserved_upper_bound
222
+ assert lower [3 ] == bootstrap_election_model .z_unobserved_lower_bound
223
+ assert upper [3 ] == bootstrap_election_model .z_unobserved_upper_bound
236
224
237
225
238
226
def test_strata_pit (bootstrap_election_model , rng ):
0 commit comments