Skip to main content

Python port of longCombat (Beer et al. 2020): longitudinal ComBat harmonization in a linear mixed-effects model framework.

Project description

longcombat-py

Python port of jcbeer/longCombat. The API mirrors neuroCombat where concepts overlap so the two can be used side-by-side.

Longitudinal ComBat uses an empirical Bayes method to harmonize the means and variances of the residuals across batches in a linear mixed-effects model framework. See:

Beer JC, Tustison NJ, Cook PA, Davatzikos C, Sheline YI, Shinohara RT, Linn KA (2020). Longitudinal ComBat: A method for harmonizing longitudinal multi-scanner imaging data. NeuroImage, 220:117129. https://doi.org/10.1016/j.neuroimage.2020.117129

Deviations from the R original — this port is not bit-identical to the R package. Please read DIFFERENCES_FROM_R.md before using, especially if comparing results to the R output.

Install

pip install longcombat-py            # core
pip install "longcombat-py[plot]"    # + matplotlib for visualization helpers

Quick start

Long-format pandas.DataFrame with one row per (subject, visit):

import pandas as pd
from longcombat import long_combat

result = long_combat(
    data=df,
    batch_col="scanner",
    id_col="subid",
    time_col="visit",
    features=["feature1", "feature2", "feature3"],
    formula="age + diagnosis*visit",     # Patsy RHS, fixed effects
    ranef="(1|subid)",                   # lme4-style random effects
)
harmonized = result.data_combat

long_combat returns a LongCombatResult with:

  • .data_combat — harmonized DataFrame ([id_col, time_col, batch_col, feature1.combat, ...])
  • .gammahat, .delta2hat — method-of-moments estimates of additive and multiplicative batch effects on the standardized residuals
  • .gammastarhat, .delta2starhat — empirical-Bayes shrunk estimates

API surface

Function R analog
long_combat longCombat
add_test addTest (LRT only — see DIFFERENCES_FROM_R.md)
mult_test multTest
batch_time_viz batchTimeViz
batch_boxplot batchBoxplot
traj_plot trajPlot

Parameter naming mirrors neuroCombat where the concept exists (batch_col, eb, mean_only). Additional concepts from longCombat (id_col, time_col, ranef, formula, niter, method) preserve the R names.

License

Artistic License 2.0. See LICENSE and NOTICE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

longcombat_py-0.1.1.tar.gz (27.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

longcombat_py-0.1.1-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

Details for the file longcombat_py-0.1.1.tar.gz.

File metadata

  • Download URL: longcombat_py-0.1.1.tar.gz
  • Upload date:
  • Size: 27.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for longcombat_py-0.1.1.tar.gz
Algorithm Hash digest
SHA256 aa02e9dee1413285ad345a4cc60ea5c2b1c241563daf7c4b685c5c3375bf113b
MD5 da3e8ad22f11de96a4320483818d221a
BLAKE2b-256 bbe59ce3d5abf178aaceb1068d24b634fec6885b06e9213a2eb08a0afac64054

See more details on using hashes here.

Provenance

The following attestation bundles were made for longcombat_py-0.1.1.tar.gz:

Publisher: publish.yml on NoiseFilterT/longcombat-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file longcombat_py-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: longcombat_py-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 23.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for longcombat_py-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fcd38374c13fc6b6996cf98e67eb31a6fb33e2935609795b50263b2d603c6568
MD5 0d6d00e717a3eb4d2f2a50a111c2253d
BLAKE2b-256 471e3bc79ce12f576b3dde6836a4b49d2715c554cc690646d0e6e3bbd7e52f88

See more details on using hashes here.

Provenance

The following attestation bundles were made for longcombat_py-0.1.1-py3-none-any.whl:

Publisher: publish.yml on NoiseFilterT/longcombat-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page