def z_link_func(x, data=data):
stim = (np.asarray(dmatrix('0 + C(s, [[0], [1]])',
{'s': data.stim.loc[x.index]},return_type='dataframe'))
)
# Apply z = (1 - x) to flip them along 0.5
z_flip = np.subtract(stim, x.to_frame())
# The above inverts those values we do not want to flip,
# so invert them back
z_flip[stim == 0] *= -1
return z_flip
z_reg = {'model': 'z ~ 1 + C(AreaSize)', 'link_func': z_link_func}
v_reg = {'model': 'v ~ 1 + C(AreaSize)', 'link_func': lambda x: x}
reg_descr = [z_reg, v_reg]
Model:
m_reg = hddm.HDDMRegressor(data, reg_descr, include='z',
keep_regressor_trace=True,
p_outlier=0.05)
m_reg.sample(10000, burn=1000)