def plotRegr(exp):
	
	"""
	Plots data for one experiment.
	
	Arguments:
	exp		--- {"004A", "004B"}
	"""
	src = 'selected_dm_%s_WITH_drift_corr_onlyControl_False.csv' % exp
	dm = CsvReader(src).dataMatrix()
	R = RBridge()

	fig = plt.figure(figsize = (8,3))
	plt.subplots_adjust(left=.2, bottom=.15)
	
	# Plot hline:
	plt.axhline(0, color = "black", linestyle = "--")
	legend = True
	for sacc in [1, 2]:
		colList = [green[1], orange[1], blue[1]]
		
		for contrast in dm.unique("contrast_side"):
	
			
			print "contrast side = ", contrast
			print "sacc = ", sacc
			
			_dm = dm.select("contrast_side == '%s'" % contrast)
			lmeRegr(R, _dm, sacc=sacc, corr=False, \
			color = colList.pop(),stats=False, legend = contrast.strip("_"))
		if legend:		
			plt.legend(frameon = False, loc='best')
			legend = False
	plt.savefig("Timecourse_contrast_per_cond%s.png" % exp)
Exemple #2
0
def plotContrast(exp = "004B", trim=True, inclSim=True,stats=True,norm=False):
	
	
	"""
	Plots landing positions as a function of contrats manipulation per saccade,
	for Exp 1 and Exp 2, relative to CoG.
	
	Keyword arguments:
	trim		--- (default=True)
	"""
	

	# Get dm:
	src = 'selected_dm_%s_WITH_drift_corr_onlyControl_False.csv' % exp
	dm = CsvReader(src).dataMatrix()

	colList = ["#f57900", "#3465a4"]
	lLegend = ["Saccade 1", "Saccade 2"]

	fig = plt.figure(figsize = (3,4))
	plt.subplots_adjust(left=.2, bottom=.15)
	yLim = [-.07, .12]
	

	for sacc in ["1", "2"]:
		dv = "endX%sNorm" % sacc
		saccVar = "saccLat%s" % sacc

		# Get dm:	
		# Only on-object:
		dm = onObject.onObject(dm, sacc,verbose=False)
		
		if trim:
			dm = dm.removeField("__dummyCond__")
			dm = dm.removeField("__stdOutlier__")
			dm = dm.selectByStdDev(keys = ["file"], \
			dv = dv,verbose=False)
			dm = dm.removeField("__dummyCond__")
			dm = dm.removeField("__stdOutlier__")
			dm = dm.selectByStdDev(keys = ["file"], dv = saccVar,\
				verbose=False)

		
		# Collect mean and error bar per saccade:
		lM = []
		lErr = []
		
		if norm:
			# Normalize across handle side:
			dm = dm.removeField("normDV")
			dm= dm.addField("normDV", dtype = float)
			dm= dm.withinize(dv, "normDV", \
					["handle_side"], whiten=False)
			dv = "normDV"

	
		for contrast in dm.unique("contrast_side"):
			contrast_dm = dm.select("contrast_side == '%s'" % contrast,\
				verbose = False)
			
			cm = contrast_dm.collapse(["file"], dv)

			M = cm["mean"].mean()
			SE = cm['mean'].std() / np.sqrt(len(cm))
			CI = SE * critVal
			lM.append(M)
			lErr.append(CI)
		if stats:
			# Run a full LME
			print "Exp = ", exp
			print "DV = ", dv
			print "trim = ", trim
			print "norm = ", norm
			print "saccVar = ", saccVar
			lmeContrast(R, dm, dv, saccVar, exp=exp)
			#raw_input()
				
			xData = range(len(lM))
			yData = lM
			yErr = lErr

		col = colList.pop()
		plt.errorbar(xData, yData, yerr=yErr, fmt='o-', marker = "o", \
			color = col, markerfacecolor='white', markeredgecolor=col, \
			markeredgewidth=1)
	plt.axhline(0, linestyle = "--")
	plt.ylim(yLim)
	plt.ylabel(yTitle)
	#ax.yaxis.set_ticklabels([])
	plt.legend(lLegend, frameon = False)
	plt.axhline(0, color = "black", linestyle = "--")
	plt.xlabel("High-contrast side")
	spacing = 0.5
	xTicks = range(0,3)
	xLabels = ["Left", "Control", "Right"]
	plt.xticks(xTicks, xLabels, rotation = .5)
	plt.xlim(min(xTicks)-spacing, max(xTicks)+spacing)
	plt.savefig(os.path.join(dst,"Contrast_Effect_%s_trim_%s_norm_%s.png") \
		% (exp, trim, norm))
	plt.show()
