0todd0000 / spm1d

One-Dimensional Statistical Parametric Mapping in Python
GNU General Public License v3.0
60 stars 21 forks source link

Paired t-test indicates weird areas of statistical difference #253

Closed itbellix closed 1 year ago

itbellix commented 1 year ago

Hi, I am using SPM1D to compare two sets of time series, representing muscle activations obtained when simulating various repetition of the same movements under 2 different conditions (cond1 and cond2). I wish to analyze the resulting activations, and compare them to see if they are statistically different. I am using the paired t-test as implemented in SPM1D, and accessing the package through Matlab.

However, I am quite surprised by the results, as regions of statistical difference (corresponding to the SPM{F} statistics) are identified even when the mean of the two conditions are very similar, and without any evident variation of the standard deviations in the two population of time series. The following figure is an example of this (especially for the very mall regions identified at the end of the interval considered):

Do the grey area of statistical difference appear to make sense?

itbellix commented 1 year ago

For context, I have 18 repetitions of the movement, and I am setting up the analysis with the following lines of code:

spm = spm1d.stats.ttest_paired(cond1, cond2);   % performing a paired t-test
spmi = spm.inference(0.01);

%%% plot mean and SD:
    fig = figure;
    subplot(121)
    spm1d.plot.plot_meanSD(cond1, 'color', [0.3 0.3 1]);
    hold on
    spm1d.plot.plot_meanSD(cond2, 'color','g');

    %%% plot SPM results:
    subplot(122)
    spmi.plot();
    spmi.plot_threshold_label();
    spmi.plot_p_values();
    xticks([0, round(size(cond1,2)/4), round(size(cond1,2)/2), round(3*size(cond1,2)/4), size(cond1,2)])

    xlabel('time')
    title('Comparing 2 conditions')

where cond1 and cond2 are matrixes of shape 18 x 250 (as I have 18 repetitions which contain 250 datapoints each)

0todd0000 commented 1 year ago

Paired t-tests pertain to the mean of the paired differences (and not to group means), so try plotting the paired differences, something like this:

figure;
spm1d.plot.plot_meanSD(cond1 - cond2, 'color', [0.3 0.3 1]);

or:

figure;
plot( (cond1 - cond2)' );

Plots like this should more closely match the SPM results.

itbellix commented 1 year ago

Dear @0todd0000, thank you very much for the quick answer. Indeed, the visualization that you suggested is much more insightful than the one I was going for (I report my original one vs the new one that I am using now, hoping it might be useful for other people in the future) old

new

Just to be sure, and sorry for the very trivial question: do you think that the approach that I am taking here (in terms of the statistical test to use) makes sense?

My goal is really to distinguish whether simulating movements under cond1 or cond2 leads to differences (potentially just in parts) of the resulting muscle activations. As I am testing the mean of the paired differences, I believe that this is the relevant statistical test to be used in my situation.

0todd0000 commented 1 year ago

Based on your description of the experimental design a paired test does indeed seem appropriate.

itbellix commented 1 year ago

Dear @0todd0000, thank you once more for your support. I will close this issue as it has been fully addressed