Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- #-*- coding:utf-8 -*-
- import numpy as np
- from matplotlib import pyplot as plt
- import sys
- from exparser.DataMatrix import DataMatrix
- from exparser.PivotMatrix import PivotMatrix
- from exparser.AnovaMatrix import AnovaMatrix
- dv = 'sacc_lat' # Dependent variable
- nBin = 10 # Number of bins
- binKeys = ['FILE', 'cond'] # Bin by subject and condition
- # Load the data, add a field for the bin, and calculate the bins
- a = np.loadtxt('data.csv', delimiter=',', dtype=str)
- dm = DataMatrix(a)
- dm = dm.addField('bin', dtype=float)
- dm = dm.calcPerc(dv, 'bin', keys=binKeys, nBin=nBin)
- lY = []
- lX = []
- # Walk through all bins
- for _bin in dm.unique('bin'):
- # Filter out all but one bin
- _dm = dm.select('bin == %f' % _bin)
- # Get the mean for both conditions. Note that using this method, the mean
- # is across all subjects, and not the mean of the mean of the subjects.
- # But this will not make any real difference for the overall pattern. You
- # can prevent this by withinizing the data first.
- m1 = _dm.select('cond == "act"', verbose=False)[dv].mean()
- m2 = _dm.select('cond == "mir"', verbose=False)[dv].mean()
- y = m2 - m1 # We are going to plot the difference score on the Y-axis
- # The bin average will be on the X-axis, so you can see how the bins are
- # distributed (i.e. the the bins in the middle are closer together than
- # the bins in the end, at least usually)
- x = _dm[dv].mean()
- lY.append(y)
- lX.append(x)
- plt.plot(lX, lY, '.-')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement