def linregress_bst(bst, tuningcurve):
"""perform linear regression on all the events in bst, and return the slopes, intercepts, and R^2 values"""
posterior, bdries, mode_pth, mean_pth = decode(bst=bst, ratemap=tuningcurve)
slopes = np.zeros(bst.n_epochs)
intercepts = np.zeros(bst.n_epochs)
r2values = np.zeros(bst.n_epochs)
for idx in range(bst.n_epochs):
y = mode_pth[bdries[idx]:bdries[idx+1]]
x = np.arange(bdries[idx],bdries[idx+1], step=1)
x = x[~np.isnan(y)]
y = y[~np.isnan(y)]
if len(y) > 0:
slope, intercept, rvalue, pvalue, stderr = stats.linregress(x, y)
slopes[idx] = slope
intercepts[idx] = intercept
r2values[idx] = rvalue**2
else:
slopes[idx] = np.nan
intercepts[idx] = np.nan
r2values[idx] = np.nan #
# if bst.n_epochs == 1:
# return np.asscalar(slopes), np.asscalar(intercepts), np.asscalar(r2values)
return slopes, intercepts, r2values
评论列表
文章目录