New users: Google Colab#
Google Colab runs in the cloud and is the easiest way to get started using spm1d. With a single command you can install spm1d in Google Colab, and with a few more you can run a statistical test.
Step 1: Install spm1d#
Google Colab is a free ℹ️ web service that runs Python notebooks in your browser. Colab includes Python and most spm1d requirements, and installing spm1d requires just a single command as shown in the screencast below.
ℹ️ A Google account is required.
As shown above:
Open your web browser and go to
colab.research.google.com.Click “New notebook” to create an empty notebook.
Type or copy the following command into the first cell, then click the run button to execute the cell.
pip install spm1d
Installation usually takes only a few seconds. When it is finished, the last line of the output reports that spm1d was successfully installed. You can then check the installation by running the following commands in a new cell.
import spm1d
print( spm1d.__version__ )
If these commands print a version number without any errors, then spm1d is ready to use.
Each Colab session starts with a fresh Python environment, so you will need to re-install spm1d each time you start a new session. Refer to JupyterLab if you prefer to use a desktop app where installation is required just once.
Step 2: Analysis#
Here are two CSV files that are used in the screencast below:
Each file contains (J,Q) data, where J and Q are the numbers of observations (rows), and domain points (columns), respectively. In this example each file has (J,Q) = (6, 101) data.
Colab runs in the cloud, so you must upload files to Colab to analyze them:
In Colab, click the folder icon on the left side of the notebook to open the Files panel.
Click the upload icon at the top of the Files panel and select the two CSV files. You can also drag the files from your computer into the Files panel.
After upload, the two files appear in the Files panel. Like the installation, uploaded files are deleted when the Colab session ends, so you will need to upload them again in each new session. You can upload your own CSV files in the same way.
The code in the animation below is:
import numpy as np
y0 = np.loadtxt('group0.csv', delimiter=',')
y1 = np.loadtxt('group1.csv', delimiter=',')
print( y0.shape, y1.shape )
The animation below shows how the data can be analyzed. The first notebook cell repeats the data reading step:
import numpy as np
import spm1d
y0 = np.loadtxt('group0.csv', delimiter=',')
y1 = np.loadtxt('group1.csv', delimiter=',')
The second cell plots the mean and standard deviation of each group.
spm1d.plot.plot_mean_sd(y0)
spm1d.plot.plot_mean_sd(y1, linecolor='r', facecolor='r')
The third cell conducts a two-sample t test and plots the results. The ttest2 function calculates the test statistic (t-value) at every point in the domain. The inference method calculates probability values, including the critical threshold for a significance level of α = 0.05.
spm = spm1d.stats.ttest2(y1, y0)
spmi = spm.inference(0.05)
spmi.plot()
In the resulting figure the dashed horizontal lines show the critical threshold. The t-value continuum (the thick curved line) exceeds the threshold, which indicates a statistically significant difference between the two groups’ means.
Next steps#
The first analyses page explains spm1d results in more detail.
The gallery provides an overview of spm1d’s functionality.