Minimal Python implementation of lmeEEG for random-intercept mass-univariate M/EEG analysis
Project description
Minimal Python package implementing the core lmeEEG workflow for epoched M/EEG/source-space data with random intercepts:
- parse a mixed-model style formula at the API edge,
- fit a random-intercept mixed model at each channel × timepoint,
- subtract the fitted random effects to obtain marginal EEG,
- run fast mass-univariate OLS on the marginalized data,
- 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)or(n_observations, n_sources, n_times) - Optional source-space metadata with
space="source"andsource_names/location_names - Chunked OLS and max-stat permutation paths over the location/time axes
- 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.4.0.tar.gz
(30.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
lmeeeg-0.4.0-py3-none-any.whl
(42.6 kB
view details)
File details
Details for the file lmeeeg-0.4.0.tar.gz.
File metadata
- Download URL: lmeeeg-0.4.0.tar.gz
- Upload date:
- Size: 30.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61747bb884e6b61735b4aa9452235d2955171230a463e20add9c2b8ec5a553eb
|
|
| MD5 |
49b5374ec07fa9e1c289f792513dd11c
|
|
| BLAKE2b-256 |
d634d87fa8a7f7430b974a81658c36a7e8c74ef55bd6ba10866fb074f1d73e89
|
File details
Details for the file lmeeeg-0.4.0-py3-none-any.whl.
File metadata
- Download URL: lmeeeg-0.4.0-py3-none-any.whl
- Upload date:
- Size: 42.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a115c7ee82eb44afd32a03858f12f84663a000e42f92b99cdb1d67c1681d9e6
|
|
| MD5 |
cdfe4dbee17a1fd2ba994d048c840531
|
|
| BLAKE2b-256 |
c4e0e837c9ccd99c5a1c6191d8484f2a5abaec8dfd19a7a1b475124d3bb6fd01
|