0todd0000 / spm1dmatlab

One-Dimensional Statistical Parametric Mapping in Matlab.
GNU General Public License v3.0
28 stars 13 forks source link

SPM ANOVA test #207

Open PJamali97 opened 4 months ago

PJamali97 commented 4 months ago

Hello, I would greatly appreciate it if you could answer a few questions regarding my analysis. I have conducted the SPM ANOVA test to determine if there are significant differences among 7 conditions, specifically to analyze the sensitivity of the results to these conditions. In each of the conditions, I am changing segmental masses. The output from the SPM 1d_anova test indicates that the results are not sensitive to changes in segmental masses (figure below). Is there a way to examine each distribution more closely to observe how it changes throughout the gait cycle? A more detailed graph that illustrates the process before the ANOVA graph below, highlighting why the results are far from significant at any time point would be very helpful for me to interpret my findings.

Capture

Thank you for the SPM toolbox and thank you in advance for your assistance!

0todd0000 commented 4 months ago

Thank you for your questions and also for your kind feedback. :)

I suggest plotting condition means with standard deviation clouds, which will provide a qualitative explanation of the ANOVA results.

One way to do this is with spm1d.plot.plot_meanSD. Here is a two-group example:

dataset = spm1d.data.uv1d.tpaired.PlantarArchAngle();
[yA,yB] = deal(dataset.YA, dataset.YB);
figure('position', [0 0 1000 300])
subplot(121)
spm1d.plot.plot_meanSD(yA, 'color','k');
hold on
spm1d.plot.plot_meanSD(yB, 'color','r');

You will likely see very similar means and/or very large SD values.

PJamali97 commented 4 months ago

Thank you very much, Professor Pataky. This has been very helpful.

PJamali97 commented 4 months ago

I have a follow-up question about the mean and SD curves: How many standard deviations from the mean are implemented in the SD part of the code? I am assuming it is 1 but wanted to make sure of that. Thank you in advance for your assistance!

0todd0000 commented 4 months ago

That is correct, 1 SD. The width however is 2 SD (1 SD above the mean and 1 SD below the mean).

PJamali97 commented 4 months ago

That makes sense. Thank you very much. I have a further question about the normality test. I used the ex1d_normality_anova1 code to test the normal distribution of my data and I am getting the error below. I am using the same data format I previously used to run the SPM ANOVA test. Now, I want to determine whether to rely on parametric or non-parametric results.

Here is the error: Error using ~ Operands must be real.

Error in spm_P_RF (line 94) if ~k || ~D

Error in spm_P (line 51) [P,p,Em,En,EN] = spm_P_RF(c,k,Z,df,STAT,R,n);

Error in spm1d.rft1d.RFTProbability/cluster (line 15) p = spm_P(1, k, u, c.df, c.STAT, c.resels, c.n, c.Q);

Error in spm1d.rft1d.chi2.p_cluster_resels (line 50) p = calc.p.cluster(k, u);

Error in spm1d.geom.Cluster/inference (line 55) p = spm1d.rft1d.chi2.p_cluster_resels(k, u, df(2), resels, 'withBonf',withBonf, 'nNodes',nNodes);

Error in spm1d.stats.spm.SPM/cluster_inference (line 124) clusters{i} = clusters{i}.inference(self.STAT, self.df, self.fwhm, self.resels, two_tailed, withBonf, self.nNodes);

Error in spm1d.stats.spm.SPM/inference (line 92) [clusters,p] = self.cluster_inference(clusters, two_tailed, withBonf);

Error in ex1d_normality_anova1_edited (line 14) spmi = spm.inference(0.05);

It seems like there is something wrong with how the data is formatted but I am using the same format of the spm anova example. My matrix A consists of 7 conditions, with each condition spanning 54 rows (totaling 378 rows). Specifically, rows 1 to 54 correspond to condition 1, rows 55 to 108 to condition 2, and so forth. My matrix y has dimensions 378 by 100, where every block of 54 rows corresponds to one condition.

I would greatly appreciate your assistance! Thank you!

0todd0000 commented 4 months ago

I've not seen this error before so I'm not sure what is causing it...

Can you please confirm whether you can run the example one-way ANOVA normality test?

PJamali97 commented 4 months ago

Yes, I can run this code and see the results. I only change the loading of the data part of this code and I get this error. Thank you!

0todd0000 commented 4 months ago

OK, if the example script runs without errors it suggests that something may be odd in the data. It may be difficult to find the source of the problem without having access to the data. Could I ask that you either post the data here (as a .mat file). If you prefer to not share publicly could you please send it to: consulting@spm1d.org ?

PJamali97 commented 4 months ago

I have sent a sample dataset to the email address you provided. Thank you for your assistance!

0todd0000 commented 4 months ago