Exemple #3
0
def plotAff(rtVar, trim=True,errBar = False,stats=True):


	"""
	"""
	
	fig = plt.figure(figsize = (5, 2.5))
	plt.subplots_adjust(left=.2, bottom=.15, wspace=.4)

	nRows = 1
	nCols = 2
	nPlot = 0
	
	lTitles = ["b) Experiment 2", "a) Experiment 1"]	
	
	for exp in ["004A", "004B"]:
		nPlot +=1 

		ax = plt.subplot(nRows, nCols, nPlot)
		plt.title(lTitles.pop())

		# Get dm:
		src = 'selected_dm_%s_WITH_drift_corr_onlyControl_True.csv' % exp
		dm = CsvReader(src).dataMatrix()
	
		# Determine the names of the dependent variables in the datamatrix
		if trim:
			dm = dm.selectByStdDev(["file"], \
				rtVar, verbose=False)
	
		colList = [orange[1], blue[1]]
		
		for hand in dm.unique("response_hand"):
			_dm = dm.select("response_hand == '%s'" % hand)
			
			lM = []		
			lErr = []
			
			for handle in dm.unique("handle_side"):
				__dm = _dm.select("handle_side == '%s'" % handle)
	
				cm = __dm.collapse(["file"], rtVar)
	
				M = cm["mean"].mean()
				SE = cm['mean'].std() / np.sqrt(len(cm))
				lM.append(M)
				lErr.append(SE)
	
			col = colList.pop()
	
			xData = range(len(lM))
			yData = lM

			if errBar:
				plt.errorbar(xData, yData, yerr=lErr, fmt='o-', marker = "o", \
					color = col, markerfacecolor='white', markeredgecolor=col, \
					markeredgewidth=1)
			else:
				plt.plot(yData, marker = "o", \
					color = col, markerfacecolor='white', markeredgecolor=col, \
					markeredgewidth=1)
			if exp == "004A":
				plt.legend(dm.unique("handle_side"), loc = 'best', frameon=False, \
					title="Handle Orientation")
			
			if exp == "004A":
				plt.ylim([700, 750])
			if exp == "004B":
				plt.ylim([600,650])

			plt.xlabel("Response Hand")
			spacing = 0.5
			xTicks = range(0,2)
			xLabels = dm.unique("response_hand")
			plt.xticks(xTicks, xLabels, rotation = .5)
			plt.xlim(min(xTicks)-spacing, max(xTicks)+spacing)
			plt.ylabel("Response time")

		if stats:
			print "Exp = ", exp
			print "rtVar = ", rtVar
			lmeAff(R, dm, rtVar,exp=exp)
		
		raw_input()



	plt.savefig(os.path.join(dst,"Affordances_both_exp.png"))
Exemple #4
0
sacc = "1"	
dvNorm = "endX1CorrNormToHandle"
dvRaw = "endX1CorrNorm"

dm = onObject.onObject(dm, sacc)
	
print "ANOVA"
am = AnovaMatrix(dm, ["handle_side"], dvRaw, "file")._print(ret=True)
print am

print 'One-sample test scipy'
cm = dm.collapse(["file"], dvNorm)
ref = 0

t, p = scipy.stats.ttest_1samp(cm['mean'], ref)				
print "t = ",t
print "p = ", p

# Paired-samples t-test:
print "paired samples t-test"
l = []
for handle in dm.unique("handle_side"):
	handle_dm = dm.select("handle_side == '%s'" % handle)
	cm = handle_dm.collapse(["file"], dvRaw)
	l.append(cm["mean"])
t, p = scipy.stats.ttest_rel(l[0], l[1])

print "t = ",t
print "p = ", p
Exemple #5
0
def plotGap(exp, dv = "saccLat1", trim = False, norm=True, nBins = 50, \
	exclFastSacc = False):
	
	"""
	"""
	
	src = 'selected_dm_%s_WITH_drift_corr_onlyControl_True.csv' % exp
	dm = CsvReader(src).dataMatrix()

	# Determine sacc:
	sacc = [int(x.group()) for x in re.finditer(r'\d+', dv)][0]
	dm = onObject.onObject(dm, sacc)
	
	# Exclude very fast saccades:
	dm = dm.select("%s > 80" % dv)	
	
	colList = [orange[1], blue[1]]

	# Trim the data
	if trim:
		
		dm = dm.removeField("__dummyCond__")
		dm = dm.removeField("__stdOutlier__")

		dm = dm.selectByStdDev(["file"], dv, \
			verbose=False)
		dm = dm.removeField("__dummyCond__")
		dm = dm.removeField("__stdOutlier__")
		dm = dm.selectByStdDev(["file"], "endX%sNormToHandle" % sacc, \
			verbose=False)
		
		if exp == "004A":
			dm = dm.removeField("__dummyCond__")
			dm = dm.removeField("__stdOutlier__")
			dm = dm.selectByStdDev(["file"], "endX%sCorrNormToHandle" % sacc, \
				verbose=False)
				
	else:
		dm = dm.select("%s < 1000" % dv)
	
	# Normalize saccade latencies 
	if norm:
		dm= dm.addField("normSacc", dtype = float)
		dm= dm.withinize(dv, "normSacc", \
				["file"], whiten=False)
		dv = "normSacc"
		
	for gap in dm.unique("gap"):
		
		_dm = dm.select("gap == '%s'" % gap)

		samp = _dm[dv]
	
		y, edges = np.histogram(samp, bins = nBins)
		y = normY(y)
				
		x = .5*edges[1:] + .5*edges[:-1]
		col = colList.pop()
		plt.plot(x, y, color = col)
		plt.fill_between(x, 0, y, alpha=.3, color=col)	
	plt.legend(dm.unique("gap"))
	plt.ylim([0,1.1])