0todd0000 / spm1d

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

Comparing within subjects performing the same task in two conditions and between the entire cohort. #234

Closed stamstamNitzan closed 1 year ago

stamstamNitzan commented 1 year ago

Hey Todd, I have collected kinetic (force plates) and kinematic (motion capture system) data from 17 participants walking in two conditions, the first is with an ankle device and the second is without the device. After processing the data in Visual3D I have the normalized ankle flexion moment and flexion angle mean and SD of each subject in each condition. I was wondering what would be a good way to see the effect of the device on the moment and angle? I have performed a paired sample t-test (not SPM) on the minimum and on the maximum of each condition and found a significant difference in the maximum flexion moment. So, my reasoning for performing SPM is to see the effect on the entire gait cycle and not just min and max. The hypothesis is that there shouldn't be a difference between condition. In MATLAB I have created 4 variable matrixes (angle with device, angle without device, moment with device, and moment without device), each one is 17x101, and each row is the normalized mean of a subject. Thank you very much for the information and time you put in!

jwvrente commented 1 year ago

Dear Nitzan,

Thank you for your question. It would indeed be appropriate to perform a paired samples t-test in SPM to test the effect of the ankle device on the moment and/or angle data. Organising the data in 2 matrices of 17x101 would be appropriate per test.

Kind regards, Jos

stamstamNitzan commented 1 year ago

Hey Jos,

Thank you for you answer.

Is it correct to compare each participants to himself/herself? The values (moment/angle) of the individuals are different from each other. What would be a good example in SPM from the examples folder?

Kind regards, Nitzan

m-a-robinson commented 1 year ago

Hello,

Yes this is correct - each row of data in your matrix for condition one should correspond to the same row in your data matrix for condition two. In a paired design you are testing the same participants under different conditons e.g. with and without a device.

Try ex1d_ttest_paired.m if using Matlab.

Regards Mark

thelexmeister commented 1 year ago

Hello

I'm trying to do almost the same thing (101 data points of a biomechanics variable for each participant between two conditions), but I'm in python. I'm not sure how to set up my data. I read in the file. Created series for Y and SUBJ, and a datafile for A. The error says "Design must be balanced." It is balanced, but perhaps my arrays have the wrong dimension? I think I'm designating Y and SUBJ incorrectly (I can't see any other documentation or examples of how to organize and designate these variables.)

Thank you in advance for your assistance.

stamstamNitzan commented 1 year ago

Are you using the example ex1d_ttest_paired.m for python? In matlab there isn't Y and SUBJ, only two matrixes (one for each condition).

thelexmeister commented 1 year ago

No, I am not using the .m file. I have copied the .py. I appreciate that others may make this mistake as it is something I might do in one of those moments, but unfortunately, this is not as simple as that.

What I did was read in my data. Established my variables: Y = Col 1 (24 rows, 1-12, 1-12, one column) - I had 12 participants SUBJ = Col 2 (24 rows, 12 0s, 12 1s, one column) - 2 conditions A = Col 3:Col103 (24 rows, 101 data points) - a stride's worth of data for one variable, normalized 0-100%

Then, I get to line: Frm = spm1d.stats.anova1rm(Y, A, Subj, equal_var)

and I get this: ValueError: Design must be balanced.

Thank you

I also have another question that, with your experience in this area, you may be able to help me with. This is, obviously, my first time using SPM and I am actually trying it out because of a reviewer's comment. The real problem for me is I actually have 7 conditions. I saw that if I ran all 7 at once it would give me an overall answer (yes there is a significant difference somewhere) but, like an ANOVA, it won't tell me where. I decided just to run an SPM between the two conditions that show an obvious change in shape in the time series data (it definitely passes the eye-test), but how would you suggest I handle this? Is there a preferred post-hoc test with SPM to show between which conditions there is significance? Or can I run 7 SPMs, first condition - second condition, second condition - third condition, third condition - fourth condition, and so on, and use a correction factor on the alpha to take the 7 tests into account to reduce the potential statistical error?

Thank you again! I really appreciate your willingness to help out with this.

0todd0000 commented 1 year ago

If you swap Y and A it might work. All spm1d routines require that the first argument Y is the dependent variable. In the following call:

Frm = spm1d.stats.anova1rm(Y, A, SUBJ)

where J and Q are sample size and number of continuum nodes, respectively.

If there are only two conditions then you might want to try a paired t test instead:

y0 = Y[:12] # condition 0, first 12 observations
y1 = Y[12:] # condition 1, last 12 observations
t  = spm1d.stats.ttest_paired(y0, y1)

This requires that y0 and y1 have the same subject ordering (i.e., the n-th observation in both y0 and y1 should represent the same subject.)

For questions regarding post hoc tests please refer to other issues like these ones. If those don't address your questions then please create a new issue.

thelexmeister commented 1 year ago

Thank you so much for this response. This helped a lot and reading the other responses too. Got it to work and I appreciate your help!