In [1]:
import seaborn as sns
import psyutils as pu
%load_ext autoreload
%autoreload 2
%matplotlib inline
sns.set_style("white")
sns.set_style("ticks")
I'll demo some functions here using a dataset I simulated earlier.
In [2]:
# load data:
dat = pu.psydata.load_psy_data()
dat.info()
In [3]:
pu.psydata.binomial_binning(dat, y='correct',
grouping_variables=['contrast', 'sf'])
Out[3]:
Notice that you can't compute binomial confidence intervals if the proportion success is 0 or 1. We can fix this using Laplace's Rule of Succession -- add one success and one failure to each observation (basically a prior that says that both successes and failures are possible).
In [4]:
pu.psydata.binomial_binning(dat, y='correct',
grouping_variables=['contrast', 'sf'],
rule_of_succession=True)
Out[4]:
In [5]:
g = pu.psydata.plot_psy(dat, 'contrast', 'correct',
function='weibull',
hue='sf',
col='subject',
log_x=True,
col_wrap=3,
errors=False,
fixed={'gam': .5, 'lam':.02},
inits={'m': 0.01, 'w': 3})
g.add_legend()
g.set(xlabel='Log Contrast', ylabel='Prop correct')
g.fig.subplots_adjust(wspace=.8, hspace=.8);
Some kind of wonky fits (unrealistic slopes), but hey, that's what you get with a simple ML fit with no pooling / shrinkage / priors.
In [6]:
g = pu.psydata.plot_psy_params(dat, 'contrast', 'correct',
x="sf", y="m",
function='weibull',
hue='subject',
fixed={'gam': .5, 'lam':.02})
g.set(xlabel='Spatial Frequency', ylabel='Contrast threshold');
Reasonable (imposed by simulation) CSF shape recovered.