0todd0000 / spm1d

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

Paired t-test: Zero Variance Detected #203

Closed katiemallen closed 2 years ago

katiemallen commented 2 years ago

Hello,

I am using spm1d to run analysis on 1D1D data. I am comparing two different measurement systems (comparing joint angles calculated from IMUs to joint angles calculated with motion capture). I have data from each measurement system for each trial conducted. For example, for one person performing a flexion movement, I have a time-series output of joint angles from the mocap system and a time-series output of joint angles from the IMUs. The two data sets are time-aligned and the same length.

I am trying to run a paired t-test, but I get the error: “Zero variance detected…”

How do I resolve this error?

0todd0000 commented 2 years ago

This error means that all values at one or more time points are identical, and thus that the variance (standard deviation = SD) at those points is zero. Since test statistics like the t-statistic are defined roughly as z = mean / SD, zero SD means that the z value can't be calculated, and thus that the data can't be analyzed at that point.

This error usually occurs when the first and/or last values are all zeros. It can also occur if you set the first value to a presumed known value. For example, if you expect the initial joint angle to be 90 deg and set the initial value for all measurements accordingly, then there would be zero variance at the initial node.

To resolve the problem, find the time node(s) that contain zero variance and remove them. For example:

sd   = y.std(axis=0)
ynew = y[ : , sd > 0 ]

Here y is a (J,Q) array, where J is the number of observations and Q is the number of time nodes.

katiemallen commented 2 years ago

Thank you for your response! My two datasets are YA and YB that I am feeding into the paired t-test. They are both (1x185). Since J=1 here, would I not be able to compare these two using this paired t-test function since I only have one observation from each system?

0todd0000 commented 2 years ago

Yes, that it correct. It is not possible to statistically compare samples that have just one sample each. This is true of all procedures, including SPM. Test statistics like the t-statistic are defined conceptually as t = mean_change / variance, and if there is just one observation, then variance cannot be estimated, so the t-statistic cannot be calculated. Generally five or more observations are needed for procedures like these.

katiemallen commented 2 years ago

That makes sense, and that is the confirmation I needed. Thank you so much for your quick replies and for the great program!

0todd0000 commented 2 years ago

No problem! Please feel free to create a new issue if anything else comes up.