New users: JupyterLab#
JupyterLab Desktop is the easiest way to get started with spm1d in an app that you can install on your PC. It is free to download, install and use, and no registration required.
Step 1: Install JupyterLab Desktop#
Download an installer from the JupyterLab Desktop download page.
Run the installer and follow its instructions.
Open JupyterLab Desktop.
If JupyterLab Desktop cannot find Python
If JupyterLab Desktop cannot find Python the first time it starts, you can install Python as follows:
Click the menu button at the top right of the JupyterLab Desktop window and choose Manage Python environments.
Open the Create new tab and choose the option that creates a copy of the bundled environment.
Enter a name for the environment (e.g.,
my_spm1d_env) and click Create.
Step 2: Install spm1d#
Create a new notebook from the JupyterLab Desktop start screen. After the notebook appears enter the following command into the first cell, and run the cell by pressing SHIFT+ENTER.
pip install spm1d
The spm1d installation usually takes only a few seconds. 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.
In JupyterLab Desktop you need to install spm1d only once; spm1d will stay in JupyterLab’s environment even if you quit and relaunch the app. You can delete spm1d from JupyterLab Desktop’s environment any time using:
pip uninstall -y spm1d
You can upgrade to the most recent version of spm1d using:
pip install --upgrade spm1d
You can install a specific version using:
pip install spm1d==0.5.0
Step 3: 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.
Jupyter looks for files in the folder that contains the notebook. To run this example, download the two CSV files and copy them into the same folder as your notebook. If you are not sure where the current notebook is saved, run the following commands, which will print the full path to the notebook’s parent folder.
import os
print( os.getcwd() )
The file browser on the left side of JupyterLab (View > File Browser) shows the contents of the active notebook’s folder, so check there to ensure that you can see the two CSV files. You can also drag the files from your computer into the file browser to copy them into this folder.
The first cell loads the two CSV files using numpy.
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 result. The ttest2 function calculates the t-value at every point in the domain, and 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.