rpomponio / neuroHarmonize

Harmonization tools for multi-site neuroimaging analysis. Implemented as a python package. Harmonization of MRI, sMRI, dMRI, fMRI variables with support for NIFTI images. Complements the work in Neuroimage by Pomponio et al. (2019).
https://pypi.org/project/neuroHarmonize/
MIT License
82 stars 28 forks source link

Bug in grand mean calculation of one-dimensional data #38

Closed friedrichkrohn closed 9 months ago

friedrichkrohn commented 11 months ago

Hello,

I think I found a bug at line 182 in harmonizationLearn.py: I am trying to harmonize a one-dimensional variable with one feature per subject and only site as a covariate. When calculating the grand mean, harmonizationLearn expects a two-dimensional B_hat but I only provide one feature per subject leading to a one-dimensional B_hat, which causes an error. Did I maybe code the data wrongly?

I tried to upload example data and a covariate matrix only containing the sites I would like to correct across. Does it work?

example.csv

example_site.csv

Best,

Friedrich

friedrichkrohn commented 11 months ago

For everyone struggling with this too: neurocombat works great for harmonizing non-MRI features

rpomponio commented 9 months ago

Related to #4 , harmonization fails when providing only one feature to harmonize. Closing this issue (keeping the original issue open).

rpomponio commented 8 months ago

Note, I was able to run the harmonization successfully with the following code.

import numpy as np
import pandas as pd
from neuroHarmonize import harmonizationLearn

data = pd.read_csv('example.csv', index_col=0)
covars = pd.read_csv('example_site.csv', index_col=0)

# prepare inputs to harmonize ICR
data = np.array(data)

# run harmonization without EB adjustments
model, data_adj = harmonizationLearn(data, covars, eb=False)

You don't want the empirical Bayes adjustments for a harmonization of a single variable (EB is for harmonizing multiple variables, such as regional brain volumes).