Skip to content

Commit e2770ad

Browse files
committed
Update v0.0.8
1 parent 90d6bf9 commit e2770ad

15 files changed

Lines changed: 357 additions & 1359 deletions

File tree

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,16 @@ For optimal parallel performance, we recommend installing `llvm-openmp` if using
2929
conda install -c conda-forge llvm-openmp
3030
```
3131

32-
For `R` users, `reticulate` can be used to call `causarray` from `R`.
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.
3342
The documentation and tutorials using both `Python` and `R` are available at [causarray.readthedocs.io](https://causarray.readthedocs.io/en/latest/).
3443

3544

causarray/DR_learner.py

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,24 @@
1010
from causarray.utils import reset_random_seeds, pprint, tqdm, comp_size_factor, _filter_params
1111

1212

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+
1331

1432
def compute_causal_estimand(
1533
estimand,
@@ -369,9 +387,17 @@ def LFC(
369387
Returns
370388
-------
371389
df_res : DataFrame
372-
Test results with effect estimates and inference columns, raw
373-
``mean_control`` and ``mean_treated`` counterfactual means, and an
374-
``estimable`` flag (plus ``trt`` for multiple treatments).
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.
375401
"""
376402

377403
def estimand(etas, A, **kwargs):
@@ -458,12 +484,13 @@ def estimand(etas, A, **kwargs):
458484
if K is None:
459485
K = 2 if cross_est else 1
460486

461-
return compute_causal_estimand(
487+
df_res, estimation = compute_causal_estimand(
462488
estimand, Y, W, A, W_A, family, offset,
463489
Y_hat=Y_hat, pi_hat=pi_hat, mask=mask,
464490
fdx=fdx, fdx_alpha=fdx_alpha, fdx_c=fdx_c,
465491
verbose=verbose, backend=backend, K=K, ps_clip=ps_clip,
466492
ps_class_weight=ps_class_weight, **kwargs)
493+
return _add_log2fc_columns(df_res), estimation
467494

468495

469496

@@ -662,8 +689,10 @@ def gcate_lfc_batch(
662689
Returns
663690
-------
664691
df_res : DataFrame
665-
Concatenated result from all batches. Includes a ``'batch'``
666-
column with the 0-based batch index so batches can be identified.
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.
667696
"""
668697
import gc
669698
from causarray.gcate import fit_gcate_batch
@@ -834,7 +863,7 @@ def gcate_lfc_batch(
834863
result = pd.concat(
835864
[new_dfs[i] for i in all_indices], axis=0
836865
).reset_index(drop=True)
837-
return result
866+
return _add_log2fc_columns(result)
838867

839868

840869
def LFC_batch(*args, **kwargs):

causarray/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.0.7"
1+
__version__ = "0.0.8"

docs/CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
# Changelog
22

3+
## [0.0.8] - 2026-07-20
4+
5+
### Added
6+
7+
- `LFC()` and `gcate_lfc_batch()` results now include `log2fc` and
8+
`log2fc_se`, the base-2 equivalents of the existing natural-log `tau` and
9+
`std` columns. Existing statistics, p-values, and discoveries are unchanged.
10+
11+
### Changed
12+
13+
- Older compatible `gcate_lfc_batch()` caches are upgraded in memory with the
14+
new log2-scale columns when resumed.
15+
- The Python environment now requires NumPy >2. A separate `causarray-r`
16+
environment supplies R 4.4 and a NumPy-2-compatible `reticulate`, avoiding
17+
changes to the Python numerical stack for R interoperability.
18+
319
## [0.0.7] - 2026-07-18
420

521
### Added

docs/source/main_function/lfc.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,28 @@ with effect estimates, standard errors, and BH-adjusted p-values.
99
For screens with hundreds of perturbations use :func:`gcate_lfc_batch`, which
1010
runs GCATE and LFC in batches to keep peak memory bounded.
1111

12+
Effect-size columns
13+
-------------------
14+
15+
The returned DataFrame reports the treatment-versus-control effect on both
16+
natural-log and base-2 scales:
17+
18+
================= ===========================================================
19+
Column Definition
20+
================= ===========================================================
21+
``tau`` Natural logarithm of the treated/control mean ratio.
22+
``std`` Standard error of ``tau`` on the natural-log scale.
23+
``log2fc`` Base-2 log fold change, exactly ``tau / log(2)``.
24+
``log2fc_se`` Standard error of ``log2fc``, exactly ``std / log(2)``.
25+
================= ===========================================================
26+
27+
``log2fc_se`` is the standard error of the estimated log2 fold change, not the
28+
sample standard deviation of expression. The rescaling leaves ``stat``,
29+
p-values, adjusted p-values, and discoveries unchanged. ``tau`` and ``std``
30+
remain available for backward compatibility. The same columns are returned by
31+
``gcate_lfc_batch``; compatible caches made by older versions are upgraded in
32+
memory when loaded.
33+
1234
Choosing the variance estimator
1335
-------------------------------
1436

0 commit comments

Comments
 (0)