First analyses#
Running the examples below requires the jiku-data package. It can be installed with spm1d using:
pip install "spm1d[data]"
Paired t test: 1D data#
The example below analyzes the plantar arch angle dataset from Caravaggi et al. (2010). The dataset contains arch angle trajectories from ten participants who were measured in each of two conditions: normal and fast. This is a repeated-measures design with two conditions so the appropriate spm1d procedure is: spm1d.stats.ttest_paired .
spm1d procedures are conducted in two steps. First, the main stats function spm1d.stats.ttest_paired calculates the test statistic (here the t-value) at each domain point. Second, the inference method calculates the critical threshold and various probability values associated with the test statistic continuum. The script below conducts both steps and then plots the data and the result.
from matplotlib import pyplot as plt
import spm1d
import jikudata as jd
dataset = jd.PlantarArchAngle() # 1D dataset: 2 conditions, 10 participants
y, A = dataset.y, dataset.x # (20,101) array of responses, and (20,) array of condition labels
y0 = y[ A == 0 ] # (10,101) array: condition 0: normal walking
y1 = y[ A == 1 ] # (10,101) array: condition 1: fast walking (same participants, same order)
t = spm1d.stats.ttest_paired( y1, y0 ) # test statistic for y1 - y0
ti = t.inference( 0.05, dirn=0 ) # two-tailed inference at alpha = 0.05
print( ti )
fig, axs = plt.subplots( 1, 2, figsize=(8, 3.2), tight_layout=True )
spm1d.plot.plot_mean_sd( y0, ax=axs[0], linecolor='k', facecolor='0.7' ) # condition 0: mean and SD
spm1d.plot.plot_mean_sd( y1, ax=axs[0], linecolor='#0e6e84', facecolor='#2eb0ce' ) # condition 1: mean and SD
axs[0].set_title( 'Data' )
ti.plot( ax=axs[1] )
ti.plot_threshold_label( ax=axs[1] )
ti.plot_p_values( ax=axs[1] )
axs[1].set_title( 'Result' )
plt.show()
The test statistic continuum (right panel) falls below the critical threshold (i.e., the lower tail of the two-tailed threshold). The null hypothesis of no difference between conditions is therefore rejected.
Results details#
The print( ti ) command in the script above yields additional results details:
SPM{t} (1D) inference
fn_name : ttest_paired
STAT : T
z : (101,) array
df : (1, 9)
Smoothness estimates:
fwhm : 23.819
lkc : 6.991
resels : (1, 4.19835)
Inference results:
method : rft
isparametric : True
alpha : 0.05
dirn : 0
zc : 3.82866
zmax : 6.552
h0reject : True
p_zmax : 0.002
p_set : 0.040
p_cluster : [0.040]
p_point : None
The meaning of each property is described in the SPMi1D class documentation.
In addition to these main results, cluster-specific details can be retrieved from the clusters list. If there are no clusters then this list is empty.
cluster = ti.clusters[0] # the first (and only) cluster
print( cluster )
Output:
ClusterWithInference
centroid : (98.104, -5.098)
endpoints : (95.377, 100.000)
extent : 4.623
height : -3.829
integral : 8.884
iswrapped : False
max : -6.552
min : -3.829
nnodes : 5
sign : -1
Inference
metric : 0.19410
metric_type : extent_resels
p : 0.04008
The meaning of each cluster property is described in the ClusterWithInference class documentation.
Paired t test: 0D data#
“0D data” are data that are not continuous over a 1D domain. This is the type of data that most statistics textbooks use, and most statistics software packages support. Typical examples of 0D data include participant height and body mass. These properties do vary over a lifetime, but in non-longitudinal studies they are usually regarded as static scalars.
The 0D example below uses the sleep dataset from R. The dataset contains the extra sleep of ten participants measured in two conditions. The example reproduces the result of R’s t.test (t = -4.062 and p = 0.003). Note that the spm1d syntax is identical regardless of data dimensionality. The only difference is that the outputs are 0D and not 1D.
import spm1d
import jikudata as jd
dataset = jd.R_SleepPairedTest() # 0D dataset: two conditions, ten participants
y, A = dataset.y, dataset.x # (20,) arrays: responses and condition labels
y0 = y[ A == 0 ] # (10,) array: condition 0
y1 = y[ A == 1 ] # (10,) array: condition 1, same participants in the same order
t = spm1d.stats.ttest_paired( y0, y1 ) # test statistic for y0 - y1
ti = t.inference( 0.05 ) # two-tailed inference at alpha = 0.05
print( ti )
This script produces the following output:
SPM{t} (0D) inference
fn_name : ttest_paired
STAT : T
z : -4.06213
df : (1, 9)
Inference results:
method : param
isparametric : True
alpha : 0.05
dirn : 0
zc : 2.26216
h0reject : True
p : 0.00283
The meaning of each property is described in the SPMi0D class documentation.
The output for 0D data is simpler than for 1D data because the test statistic z is a scalar. There is no 1D domain. z therefore has no geometric features other than its value (i.e., no smoothness and no clusters). All properties that appear in 0D results can otherwise be interpreted identically to those from the 1D results. The default method param is equivalent ℹ️ to the parametric methods used in most statistics software packages. The critical value zc is identical to the values in standard test statistic tables and to those calculated from common (inverse) cumulative distribution functions.
ℹ️ Equivalence to other packages
While the param method used by default in spm1d is indeed equivalent to the default methods of many other statistics packages, the actual results may vary depending on each package’s default settings. For example: two-tailed vs. one-tailed, whether equal variances are assumed, etc. Under identical settings spm1d is expected to produce identical results to other packages for most tests.
Where to go next#
Gallery: an overview of spm1d functionality
API: descriptions of all spm1d procedures
Support: where to ask questions and how to report bugs