0todd0000 / spm1d

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

Problems with Python #87

Closed gabrielmoisan closed 5 years ago

gabrielmoisan commented 5 years ago

Hi Todd, I am having problem reading my MatLab script in Python to use 1DSPM. I have been working on this for couple weeks and I can't figure out what is wrong. I am using the same script (more or less) than my previous published project and it just won't work. I am studying ankle and knee angles and moments during walking shod and barefoot between two groups during comfortable and fast speeds. I have 21 participants per group. I am trying to do a one-way repeated measures ANOVA to compare Grp1 vs Grp2 for:

  1. barefoot comfortable walking
  2. barefoot fast walking
  3. Shod comfortable walking
  4. Shod fast walking Can you help me? See my python script and an example data attached. Projet2doc_test_x.zip

Here is the error code Python gives me. I would really appreciate your help! Gabriel

%run "E:/SPM/testspm.py"


ValueError Traceback (most recent call last)

E:\SPM\testspm.py in ()

 19 SUBJ = SUBJ2.reshape(nb_ligne,)

 20

---> 21 F = spm1d.stats.anova1rm(Y, A, SUBJ, equal_var=True)

 22

 23 Fi = F.inference(alpha=0.05)

C:\Users\cantinv\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\spm1d-0.4.0-py3.5.egg\spm1d\stats\anova\ui.py in anova1rm(Y, A, SUBJ, equal_var, roi, _force_approx0D)

114         if not equal_var:

115                 raise( NotImplementedError( 'Non-sphericity corrections are not yet implemented. Set "equal_var" to "True" to force an assumption of equal variance.' ) )

--> 116 design = designs.ANOVA1rm(A, SUBJ)

117         model   = models.LinearModel(Y, design.X, roi=roi)

118         if ((model.dim == 1) or _force_approx0D)   and   ( design.check_for_single_responses(dim=model.dim) ):

C:\Users\cantinv\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\spm1d-0.4.0-py3.5.egg\spm1d\stats\anova\designs.py in init(self, A, SUBJ)

152                 self.term_labels = ['Intercept', 'A', 'S', 'SA']

153                 self.f_terms     = [('A','SA')]

--> 154 self._check_balanced()

155                 self._assemble()

156

C:\Users\cantinv\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\spm1d-0.4.0-py3.5.egg\spm1d\stats\anova\designs.py in _check_balanced(self)

174         def _check_balanced(self):

175                 if not (self.A.balanced and self.S.balanced):

--> 176 raise( ValueError('Design must be balanced.') )

177                 if not self.S.check_balanced(self.A):

178                         raise( ValueError('Design must be balanced.') )

ValueError: Design must be balanced.

0todd0000 commented 5 years ago

Hi Gabriel,

The error means that the design is not balanced. In order to run repeated-measures ANOVA, each subject must have completed each condition.

In Python please check the number of subjects in each condition like this:

>>> np.sum(A==1) #number of subjects in Condition 1
>>> np.sum(A==2) #number of subjects in Condition 2

You will likely find that the number of subjects is different.

Please note that we are unable to check attached code/data in this forum, so please either:

Cheers, Todd

gabrielmoisan commented 5 years ago

Hi Todd, Thank you for your answer. I managed to make it works. Last quick question. What is the non-parametric equivalent of the two sample t-test in SPM? Nichols and Holmes permutation method? Thanks again for your time, Gabriel

0todd0000 commented 5 years ago

That's great, I'm glad it's working now.

A variety of non-parametric two-sample tests exist, but no single non-parametric test is equivalent to the parametric t test because all tests make slightly different assumptions. This implies that the results from the tests have slightly different meanings. Nevertheless, the probability values from all tests should converge to the same value as (a) the data become more normally distributed, and (b) the sample size gets larger.

spm1d uses the permutation approach described by Nichols and Holmes because:

Todd

gabrielmoisan commented 5 years ago

Thanks Todd. Very helpful, as always!