Skip to content

lvanderlinden/exparser

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Exparser

A Python library for the analysis of experimental data.

Copyright 2011-2014 Sebastiaan MathĂ´t

Overview

class DataMatrix

Provides functionality for convenient processing of experimental data.

function DataMatrix.__add__(dm, cautious=False)

Concatenates two DataMatrices. Implements the + operator.

Example:

dm3 = dm1 + dm2

Arguments:

  • dm -- The DataMatrix to be appended.
    • Type: DataMatrix

Keywords:

  • cautious -- DEPRECATED
    • Default: False

Returns:

The concatenation of the current and the passed DataMatrix.

  • Type: DataMatrix

function DataMatrix.__getitem__(key)

Returns a column, index, or slice. Note that some operations return a copy of the DataMatrix, so they cannot be used to modify the contents of the DataMatrix.

Example:

dm['rt'] # returns column 'rt' as numpy array
dm[0] # returns first row as DataMatrix
dm[0:2] # returns first two rows as DataMatrix
dm[0]['rt'] = 1 # This doesn't alter the original DataMatrix
dm['rt'][0] = 1 # This does!

Arguments:

  • key -- A column name or index.
    • Type: int, str, unicode

Returns:

A DataMatrix or NumPy array corresponding to a slice or column from this DataMatrix.

  • Type: DataMatrix, ndarray

function DataMatrix.__init__(a, structured=False)

Creates a new DataMatrix object.

Arguments:

  • a -- A NumPy array, list, or filename. For unstructured NumPy arrays or lists, the first row is assumed to contain column names. Filenames are assumed to refer to a .npy file.
    • Type: ndarray, list, str, unicode

Keywords:

  • structured -- Indicates whether a is a structured NumPy array.
    • Default: False
    • Type: bool

function DataMatrix.__iter__()

Implements an iterator for 'for' loops to walk through a DataMatrix row by row.

Example:

for rowDm in dm:
        print rowDm

Returns:

No description

  • Type: DataMatrixIterator

function DataMatrix.__len__()

No description specified.

Returns:

The number of rows.

  • Type: int

function DataMatrix.__setitem__(key, val)

Set a certain variable. Implements assigment.

Example:

dm['rt'] = 100

Arguments:

  • key -- The name of a key.
    • Type: str, unicode
  • val -- An array with the new values, or a single new value to use for the entire column.

function DataMatrix.addField(key, default=None, dtype=<type 'numpy.int32'>)

Creates a new DataMatrix that is a copy of the current DataMatrix with an additional field.

Example:

dm = dm.addField('rt', dtype=float, default=-1000)

Source(s):

  • <:>

  • </>

  • </>

  • <.>

  • </>

  • </>

  • <1>

  • <2>

  • <0>

  • <1>

  • <8>

  • <1>

  • <7>

  • </>

  • < >

  • < >

  • < >

  • < >

  • < >

  • < >

  • < >

  • < >

  • < >

  • < >

  • < >

  • < >

  • < >

  • < >

  • < >

  • < >

  • < >

  • < >

  • < >

  • < >

  • < >

  • <->

  • <->

  • <->

  • <->

  • <->

  • <->

  • <->

  • <>> Arguments:

  • key -- The name of the new field.

    • Type: str, unicode

Keywords:

  • default -- The default value or None for no default.
    • Default: None
  • dtype -- The dtype for the new field.
    • Default: <type 'numpy.int32'>

Returns:

No description

  • Type: DataMatrix.

function DataMatrix.asArray()

No description specified.

Returns:

An array representation of the current DataMatrix.

  • Type: ndarray

function DataMatrix.balance(key, maxErr, ref=0, verbose=False)

Filters the data such that a given column is on average close to a reference value, and is symetrically distributed.

Arguments:

  • maxErr -- The maximum mean error relative to the reference value.
    • Type: int, float
  • key -- The key to balance. It must have a numeric dtype.
    • Type: str, unicode

Keywords:

  • ref -- The reference value.
    • Default: 0
    • Type: int, float
  • verbose -- Indicates whether verbose output is printed.
    • Default: False
    • Type: bool

