Note
Go to the end to download the full example code
Dataset basics
# Author: Christian Brodbeck <christianbrodbeck@nyu.edu>
from eelbrain import *
import numpy
A dataset can be constructed column by column, by adding one variable after another:
# initialize an empty Dataset:
ds = Dataset()
# numeric values are added as Var object:
ds['y'] = Var(numpy.random.normal(0, 1, 6))
# categorical data as represented in Factors:
ds['a'] = Factor(['a', 'b', 'c'], repeat=2)
# A variable that's equal in all cases can be assigned quickly:
ds[:, 'z'] = 0.
# check the result:
ds
For larger datasets it can be more convenient to print only the first few cases…
ds.head()
… or a summary of variables:
An alternative way of constructing a dataset is case by case (i.e., row by row):
Example
Below is a simple example using data objects (for more, see the Examples):
y = numpy.empty(21)
y[:14] = numpy.random.normal(0, 1, 14)
y[14:] = numpy.random.normal(2, 1, 7)
ds = Dataset({
'a': Factor('abc', 'A', repeat=7),
'y': Var(y, 'Y'),
})
ds
table.frequencies('a', data=ds)
test.ANOVA('y', 'a', data=ds)
test.pairwise('y', 'a', data=ds, corr='Hochberg')
\begin{center}
\begin{tabular}{lll}
\toprule
& b & c \\
\midrule
a & $t_{12} = 0.75^{ \ \ \ }$\\
$p = .466$\\
$p_{c} = .466$ & $t_{12} = -3.09^{* \ \ }$\\
$p = .009$\\
$p_{c} = .028$ \\
b & & $t_{12} = -3.97^{** \ }$\\
$p = .002$\\
$p_{c} = .009$ \\
\bottomrule
\end{tabular}
\end{center}
p = plot.Boxplot('y', 'a', data=ds, title="My Boxplot", ylabel="value", corr='Hochberg')
