0todd0000 / spm1d

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

TypeError: SPM0D_T.inference() got an unexpected keyword argument 'interp' #254

Closed DrStimGeek closed 7 months ago

DrStimGeek commented 1 year ago

Hi, I am incredibly new to SPM as well as Python. But for some reason, it does not recognize the interp=true. I'm trying to test out the two-sample t-test, aka independent t-test. I have a CSV file with two columns; the first variable is the name. Here is the code I have. Is it me, or is something with the t.inference() not working?

Screenshot 2023-04-04 at 5 00 37 PM

DrStimGeek commented 1 year ago

In addition if i remove the interp= then the error it tells me is plot isn't defined. I see here I don't have the import matplotlib.pyplot as plt but even then it just says 'SPM0Di_T' object has no attribute 'plot'

0todd0000 commented 1 year ago

It sounds like there is an insufficient number of observations. To analyze 1D data the inputs data1 and data2 must both be (J,Q), where J it the number of observations and Q is the number of time nodes.

From your code it appears that J=1, which means that data1 contains just a single 1D observation. You must have multiple observations to conduct statistical analyses. A rule-of-thumb is that J should be at least 5.

DrStimGeek commented 1 year ago

The data I have has two columns so Data1 is 9 data points of fake knee flexion and Data2 would be the set of corresponding control data points. So maybe I’m confused on how the csv data needs to be displayed. Aka an example of the J x Q data set

DrStimGeek commented 1 year ago

I’m use to running everything in spss.

DrStimGeek commented 1 year ago

I think I’ve realized my flaw here, the SPM is for items such as large kinematic data sets. A simple set of data that is a normal independent t.test would not fit for this. Tomorrow I’ll run a set of old knee flexion in stance kinematic data and see if that’s the problem at hand. Still interested to see how it’s best to format data to then read in to python.

0todd0000 commented 1 year ago

One point of confusion might be the fact that spm1d handles both "0D" and "1D" data. 0D data are simple scalars that do not change in time, like the data you have likely worked with in SPSS; each observation contains just one value. "1D" data are single variables (like joint flexion angle) that vary over some one-dimensional domain like time; a single 1D observation contains Q values, where Q is usually 100 or 101 for biomechanics data. In both the 0D and 1D case, several observations are required for statistical analysis.

To get a better feel for the data arrays that you need to submit for 0D vs 1D analysis, try the example scripts here:

For the 0D case check the input variables using for example:

# check 0D variables:

print( yA.shape )
print( yB.shape )
print()
print( yA )
print()
print( yB )

For the 1D variables try checking the data like this:

# check 1D variables:

print( YA.shape )
print( YB.shape )

import matplotlib.pyplot as plt
plt.plot( YA.T, color='k' )
plt.plot( YB.T, color='r' )
DrStimGeek commented 1 year ago

Ah so I can use 0D data. So how would one get two columns of data that are 10 cells long into python for spm1d to read and run a ttest2? Printing the data set you have above puts it into what seems like a set up or rows? So my biggest confusion is how to structure the data within CSV so it gets red in correctly so I don't have to define each variable one by one in python itself.

0todd0000 commented 1 year ago

If you have a two-column CSV file, one option is to read it using NumPy:

import numpy as np
fpath = '/full/path/to/your/file.csv'
a     = np.loadtxt( fpath, delimiter=',', skiprows=0)  # all data as a 2D array
x0    = a[:,0]  # first column
x1    = a[:,1]  # second column

If there is one header line (e.g. with column labels) then change to skiprows=1 .