0todd0000 / spm1d

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

ANOVA test significant while the post hoc test is not significant. #220

Closed Shivangi2208 closed 2 years ago

Shivangi2208 commented 2 years ago

Hello Todd, I have run into issues while performing post-hoc analysis on two-way repeated-measures ANOVA tests. Could it be possible that the ANOVA test is significant and posthoc tests are non-significant? I have 17 muscles for which I am performing these tests. ANOVA reports significance for all muscles for either or both factors. Meanwhile, the paired t-tests (post-hoc analysis) reported significance for 5 muscles. I checked my codes but don't know where the problem lies. Everything seems to be fine. Is there any other test available in spm to be used for post-hoc other than the t-tests. I wanted to share my entire code and data files, however, I thought that would make the post too lengthy. Kindly help.

Regards, Shivangi

0todd0000 commented 2 years ago

Easier part first: no, spm1d does not support automated post hoc analysis.

Disagreement between ANOVA and post hoc results can occur for a variety of reasons. To narrow down the possibilities, please attach a figure or two for just one muscle to illustrate the problem. Please also paste the corresponding code into this thread.

Shivangi2208 commented 2 years ago

Thank you Todd for your quick reply. I have attached the codes for ANOVA and post-hoc tests and the relevant data file. I have also provided figures from the two tests for a single muscle. As you would observe, the ANOVA test shows significance for both factors. However, when I run post-hoc t-tests using one of the models to check for significance among the gravity pairs, I see no significance. Just to make things clearer, I will brief what I am trying to achieve. I have 10 subjects performing walking in 3 different levels of gravity and 2 models predicting the muscle activations for the same. So my factor A is number of model types i.e 2 and Factor B number of gravity levels i.e 3 and 10 subjects.

Post_hoc_using_paired_t_test_plot two_way_rm_ANOVA_plot files.zip

  1. ANOVA code clc

Musc_Act= 'C:\Users\shivangi.000\Desktop\muscle_activations.xlsx'; % %For 1st Model and all three gravities GasLat_1stModel_1stGravity = xlsread(Musc_Act,1); P = GasLat_1stModel_1stGravity(2:end,1:end); GasLat_1stModel_2ndGravity = xlsread(Musc_Act,3); Q = GasLat_1stModel_2ndGravity(2:end,1:end); GasLat_1stModel_3rdGravity = xlsread(Musc_Act,5); R = GasLat_1stModel_3rdGravity(2:end,1:end); n0 = size(P, 1); %number of group 0 observations n1 = size(Q, 1); %number of group 1 observations n2 = size(R, 1); %number of group 2 observations b0 = 0 ones(n0, 1); %group 0 labels b1 = 1 ones(n1, 1); %group 1 labels b2 = 2 * ones(n2, 1); %group 2 labels

%For 2nd Model and all three gravities GasLat_2ndModel_1stGravity = xlsread(Musc_Act,2); J = GasLat_2ndModel_1stGravity(2:end,1:end); GasLat_2ndModel_2ndGravity = xlsread(Musc_Act,4); K = GasLat_2ndModel_2ndGravity(2:end,1:end); GasLat_2ndModel_3rdGravity = xlsread(Musc_Act,6); L = GasLat_2ndModel_3rdGravity(2:end,1:end); n3 = size(J, 1); %number of group 0 observations n4 = size(K, 1); %number of group 1 observations n5 = size(L, 1); %number of group 2 observations b3 = 0 ones(n3, 1); %group 0 labels b4 = 1 ones(n4, 1); %group 1 labels b5 = 2 * ones(n5, 1); %group 2 labels

M = [P;Q;R]; %all data from model 1 for 10 subjects n6 = size(M, 1); Y = [J;K;L]; %all data from model 2 for 10 subjects n7 = size(Y, 1); a0 = 0 ones(n6,1); a1 = 1 ones(n7,1); A= [a0;a1]'; % Factor 1 which indicates the number of model types i.e 2 Z = [M;Y]; B = [b0; b1; b2; b3; b4; b5]'; % Factor 2 which indicates the number of gravities i.e 3

SUBJ = [1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10];

%spm_bs = spm1d.stats.anova1(M, A); %between-subjects model spmlist = spm1d.stats.anova2rm(Z, A, B, SUBJ); spmilist = spmlist.inference(0.05); spmilist.plot('plot_threshold_label',true, 'plot_p_values',true, 'autoset_ylim',true);

  1. Post-Hoc test code

clc

Musc_Act= 'C:\Users\shivangi.000\Desktop\muscle_activations.xlsx';

%For 1st Model and all three gravities GasLat_1stModel_1stGravity = xlsread(Musc_Act,1); P = GasLat_1stModel_1stGravity(2:end,1:end); GasLat_1stModel_2ndGravity = xlsread(Musc_Act,3); Q = GasLat_1stModel_2ndGravity(2:end,1:end); GasLat_1stModel_3rdGravity = xlsread(Musc_Act,5); R = GasLat_1stModel_3rdGravity(2:end,1:end);

%(1) Conduct SPM analysis: t21 = spm1d.stats.ttest_paired(Q, P); t32 = spm1d.stats.ttest_paired(R, Q); t31 = spm1d.stats.ttest_paired(R, P); % inference: alpha = 0.05; nTests = 3; p_critical = spm1d.util.p_critical_bonf(alpha, nTests); t21i = t21.inference(p_critical, 'two_tailed',true); t32i = t32.inference(p_critical, 'two_tailed',true); t31i = t31.inference(p_critical, 'two_tailed',true);

subplot(221); t21i.plot(); title('2ndGravity - 1stGravity') subplot(222); t32i.plot(); title('3rdGravity - 2ndGravity') subplot(223); t31i.plot(); title('3rdGravity - 1stGravity')

muscle_activations.xlsx

0todd0000 commented 2 years ago

This is MATLAB code so I am transferring the issue to the MATLAB forum here: https://github.com/0todd0000/spm1dmatlab/issues/169