0todd0000 / spm1d

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

Two-sample Hotelling’s T2 test plots #34

Closed fmoissenet closed 8 years ago

fmoissenet commented 8 years ago

Dear Todd Pataky,

I am trying to use the function "Two-sample Hotelling’s T2 test". Based on the example "./spm1d/examples/stats1d/ex_hotellings2_Besier2009muscleforces.py", I prepared the following code:

import os,sys import pandas as pd from matplotlib import pyplot import spm1d

(0) Load data:

args=[] for arg in sys.argv: args.append( arg) YA = pd.read_csv(args[1]).as_matrix().T YB = pd.read_csv(args[2]).as_matrix().T

(1) Conduct test:

alpha = 0.05 T2 = spm1d.stats.hotellings2(YA, YB) T2i = T2.inference(0.05)

(2) Plot:

pyplot.close('all') T2i.plot() pyplot.show()

However, I get the error "AttributeError: 'SPM0Di_T2' object has no attribute 'plot' ".

Could you help me solving this problem and perform this test?

Best regards, Florent Moissenet.

0todd0000 commented 8 years ago

Dear Florent,

The problem is that the data are 0D and not 1D. The error indicates "SPM0Di_T2"; if the data were 1D it would say "SPM1Di_T2". You can print 0D results using "print T2i" but there is no function for plotting 0D results, and that's why the error is produced.

spm1d.stats.hotellings2 and all other multivariate procedures in spm1d interpret the data as follows:

Q needn't represent time but must represent some 1D domain.

Note that it is usually quite difficult to store 1D multivariate data in a CSV file. One option for organizing CSV data into the required format is to save different vector components in different CSV files, then stack them as follows:

YAx = pd.read_csv(args[1]).as_matrix().T  #(J x Q)
YAy = pd.read_csv(args[2]).as_matrix().T  #(J x Q)
YAz = pd.read_csv(args[3]).as_matrix().T  #(J x Q)
YA = np.dstack([YAx, YAy, YAz])  #(J x Q x 3)

Cheers, Todd

fmoissenet commented 8 years ago

Dear Todd,

Everything is clear now! I did not check my csv files and for sure I have a problem with my JxQxI arrays. Thank you for the option for organising CSV data!

Best regards, Florent.

Le 01/12/2015 20:21, Todd Pataky a écrit :

Dear Florent,

The problem is that the data are 0D and not 1D. The error indicates "SPM0Di_T2"; if the data were 1D it would say "SPM1Di_T2". You can print 0D results using "print T2i" but there is no function for plotting 0D results, and that's why the error is produced.

spm1d.stats.hotellings2 and all other multivariate procedures in spm1d interpret the data as follows:

  • (J x I) array: J observations, I vector components
  • (J x Q x I) array: J observations, Q time nodes, I vector components

Q needn't represent time but must represent some 1D domain.

Note that it is usually quite difficult to store 1D multivariate data in a CSV file. One option for organizing CSV data into the required format is to save different vector components in different CSV files, then stack them as follows:

YAx= pd.read_csv(args[1]).as_matrix().T#(J x Q) YAy= pd.read_csv(args[2]).as_matrix().T#(J x Q) YAz= pd.read_csv(args[3]).as_matrix().T#(J x Q) YA= np.dstack([YAx, YAy, YAz])#(J x Q x 3)

Cheers, Todd

— Reply to this email directly or view it on GitHub https://github.com/0todd0000/spm1d/issues/34#issuecomment-161068648.