Align datasets

Shows how to combine information from two datasets describing the same cases, but not necessarily in the same order.

# Author: Christian Brodbeck <christianbrodbeck@nyu.edu>
import random
import string

from eelbrain import *


# Generate a dataset with known sequence
ds = Dataset()
ds['ascii'] = Factor(string.ascii_lowercase)
# Add an index variable to the dataset to later identify the cases
ds.index()

# Generate two shuffled copies of the dataset (and print them to confirm that
# they are shuffled)
ds1 = ds[random.sample(range(ds.n_cases), 15)]
ds1.head()
# ascii index
0 y 24
1 j 9
2 v 21
3 t 19
4 o 14
5 w 22
6 f 5
7 u 20
8 m 12
9 k 10


# ascii index
0 w 22
1 s 18
2 j 9
3 g 6
4 c 2
5 h 7
6 x 23
7 l 11
8 v 21
9 t 19


Align the datasets

Use the "index" variable added above to identify cases and align the two datasets

ds1_aligned, ds2_aligned = align(ds1, ds2, 'index')

# show the ascii sequences for the two datasets next to each other to
# demonstrate that they are aligned
ds1_aligned['ascii_ds2'] = ds2_aligned['ascii']
ds1_aligned
# ascii index ascii_ds2
0 y 24 y
1 j 9 j
2 v 21 v
3 t 19 t
4 w 22 w
5 f 5 f
6 k 10 k
7 h 7 h


Gallery generated by Sphinx-Gallery