0todd0000 / spm1d

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

One-way ANOVA in Matlab: error #104

Closed VSGhent closed 4 years ago

VSGhent commented 5 years ago

Dear, I am writing with regard to some problems I encounter during an one-way ANOVA analysis (SPM) in Matlab. I ran the following script:

%(0) Load data: Y0 = xlsread('CON_ScapulaThoraxJAngle_C1_Y.xlsx'); Y1 = xlsread('EDS_ScapulaThoraxJAngle_C1_Y.xlsx'); Y2 = xlsread('MDL_ScapulaThoraxJAngle_C1_Y.xlsx');

plot(Y0','k-') hold on plot(Y1','r-') plot(Y2','b-')

% Conduct SPM analysis: spm = spm1d.stats.anova1(Y0, Y1, Y2, 'equal_var',false); spmi = spm.inference(0.05, 'interp',true);

% Conduct post hoc tests: t21 = spm1d.stats.ttest2(Y1, Y0); t32 = spm1d.stats.ttest2(Y2, Y1); t31 = spm1d.stats.ttest2(Y2, Y0);

% 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);

close all subplot(221); t21i.plot(); ylim([-40 40]); title('EDS - CON') spmi.plot_p_values(); subplot(222); t32i.plot(); ylim([-40 40]); title('MDL - EDS') spmi.plot_p_values(); subplot(223); t31i.plot(); ylim([-40 40]); title('MDL - CON') spmi.plot_pvalues();

However, every time I try to run the script, I get the same error:

Error Matlab

I have searched for answers at the internet but I did not found anything that solved this problem. I think the problem may be lying in the arrangement of my datasets in excel, however, I have executed two-tailed t-tests on these datasets and then no errors occur.

Could you please enlighten on this error? Do I have to rearrange my data in excel in order to make this script work?

Best regards, Valentien

0todd0000 commented 5 years ago

Hi Valentien, I think the error appears because anova1 expects just two variables: Y and A, where Y is the data array and where A is a vector of group labels. Try vertically stacking the Y variables and creating an A vector as follows:

n0 = size(Y0, 1);  %number of group 0 observations
n1 = size(Y1, 1);  %number of group 1 observations
n2 = size(Y2, 1);  %number of group 2 observations

a0 = 0 * ones(n0, 1);  %group 0 labels
a1 = 1 * ones(n1, 1);  %group 1 labels
a2 = 2 * ones(n2, 1);  %group 2 labels

Y  = [Y0; Y1; Y2];  %all data
A  = [a0; a1; a2];  %all group labels

spm = spm1d.stats.anova1(Y, A, 'equal_var',false);
VSGhent commented 5 years ago

Dear Todd,

Thank you very much for your help! This indeed solved the problem.

Kind regards, Valentien

VSGhent commented 5 years ago

However, if I run spm = spm1d.stats.anova1(Y, A, 'equal_var',false); another error occurs: Knipsel

This error does not occur when I delete the 'equal_var',false part and just run spm = spm1d.stats.anova1(Y, A);

0todd0000 commented 5 years ago

Oops! Sorry about that. The equal_var keyword argument is no longer supported. Nonsphericity (unequal group variances) will be supported more comprehensively in future spm1d releases.

VSGhent commented 5 years ago

Thank you for your help!

Shivangi2208 commented 3 years ago

Hello, I am new to spm1d and have tried to perform t-test using data from excel sheets. However, the spm plots show x-axis as the number of columns in my data and not the data in the first row which represents percentage of gait cycle. Please let me know is there a required format for xlsx files to be used for spm1d?

Regards, Shivangi

0todd0000 commented 3 years ago

Hello Shivangi, I'll respond to this question in Issue #156.