Returns:

A balanced copy of the current DataMatrix.

  • Type: DataMatrix

function DataMatrix.calcPerc(vName, targetVName, keys=None, nBin=None)

Calculates percentile scores for a variable.

Arguments:

  • targetVName -- The variable to store the percentile scores in. This variable must exist, it is not created.
    • Type: str, unicode
  • vName -- The variable to calculate percentile scores for.
    • Type: str, unicode

Keywords:

  • keys -- A key or list of keys to split the data by, before calculating percentile scores, so you can calculate scores individually per subject, condition, etc.
    • Default: None
    • Type: list, str, unicode
  • nBin -- The number of bins or None for continuous scores.
    • Default: None
    • Type: int, NoneType

Returns:

No description

  • Type: DataMatrix

function DataMatrix.collapse(keys, vName)

Collapse the data by a (list of) keys and get statistics on a dependent variable.

Arguments:

  • keys -- A key or list of keys to collapse the data on.
    • Type: list, str, unicode
  • vName -- The dependent variable to collapse. Alternative, you can specifiy a function, in which case the error will be 0.
    • Type: str, unicode, function

Returns:

A DataMatrix with the collapsed data, with the descriptives statistics on vName.

  • Type: DataMatrix

function DataMatrix.columns(dtype=False)

Returns a list of the columns.

Keywords:

  • dtype -- Indicates whether the dtype for each column should be returned as well.
    • Default: False
    • Type: bool

Returns:

If dtype == False: A list of names If dtype == True: A list of (name, dtype) tuples

  • Type: list

function DataMatrix.count(key)

Returns the number of different values for a given variable.

Arguments:

  • key -- The variable to count.
    • Type: str, unicode

Returns:

The number of different values for 'key'.

  • Type: int

function DataMatrix.explode(N)

Break up the DataMatrix in N smaller DataMatrices. For splitting a DataMatrix based on column values, see DataMatrix.split.

Arguments:

  • N -- The number of DataMatrices to explode in.
    • Type: int

Returns:

A list of DataMatrices.

  • Type: list

function DataMatrix.group(keys, _sort=True)

Split the data into different groups based on unique values for the key variables.

Arguments:

  • keys -- A key or list of keys to split the data on.
    • Type: str, unicode, list

Keywords:

  • _sort -- Indicates whether the groups should be sorted by values.
    • Default: True
    • Type: bool

Returns:

A list of DataMatrices.

  • Type: list

function DataMatrix.intertrialer(keys, dv, _range=[1])

Adds columns that contain values from the previous or next trial. These columns are called '[dv]_p1' for the next value, '[dv]_m1' for the previous one, etc.

Arguments:

  • keys -- A key or list of keys that define the trial order.
    • Type: list, str, unicode
  • dv -- The dependent variable.
    • Type: str, unicode

Keywords:

  • _range -- A list of integers that specifies the range for which the operation should be executed.
    • Default: [1]
    • Type: list

Returns:

No description

  • Type: DataMatrix

function DataMatrix.range()

Gives a list of indices to walk through the current DataMatrix.

Returns:

A list of indices.

function DataMatrix.recode(key, coding)

Recodes values (i.e. changes one value into another for a given set of columns).

Arguments:

  • coding -- An (oldValue, newValue) tuple, a list of tuples to handle multiple recodings in one go, or a function that takes a value and returns the recoded value.
    • Type: tuple, list, function
  • key -- The name of the variable to recode, or a list of names to recode multiple variables in one go.
    • Type: str, unicode, list

function DataMatrix.removeField(key)

Return a DataMatrix that is a copy of the current DataMatrix without the specified field.

Arguments:

  • key -- The name of the field to be removed.
    • Type: str, unicode

Returns:

No description

  • Type: DataMatrix

function DataMatrix.removeNan(key)

Remove all rows where the specified key is nan.

Arguments:

  • key -- A key that should not have any nan values.
    • Type: str, unicode

Returns:

No description

  • Type: DataMatrix

