Skip to content

Commit 8ceb192

Browse files
authored
Merge pull request #210 from ACCLAB/mini-meta-weight-fix
Fixes mini-meta weight calculation
2 parents 034e59d + 06cae31 commit 8ceb192

File tree

43 files changed

+213
-38
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+213
-38
lines changed

README.md

Lines changed: 2 additions & 2 deletions

dabest/_delta_objects.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,17 +435,19 @@ def __init__(self, effectsizedataframe, permutation_count,
435435
self.__control_N,
436436
self.__test_var,
437437
self.__test_N)
438+
439+
self.__bootstraps_variance = ci2g.calculate_bootstraps_var(self.__bootstraps)
438440

439441
# Compute the weighted average mean differences of the bootstrap data
440442
# using the pooled group variances of the raw data as the inverse of
441443
# weights
442444
self.__bootstraps_weighted_delta = ci2g.calculate_weighted_delta(
443-
self.__group_var,
445+
self.__bootstraps_variance,
444446
self.__bootstraps)
445447

446448
# Compute the weighted average mean difference based on the raw data
447449
self.__difference = es.weighted_delta(np.array(self.__effsizedf["difference"]),
448-
self.__group_var)
450+
self.__bootstraps_variance)
449451

450452
sorted_weighted_deltas = npsort(self.__bootstraps_weighted_delta)
451453

@@ -753,6 +755,14 @@ def group_var(self):
753755
in order.
754756
'''
755757
return self.__group_var
758+
759+
@property
760+
def bootstraps_var(self):
761+
'''
762+
Return the variances of each bootstrapped mean difference distribution
763+
in order.
764+
'''
765+
return self.__bootstraps_variance
756766

757767

758768
@property

dabest/_modidx.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
'dabest/_stats_tools/confint_2group_diff.py'),
2828
'dabest._stats_tools.confint_2group_diff.bootstrap_indices': ( 'API/confint_2group_diff.html#bootstrap_indices',
2929
'dabest/_stats_tools/confint_2group_diff.py'),
30+
'dabest._stats_tools.confint_2group_diff.calculate_bootstraps_var': ( 'API/confint_2group_diff.html#calculate_bootstraps_var',
31+
'dabest/_stats_tools/confint_2group_diff.py'),
3032
'dabest._stats_tools.confint_2group_diff.calculate_group_var': ( 'API/confint_2group_diff.html#calculate_group_var',
3133
'dabest/_stats_tools/confint_2group_diff.py'),
3234
'dabest._stats_tools.confint_2group_diff.calculate_weighted_delta': ( 'API/confint_2group_diff.html#calculate_weighted_delta',

dabest/_stats_tools/confint_2group_diff.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
__all__ = ['create_jackknife_indexes', 'create_repeated_indexes', 'compute_meandiff_jackknife', 'bootstrap_indices',
77
'compute_bootstrapped_diff', 'delta2_bootstrap_loop', 'compute_delta2_bootstrapped_diff',
88
'compute_meandiff_bias_correction', 'compute_interval_limits', 'calculate_group_var',
9-
'calculate_weighted_delta']
9+
'calculate_bootstraps_var', 'calculate_weighted_delta']
1010

1111
# %% ../../nbs/API/confint_2group_diff.ipynb 4
1212
import numpy as np
@@ -319,15 +319,23 @@ def calculate_group_var(control_var, control_N, test_var, test_N):
319319

320320
return pooled_var
321321

322+
def calculate_bootstraps_var(bootstraps):
322323

323-
def calculate_weighted_delta(group_var, differences):
324+
bootstraps_var_list = [np.var(x, ddof=1) for x in bootstraps]
325+
bootstraps_var_array = np.array(bootstraps_var_list)
326+
327+
return bootstraps_var_array
328+
329+
330+
331+
def calculate_weighted_delta(bootstrap_dist_var, differences):
324332
"""
325333
Compute the weighted deltas.
326334
"""
327335

328-
weight = 1 / group_var
336+
weight = np.true_divide(1, bootstrap_dist_var)
329337
denom = np.sum(weight)
330338
num = 0.0
331339
for i in range(len(weight)):
332340
num += weight[i] * differences[i]
333-
return num / denom
341+
return np.true_divide(num, denom)

dabest/_stats_tools/effsize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,11 @@ def _compute_hedges_correction_factor(n1,
392392

393393
# %% ../../nbs/API/effsize.ipynb 13
394394
@njit(cache=True)
395-
def weighted_delta(difference, group_var):
395+
def weighted_delta(difference, bootstrap_dist_var):
396396
'''
397397
Compute the weighted deltas where the weight is the inverse of the
398398
pooled group difference.
399399
'''
400400

401-
weight = np.true_divide(1, group_var)
401+
weight = np.true_divide(1, bootstrap_dist_var)
402402
return np.sum(difference*weight)/np.sum(weight)

nbs/API/confint_2group_diff.ipynb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,18 +373,26 @@
373373
" \n",
374374
" return pooled_var\n",
375375
"\n",
376+
"def calculate_bootstraps_var(bootstraps):\n",
376377
"\n",
377-
"def calculate_weighted_delta(group_var, differences):\n",
378+
" bootstraps_var_list = [np.var(x, ddof=1) for x in bootstraps]\n",
379+
" bootstraps_var_array = np.array(bootstraps_var_list)\n",
380+
" \n",
381+
" return bootstraps_var_array\n",
382+
" \n",
383+
"\n",
384+
"\n",
385+
"def calculate_weighted_delta(bootstrap_dist_var, differences):\n",
378386
" \"\"\"\n",
379387
" Compute the weighted deltas.\n",
380388
" \"\"\"\n",
381389
"\n",
382-
" weight = 1 / group_var\n",
390+
" weight = np.true_divide(1, bootstrap_dist_var)\n",
383391
" denom = np.sum(weight)\n",
384392
" num = 0.0\n",
385393
" for i in range(len(weight)):\n",
386394
" num += weight[i] * differences[i]\n",
387-
" return num / denom"
395+
" return np.true_divide(num, denom)"
388396
]
389397
}
390398
],

nbs/API/delta_objects.ipynb

Lines changed: 68 additions & 9 deletions
Large diffs are not rendered by default.

nbs/API/effsize.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,13 +507,13 @@
507507
"source": [
508508
"#| export\n",
509509
"@njit(cache=True)\n",
510-
"def weighted_delta(difference, group_var):\n",
510+
"def weighted_delta(difference, bootstrap_dist_var):\n",
511511
" '''\n",
512512
" Compute the weighted deltas where the weight is the inverse of the\n",
513513
" pooled group difference.\n",
514514
" '''\n",
515515
"\n",
516-
" weight = np.true_divide(1, group_var)\n",
516+
" weight = np.true_divide(1, bootstrap_dist_var)\n",
517517
" return np.sum(difference*weight)/np.sum(weight)"
518518
]
519519
}

nbs/API/effsize_objects.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2403,5 +2403,5 @@
24032403
}
24042404
},
24052405
"nbformat": 4,
2406-
"nbformat_minor": 2
2406+
"nbformat_minor": 4
24072407
}
29 Bytes

0 commit comments

Comments
 (0)