0todd0000 / spm1d

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

multiple regression analysis #214

Closed Xlcandy closed 2 years ago

Xlcandy commented 2 years ago

Hi, there

I am trying to examine the correlation between the peroneal longus, tibialis anterior, soleus muscles (3 independent variables) and the COP mediolateral displacement (1 dependent variable) during gait. After watching SPM Workshop, I feel that Canonical correlation analysis seems possible, but I found in spm1d.org about CCA, said that "spm1d currently does not support multivariate regressors." I would like to know when multiple regression analyses will be available using spm1d. And if you think there are any other better ways to analyze, I would be very appreciative of your advice.

Thanks!

0todd0000 commented 2 years ago

I would like to know when multiple regression analyses will be available using spm1d.

I would like to say soon, but it may be one year or more.

And if you think there are any other better ways to analyze, I would be very appreciative of your advice.

It depends whether the dependent variable (COP mediolateral displacement) is a scalar or not. If it is a scalar, then you can use CCA, simply by swapping the independent and dependent variables. If it is not a scalar, then spm1d currently does not support that type of analysis.

Xlcandy commented 2 years ago

Hi, The dependent variable is a scalar, but I don’t know exactly how to do the CCA analysis using Python.... I have tried to convert all the dependent and independent variables into npy files separately and then merged them into one npz file. But I'm not sure where I should put this npz file and if I should change the code in which script to complete the analysis....

Thanks all the time.

0todd0000 commented 2 years ago

This script for 0D data and this script for 1D data demonstrate how the data should be organized.

The basic function call is:

x2 = spm1d.stats.cca(y, x)

Here:

Xlcandy commented 2 years ago

Thank you so much!!

Xlcandy commented 2 years ago
  • The x variable should be a J-element 1D array, or equivalently an array with size(J,).
  • For 0D data the y variable must be a (J,I)2D array.
  • For 1D data the y variable must be a (J,Q,I)3D array.

Hi!

I would like to ask how to create a (J)-element 1D array using EXCEL. image image

Both of these two are 2D array...

Thank you!!

0todd0000 commented 2 years ago

If a 2D array has just one column or one row (i.e., with shape (J,1) or (1,J)) you can convert it to a 1D array using the flatten method:

import numpy as np

x0 = np.array( [ [1, 3, 5] ] )
x1 = np.array( [ [1], [3], [5] ] )

print( x0.shape )
print( x1.shape )

x0 = x0.flatten()
x1 = x1.flatten()

print( x0.shape )
print( x1.shape )

Output:

(1, 3)
(3, 1)
(3,)
(3,)
Xlcandy commented 2 years ago

Thank you Todd!!

0todd0000 commented 2 years ago

I received an email regarding a plot command error but do not see the question here... please repost if the issue has not yet been resolved.