Hello, apologies for the delay. I've found the source of the problem but not yet a solution. The problem is that the data are highly bimodal, which can be seen most clearly in the 89th column:

y = xlsread( 'Y.xlsx' );
hist( y(:,89) );

This bimodality produces very large test statistic values, including a value too large to be calculated (i.e., infinite) for the 89th column.

There should be a relatively easy fix for this case, but please give me a few days to research a solution and implement a fix.

PJamali97 commented 4 months ago

Hello Professor Pataky, That makes sense. Thank you very much for looking into this issue.

PJamali97 commented 3 months ago

Hello Professor Pataky, I wanted to follow up on the issue regarding the error caused by large test statistic values. Could you please let me know if a fix has been implemented? Thank you!

0todd0000 commented 3 months ago

I apologize for the delay. Please find that a fix has been implemented in the newest version of spm1d-matlab (v0.4.12). Please access the updated code here. Please note that this fix will affect only cases where the test statistic approaches infinity; the fix is simply places numerical bounds on the results and is unlikely to affect interpretation.

Thank you again for reporting this bug!

PJamali97 commented 3 months ago

Hello Professor Pataky, Thank you so much for fixing the issue. I truly appreciate your support and time. Thank you again!

PJamali97 commented 2 months ago

Dear Professor Pataky,

I have a few more questions regarding my analysis, and I would greatly appreciate your guidance. I switched to using the one-way repeated measures ANOVA code to test for significant differences among the 7 conditions in my study, which includes 27 participants.

  1. I have formatted my data according to the example provided for SPM, but I encountered a warning (below) when running the code, which makes me question the validity of the results. I have attached the A and SUBJ Excel files to clarify the structure of my data and I would appreciate it if you could clarify why I might be getting this warning.

  2. Is there a way to examine what is happening before the SPM (F) graph is generated? For example, could I view paired difference curves between every two conditions being tested for ANOVA? This would help me better understand and interpret the results and ensure the validity of the results.

  3. Also, do I need to test for normality when using the one-way repeated measures ANOVA in this context? I only see one output from the code (not specified as parametric or non-parametric) so I assume the repeated measures ANOVA test does not rely on the normality assumption. Am I right?

Warning: Only one observation per subject found. Residuals and inference will be approximate. To avoid approximate residuals: (a) Add multiple observations per subject and per condition, and (b) ensure that all subjects and conditions have the same number of observations.

In spm1d.stats.anova.designs/ANOVA1rm/check_for_single_responses (line 33) In spm1d.stats.anova1rm (line 13) In ex1d_anova1rm_within (line 9)

Here is the code I am using: https://github.com/0todd0000/spm1dmatlab/blob/master/examples/stats1d/ex1d_anova1rm.m.

Thank you very much for your assistance. Best regards,

A.xlsx SUBJ.xlsx

0todd0000 commented 2 months ago

I have formatted my data according to the example provided for SPM, but I encountered a warning (below) when running the code, which makes me question the validity of the results. I have attached the A and SUBJ Excel files to clarify the structure of my data and I would appreciate it if you could clarify why I might be getting this warning.

This warning can be ignored. Please see discussions regarding this warning here:

https://github.com/0todd0000/spm1dmatlab/issues?q=%22one+observation+found%22 https://github.com/0todd0000/spm1d/issues?q=%22one+observation+found%22



Is there a way to examine what is happening before the SPM (F) graph is generated? For example, could I view paired difference curves between every two conditions being tested for ANOVA? This would help me better understand and interpret the results and ensure the validity of the results.

This must be done manually. The current version of spm1d does not support automated post hoc testing.



Also, do I need to test for normality when using the one-way repeated measures ANOVA in this context? I only see one output from the code (not specified as parametric or non-parametric) so I assume the repeated measures ANOVA test does not rely on the normality assumption. Am I right?

Note first that all functions in spm1d.stats use parametric inference which is indeed based on an assumption of normality. Checking normality, or rather testing for non-normality, is indeed possible using the functions in spm1d.stats.normality, but this may not be strictly necessary. You could instead simply run the corresponding nonparametric procedure spm1d.stats.nonparam.anova1rm and compare the results to those of parametric inference. In many cases the results will be qualitatively similar, which implies that the parametric procedure's assumption of normality is inconsequential for that particular dataset.

Parametric and nonparametric results tend to diverge primarily when effect sizes are relatively small, or just large enough to reach significance. In this case the parametric and nonparametric procedures could yield differing significance results. However, even in this case normality testing is not strictly necessary because relatively small effects should be interpreted cautiously regardless of procedure.

PJamali97 commented 2 months ago

Hello Professor Pataky, Thank you very much for your response; It was very helpful. I truly appreciate your support and time. Thank you again!