function DataMatrix.rename(oldKey, newKey)

Renames a column. This function operates in place, so it modifies the current dataMatrix.

Arguments:

  • newKey -- The new name.
    • Type: str, unicode
  • oldKey -- The old name.
    • Type: str, unicode

Returns:

No description

  • Type: DataMatrix

function DataMatrix.select(query, verbose=True)

Select a subset of the data.

Arguments:

  • query -- A query, e.g. 'rt > 1000'.
    • Type: str, unicode

Keywords:

  • verbose -- Indicates if a summary should be printed.
    • Default: True
    • Type: bool

Returns:

No description

  • Type: DataMatrix

function DataMatrix.selectByStdDev(keys, dv, thr=2.5, verbose=False)

Select only those rows where the value of a given column is within a certain distance from the mean.

Arguments:

  • keys -- A list of keys to create groups for which the deviation is calculated seperately.
    • Type: list
  • dv -- The dependent variable.
    • Type: str, unicode

Keywords:

  • thr -- The stddev threshold.
    • Default: 2.5
    • Type: float, int
  • verbose -- Indicates whether detailed output should be provided.
    • Default: False
    • Type: bool

Returns:

No description

  • Type: DataMatrix

function DataMatrix.selectColumns(keys)

Creates a new DataMatrix with only the specified columns.

Arguments:

  • keys -- A column or list of columns to select.
    • Type: list, str, unicode

Returns:

No description

  • Type: DataMatrix

function DataMatrix.shuffle()

Shuffles the DataMatrix in place.

function DataMatrix.sort(keys, ascending=True)

Sorts the DataMatrix in place.

Arguments:

  • keys -- A key or list of keys to use for sorting. The first key is dominant, the second key is next-to-dominant, etc.
    • Type: str, unicode, list

Keywords:

  • ascending -- Indicates whether the sorting should occur in ascending (True) or descending (False) order.
    • Default: True
    • Type: bool

function DataMatrix.split(key)

Splits the DataMatrix in chunks such that each chunk only has the same value for the specified column. For splitting a DataMatrix into equally sized parts, see DataMatrix.explode.

Arguments:

  • key -- A key to split by.
    • Type: str, unicode

Returns:

A list of DataMatrices.

  • Type: list

function DataMatrix.ttest(keys, dv, paired=True, collapse=None)

Performs t-tests between groups defined by a list of keys.

Arguments:

  • keys -- A list of keys to define the groups.
    • Type: list
  • dv -- The dependent variable.
    • Type: str, unicode

Keywords:

  • paired -- Determines whether a paired-samples t-test or an independent samples t-test should be conducted.
    • Default: True
    • Type: bool
  • collapse -- A key to collapse the data on, so that you can do t-tests on (subject) means.
    • Default: None
    • Type: str, unicode, NoneType

Returns:

A list of (desc, t, p) tuples.

  • Type: list

function DataMatrix.unique(key)

Gives all unique values for a particular key.

Arguments:

  • key -- A column name.
    • Type: str, unicode

Returns:

A list of unique values.

  • Type: list

function DataMatrix.where(query)

Return indices corresponding to the query.

Arguments:

  • query -- A query, e.g. 'rt > 1000'.
    • Type: str, unicode

Returns:

Indices.

  • Type: ndarray

function DataMatrix.withinize(vName, targetVName, key, verbose=True, whiten=False)

Removes the between factor variance for a given key (such as subject or file) for a given dependent variable. This operation acts in place.

Arguments:

  • targetVName -- The target variable to store withinized values. This variable should exist.
    • Type: str, unicode
  • vName -- The dependent variable to withinize.
    • Type: str, unicode
  • key -- The key that defines the group.
    • Type: str, unicode

Keywords:

  • verbose -- Indicates whether the results should be printed.
    • Default: True
    • Type: bool
  • whiten -- Indicates whether the data should be whitened so that the standard deviation is 1 and the mean 0.
    • Default: False
    • Type: bool

Returns:

No description

  • Type: DataMatrix

About

Python module for parsing experimental data

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%