-
Notifications
You must be signed in to change notification settings - Fork 13
/
doAnalysisV1.py
126 lines (93 loc) · 4.05 KB
/
doAnalysisV1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import ipdb
import os
import pandas as pd
import statsmodels.api as sm
import matplotlib.pyplot as plt
ipdb.set_trace()
dataFilename = "data/All_three_exp_conditions_3.csv"
figFilename = "figures/absSpeedVsSpikesV1.png"
data = pd.read_csv(dataFilename, index_col=0)
print(data.columns.values)
# 'Expt #', 'Cell #', 'Speed', 'Bin(i)', 'Bin(i+1)', 'Bin(i+2)', 'Bin(i+3)',
# 'Bin(i+4)', 'Bin(i+5)', 'Trial Condition', 'Region', 'Layer', 'Cell Type'
trialConditions = data.loc[:, "Trial Condition"].unique()
print(trialConditions)
# ['Vestibular' 'VisVes' 'Visual']
regions = data.loc[:, "Region"].unique()
print(regions)
# ['SUB' nan 'V1' 'SC' 'RSPg' 'RSPd' 'Hip']
# We will make a figure with len(trialConditions)==3 panels
f, axes = plt.subplots(1, len(trialConditions), sharey=True)
### Start first panel
# Extract the subset of the data corresponding to vestibular-only stimulation
# and recordings from V1
dataSubset = data.loc[(data["Trial Condition"]=="Vestibular") & (data["Region"]=="V1"),:]
# Plot the spikes counts in Bin(i) as a function of the absolute value of
# the stimulation speed
axes[0].scatter(x=abs(dataSubset["Speed"]), y=dataSubset["Bin(i)"], c="lightgray")
axes[0].set_title("Vestibular")
# Estimate the regression line
regressors = sm.add_constant(abs(dataSubset["Speed"]))
# fit.params contains the regression coefficients
# fit.pvalues contains the regression coefficients pvalues
fit = sm.OLS(endog=dataSubset["Bin(i)"], exog=regressors).fit()
# Plot the regression line
legend = "p={:.4f}".format(fit.pvalues[1])
axes[0].plot(abs(dataSubset["Speed"]), fit.params[0]+abs(dataSubset["Speed"])*fit.params[1], color="red", label=legend)
axes[0].legend(loc="upper left")
axes[0].set_title("Vestibular")
axes[0].set_xlabel("Abs(Speed)")
axes[0].set_ylabel("Spike Count")
### End first panel
### Start second panel
# Extract the subset of the data corresponding to vestibular-only stimulation
# and recordings from V1
dataSubset = data.loc[(data["Trial Condition"]=="VisVes") & (data["Region"]=="V1"),:]
# Plot the spikes counts in Bin(i) as a function of the absolute value of
# the stimulation speed
axes[1].scatter(abs(dataSubset["Speed"]), dataSubset["Bin(i)"], c="lightgray")
axes[1].set_title("VisVes")
# Estimate the regression line
regressors = sm.add_constant(abs(dataSubset["Speed"]))
# fit.params contains the regression coefficients
# fit.pvalues contains the regression coefficients pvalues
fit = sm.OLS(dataSubset["Bin(i)"], regressors).fit()
# Plot the regression line
legend = "p={:.4f}".format(fit.pvalues[1])
axes[1].plot(abs(dataSubset["Speed"]), fit.params[0]+abs(dataSubset["Speed"])*fit.params[1], color="red", label=legend)
axes[1].legend(loc="upper left")
axes[1].set_title("VisVes")
axes[1].set_xlabel("Abs(Speed)")
axes[1].set_ylabel("Spike Count")
### End second panel
### Start third panel
# Extract the subset of the data corresponding to vestibular-only stimulation
# and recordings from V1
dataSubset = data.loc[(data["Trial Condition"]=="Visual") & (data["Region"]=="V1"),:]
# Plot the spikes counts in Bin(i) as a function of the absolute value of
# the stimulation speed
axes[2].scatter(abs(dataSubset["Speed"]), dataSubset["Bin(i)"], c="lightgray")
axes[2].set_title("Visual")
# Estimate the regression line
regressors = sm.add_constant(abs(dataSubset["Speed"]))
# fit.params contains the regression coefficients
# fit.pvalues contains the regression coefficients pvalues
fit = sm.OLS(dataSubset["Bin(i)"], regressors).fit()
# Plot the regression line
legend = "p={:.4f}".format(fit.pvalues[1])
axes[2].plot(abs(dataSubset["Speed"]), fit.params[0]+abs(dataSubset["Speed"])*fit.params[1], color="red", label=legend)
axes[2].legend(loc="upper left")
axes[2].set_title("Visual")
axes[2].set_xlabel("Abs(Speed)")
axes[2].set_ylabel("Spike Count")
### End third panel
plt.savefig(figFilename)
f.show()
ipdb.set_trace()
# 1. Modify script to only print the ylabel in the left panel and the xlabel in the center panel
# 2. Build and call a function to avoid code repetition
# 3. Eight panels
# . Exceptions
# . Git commits
# . Push to github
# . CIs