Skip to main content

Minimal Python implementation of lmeEEG for random-intercept mass-univariate M/EEG analysis

Project description

LmeEEG

Minimal Python package implementing the core lmeEEG workflow for epoched M/EEG data with random intercepts:

  1. parse a mixed-model style formula at the API edge,
  2. fit a random-intercept mixed model at each channel × timepoint,
  3. subtract the fitted random effects to obtain marginal EEG,
  4. run fast mass-univariate OLS on the marginalized data,
  5. perform max-stat, cluster, or TFCE correction.

Current scope

  • One grouping factor in the public API
  • Random intercept only
  • Trial-wise epoched data shaped (n_observations, n_channels, n_times)
  • Cluster / TFCE correction via MNE-Python when installed
  • Tiny simulation utilities for recovery / null checks

Not yet included

  • Random slopes
  • Two grouping factors in the public API
  • Real-data validation workflows
  • Parallel / distributed optimization

Basic example

import numpy as np
import pandas as pd

from lmeeeg.api.fit import fit_lmm_mass_univariate
from lmeeeg.api.infer import permute_fixed_effect
from lmeeeg.simulation.generator import simulate_random_intercept_dataset

simulated = simulate_random_intercept_dataset(
    n_subjects=10,
    n_trials_per_subject=12,
    n_channels=4,
    n_times=25,
    effect_channels=[1, 2],
    effect_times=range(8, 14),
    beta=0.8,
    seed=13,
)

fit_result = fit_lmm_mass_univariate(
    eeg=simulated.eeg,
    metadata=simulated.metadata,
    formula="y ~ condition + latency + (1|subject)",
    variable_types={
        "condition": "categorical",
        "latency": "numeric",
        "subject": "group",
    },
)

# A rich progress bar is shown during the per-feature mixed-model fits by default.
# Disable it for quiet runs with:
# from lmeeeg.api.fit import FitConfig
# fit_result = fit_lmm_mass_univariate(..., config=FitConfig(show_progress=False))

inference = permute_fixed_effect(
    fit_result=fit_result,
    effect="condition[T.B]",
    correction="maxstat",
    n_permutations=200,
    seed=13,
)

print(inference.corrected_p_values.shape)

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

lmeeeg-0.3.2.tar.gz (21.6 kB view details)

Uploaded Source

Built Distribution

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

lmeeeg-0.3.2-py3-none-any.whl (31.1 kB view details)

Uploaded Python 3

File details

Details for the file lmeeeg-0.3.2.tar.gz.

File metadata

  • Download URL: lmeeeg-0.3.2.tar.gz
  • Upload date:
  • Size: 21.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for lmeeeg-0.3.2.tar.gz
Algorithm Hash digest
SHA256 2deafcab9206f1c7ee18e56cffa6dda101b0fb2315a2693c2d28f4c5739a84b7
MD5 c3611cc8cd025005238b14e0f9276d90
BLAKE2b-256 f4a782a1935e0229cc0a2b63a7b5fa63684f17c67a8311901cd2991a63e85a21

See more details on using hashes here.

File details

Details for the file lmeeeg-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: lmeeeg-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 31.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for lmeeeg-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6a34651835c4b26cf84732d071af6719337d6d1bdbe1512defe5b79dc2e9ea4e
MD5 320e8b88cae7204f84f70fd1d4f0e63c
BLAKE2b-256 e93892b5c15eea1caf921110d426b3c98a73078b09173fd166525ca6ef2e09a1

See more details on using hashes here.

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