causarray 0.0.7__tar.gz → 0.0.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {causarray-0.0.7 → causarray-0.0.8}/PKG-INFO +11 -2
- {causarray-0.0.7 → causarray-0.0.8}/README.md +10 -1
- {causarray-0.0.7 → causarray-0.0.8}/causarray/DR_learner.py +65 -23
- causarray-0.0.8/causarray/__about__.py +1 -0
- causarray-0.0.7/causarray/__about__.py +0 -1
- {causarray-0.0.7 → causarray-0.0.8}/.gitignore +0 -0
- {causarray-0.0.7 → causarray-0.0.8}/LICENSE +0 -0
- {causarray-0.0.7 → causarray-0.0.8}/causarray/DR_estimation.py +0 -0
- {causarray-0.0.7 → causarray-0.0.8}/causarray/DR_inference.py +0 -0
- {causarray-0.0.7 → causarray-0.0.8}/causarray/__init__.py +0 -0
- {causarray-0.0.7 → causarray-0.0.8}/causarray/diagnostics.py +0 -0
- {causarray-0.0.7 → causarray-0.0.8}/causarray/gcate.py +0 -0
- {causarray-0.0.7 → causarray-0.0.8}/causarray/gcate_glm.py +0 -0
- {causarray-0.0.7 → causarray-0.0.8}/causarray/gcate_likelihood.py +0 -0
- {causarray-0.0.7 → causarray-0.0.8}/causarray/gcate_opt.py +0 -0
- {causarray-0.0.7 → causarray-0.0.8}/causarray/nb_glm_fast.py +0 -0
- {causarray-0.0.7 → causarray-0.0.8}/causarray/utils.py +0 -0
- {causarray-0.0.7 → causarray-0.0.8}/pyproject.toml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: causarray
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.8
|
|
4
4
|
Summary: causarray is a Python module for simultaneous causal inference with an array of outcomes.
|
|
5
5
|
Author-email: Jin-Hong Du <jinhongd@hku.hk>, Maya Shen <myshen@andrew.cmu.edu>, Hansruedi Mathys <mathysh@pitt.edu>, Kathryn Roeder <jinhongd@hku.hk>
|
|
6
6
|
Maintainer-email: Jin-Hong Du <jinhongd@hku.hk>
|
|
@@ -54,7 +54,16 @@ For optimal parallel performance, we recommend installing `llvm-openmp` if using
|
|
|
54
54
|
conda install -c conda-forge llvm-openmp
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
-
For `R` users, `reticulate` can be used to call `causarray` from
|
|
57
|
+
For `R` users, `reticulate` can be used to call `causarray` from R while
|
|
58
|
+
keeping NumPy >2 in the Python environment. Create the separate R environment
|
|
59
|
+
with a current NumPy-2-compatible reticulate build:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
conda env create -f environment-r.yaml
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
The R tutorial runs from `causarray-r` and connects to the Python package in
|
|
66
|
+
the `causarray` environment.
|
|
58
67
|
The documentation and tutorials using both `Python` and `R` are available at [causarray.readthedocs.io](https://causarray.readthedocs.io/en/latest/).
|
|
59
68
|
|
|
60
69
|
|
|
@@ -29,7 +29,16 @@ For optimal parallel performance, we recommend installing `llvm-openmp` if using
|
|
|
29
29
|
conda install -c conda-forge llvm-openmp
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
For `R` users, `reticulate` can be used to call `causarray` from
|
|
32
|
+
For `R` users, `reticulate` can be used to call `causarray` from R while
|
|
33
|
+
keeping NumPy >2 in the Python environment. Create the separate R environment
|
|
34
|
+
with a current NumPy-2-compatible reticulate build:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
conda env create -f environment-r.yaml
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The R tutorial runs from `causarray-r` and connects to the Python package in
|
|
41
|
+
the `causarray` environment.
|
|
33
42
|
The documentation and tutorials using both `Python` and `R` are available at [causarray.readthedocs.io](https://causarray.readthedocs.io/en/latest/).
|
|
34
43
|
|
|
35
44
|
|
|
@@ -10,6 +10,24 @@ from causarray.DR_inference import fdx_control, bh_correction
|
|
|
10
10
|
from causarray.utils import reset_random_seeds, pprint, tqdm, comp_size_factor, _filter_params
|
|
11
11
|
|
|
12
12
|
|
|
13
|
+
def _add_log2fc_columns(df_res):
|
|
14
|
+
"""Add base-2 LFC aliases while retaining natural-log result columns."""
|
|
15
|
+
log2 = np.log(2.0)
|
|
16
|
+
log2fc = df_res['tau'].to_numpy() / log2
|
|
17
|
+
log2fc_se = df_res['std'].to_numpy() / log2
|
|
18
|
+
|
|
19
|
+
# Recompute existing aliases as well as missing ones. This normalizes
|
|
20
|
+
# mixed old/new frames loaded from resumable batch caches and guarantees
|
|
21
|
+
# that the aliases remain exact transformations of tau and std.
|
|
22
|
+
for name in ('log2fc', 'log2fc_se'):
|
|
23
|
+
if name in df_res.columns:
|
|
24
|
+
df_res.pop(name)
|
|
25
|
+
insert_at = df_res.columns.get_loc('std') + 1
|
|
26
|
+
df_res.insert(insert_at, 'log2fc', log2fc)
|
|
27
|
+
df_res.insert(insert_at + 1, 'log2fc_se', log2fc_se)
|
|
28
|
+
return df_res
|
|
29
|
+
|
|
30
|
+
|
|
13
31
|
|
|
14
32
|
def compute_causal_estimand(
|
|
15
33
|
estimand,
|
|
@@ -301,19 +319,29 @@ def LFC(
|
|
|
301
319
|
|
|
302
320
|
* ``'unequal'`` (default, v0.0.6+): Welch variance
|
|
303
321
|
``s₀²/n₀ + s₁²/n₁`` with Welch-Satterthwaite degrees of
|
|
304
|
-
freedom; p-values use the t-distribution.
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
322
|
+
freedom; p-values use the t-distribution. Prefer this estimator when
|
|
323
|
+
treatment and control sample sizes or effective sample sizes are
|
|
324
|
+
meaningfully unbalanced, when arm-specific pseudo-outcome variances
|
|
325
|
+
may differ, and for case-control, bulk, and donor-level pseudo-bulk
|
|
326
|
+
analyses. Independence of the rows does not imply equal
|
|
327
|
+
treatment-arm variances, and biological heterogeneity or imbalance
|
|
328
|
+
can make pooled inference anti-conservative.
|
|
310
329
|
* ``'pooled'``: pooled-variance estimator ``(s² + eps_var) / n``.
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
330
|
+
For a small, approximately balanced perturbation comparison, this
|
|
331
|
+
estimator may provide better power when the independent sampling
|
|
332
|
+
units and arm-specific pseudo-outcome variances are reasonably
|
|
333
|
+
comparable. Treat it as an opt-in, empirically justified analysis,
|
|
334
|
+
not as an automatic choice for every small study. Balanced sample
|
|
335
|
+
counts alone are insufficient for case-control data, where biological
|
|
336
|
+
heterogeneity commonly favors ``'unequal'``. Pooled inference can
|
|
337
|
+
produce substantially smaller standard errors and many more
|
|
338
|
+
discoveries.
|
|
339
|
+
|
|
340
|
+
There is no universal arm-size ratio at which the choice should switch.
|
|
341
|
+
Inspect nominal and propensity-weighted effective sample sizes,
|
|
342
|
+
arm-specific pseudo-outcome variability, and sensitivity of the
|
|
343
|
+
discoveries. When those diagnostics are uncertain, retain
|
|
344
|
+
``'unequal'``.
|
|
317
345
|
|
|
318
346
|
``'unequal'`` accommodates arm-specific variance but does not model
|
|
319
347
|
within-donor or within-subject correlation. Repeated cells from the
|
|
@@ -359,9 +387,17 @@ def LFC(
|
|
|
359
387
|
Returns
|
|
360
388
|
-------
|
|
361
389
|
df_res : DataFrame
|
|
362
|
-
Test results with effect
|
|
363
|
-
``
|
|
364
|
-
``
|
|
390
|
+
Test results with natural-log effect estimate ``tau`` and standard
|
|
391
|
+
error ``std``, together with their base-2 equivalents ``log2fc`` and
|
|
392
|
+
``log2fc_se``. The fold change is treatment relative to control, and
|
|
393
|
+
``log2fc_se`` is a standard error (not a sample standard deviation).
|
|
394
|
+
The result also contains inference columns, raw ``mean_control`` and
|
|
395
|
+
``mean_treated`` counterfactual means, and an ``estimable`` flag (plus
|
|
396
|
+
``trt`` for multiple treatments).
|
|
397
|
+
|
|
398
|
+
.. versionadded:: 0.0.8
|
|
399
|
+
Added the ``log2fc`` and ``log2fc_se`` convenience columns. The
|
|
400
|
+
original natural-log ``tau`` and ``std`` columns remain unchanged.
|
|
365
401
|
"""
|
|
366
402
|
|
|
367
403
|
def estimand(etas, A, **kwargs):
|
|
@@ -448,12 +484,13 @@ def LFC(
|
|
|
448
484
|
if K is None:
|
|
449
485
|
K = 2 if cross_est else 1
|
|
450
486
|
|
|
451
|
-
|
|
487
|
+
df_res, estimation = compute_causal_estimand(
|
|
452
488
|
estimand, Y, W, A, W_A, family, offset,
|
|
453
489
|
Y_hat=Y_hat, pi_hat=pi_hat, mask=mask,
|
|
454
490
|
fdx=fdx, fdx_alpha=fdx_alpha, fdx_c=fdx_c,
|
|
455
491
|
verbose=verbose, backend=backend, K=K, ps_clip=ps_clip,
|
|
456
492
|
ps_class_weight=ps_class_weight, **kwargs)
|
|
493
|
+
return _add_log2fc_columns(df_res), estimation
|
|
457
494
|
|
|
458
495
|
|
|
459
496
|
|
|
@@ -634,10 +671,13 @@ def gcate_lfc_batch(
|
|
|
634
671
|
lfc_kwargs : dict or None
|
|
635
672
|
Extra keyword arguments forwarded to :func:`LFC`
|
|
636
673
|
(e.g. ``usevar``, ``fdx``, ``thres_min``). Retain the default
|
|
637
|
-
``usevar='unequal'``
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
674
|
+
``usevar='unequal'`` when arm sizes or effective sample sizes are
|
|
675
|
+
meaningfully unbalanced, when arm-specific variability may differ, and
|
|
676
|
+
for case-control, bulk, or pseudo-bulk analyses. For a small,
|
|
677
|
+
approximately balanced perturbation comparison with comparable
|
|
678
|
+
pseudo-outcome variability, ``lfc_kwargs=dict(usevar='pooled')`` may
|
|
679
|
+
improve power. There is no universal balance threshold; compare the
|
|
680
|
+
relevant diagnostics and retain ``'unequal'`` when uncertain.
|
|
641
681
|
**kwargs
|
|
642
682
|
Additional arguments forwarded to both :func:`fit_gcate_batch` and
|
|
643
683
|
:func:`LFC`. When a key collides with ``gcate_kwargs`` /
|
|
@@ -649,8 +689,10 @@ def gcate_lfc_batch(
|
|
|
649
689
|
Returns
|
|
650
690
|
-------
|
|
651
691
|
df_res : DataFrame
|
|
652
|
-
Concatenated result from all batches.
|
|
653
|
-
|
|
692
|
+
Concatenated result from all batches. Includes natural-log ``tau`` and
|
|
693
|
+
``std`` columns, base-2 ``log2fc`` and ``log2fc_se`` columns, and a
|
|
694
|
+
``'batch'`` column with the 0-based batch index. Older compatible
|
|
695
|
+
caches containing only ``tau`` and ``std`` are upgraded in memory.
|
|
654
696
|
"""
|
|
655
697
|
import gc
|
|
656
698
|
from causarray.gcate import fit_gcate_batch
|
|
@@ -821,7 +863,7 @@ def gcate_lfc_batch(
|
|
|
821
863
|
result = pd.concat(
|
|
822
864
|
[new_dfs[i] for i in all_indices], axis=0
|
|
823
865
|
).reset_index(drop=True)
|
|
824
|
-
return result
|
|
866
|
+
return _add_log2fc_columns(result)
|
|
825
867
|
|
|
826
868
|
|
|
827
869
|
def LFC_batch(*args, **kwargs):
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.0.8"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.0.7"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|