def get_r2c_sim(coords): dims = [ 'est', 'sim', 'r2', 'sig2', 'snr', 'ms', 'ns', ] res = xr.DataArray(np.zeros(tuple(len(c) for c in coords)), coords=coords, dims=dims) res = res.stack(c=dims[2:]) for i in range(res.shape[-1]): [r2, sig2, snr, m, n] = res[:, :, i].coords['c'].values.tolist() mu2y = SNR_to_mu2(snr, sig2, m, n) theta = [r2, sig2, mu2y, mu2y, m, n] x, y = rc.pds_n2m_r2c(theta, n_exps, ddof=1) x = x.squeeze()[np.newaxis, np.newaxis] r2c, r2 = rc.r2c_n2m(x, y) res[..., i] = np.array([r2, r2c]).squeeze() res = res.unstack() return res
def r2c_n2m_ci_from_post(trace, n, m, r2c_hat_obs, alpha_targ=0.10, nr2cs=50, nr2c_hat=1000): sig2s = trace[0] mu2ys = trace[1] * m sample_inds = np.random.choice(len(sig2s), size=nr2c_hat, replace=False) n_exps = 1 ress = [] r2s = np.linspace(0, 1, nr2cs) for r2 in r2s: res = [] for i in range(nr2c_hat): i = sample_inds[i] theta = [r2, sig2s[i], mu2ys[i], mu2ys[i], m, n] x, y = rc.pds_n2m_r2c(theta, n_exps, ddof=1) res.append(rc.r2c_n2m(x.squeeze(), y)[0]) ress.append(np.array(res).squeeze()) ress = np.array(ress) tol = alpha_targ alpha_obs = np.mean(ress > r2c_hat_obs, 1) ll_dif = np.abs(alpha_obs - alpha_targ / 2) ll_ind = np.argmin(ll_dif) if ll_dif[ll_ind] < tol: ll = r2s[ll_ind] else: ll = 0 ul_dif = np.abs(alpha_obs - (1 - alpha_targ / 2)) ul_ind = np.argmin(ul_dif) if ul_dif[ul_ind] < tol: ul = r2s[ul_ind] else: ul = 1 return ll, ul, alpha_obs
'H&C_their_deriv', 'Y&D', 'H&T', 'S&L', 'S&S', 'Zyl'], snrs, r2sims, ms, range(n_exps)]) da.attrs = {'n':n, 'm':m, 'mu2x':mu2x, 'sig2':sig2, 'n_exps':n_exps} for k, mu2y in enumerate(mu2ys): r2cs = [] r2s = [] for l, m in enumerate(ms): for j, r2 in enumerate(r2sims): theta = [r2, sig2, mu2y, mu2y, m, n] [x, y] = rc.pds_n2m_r2c(theta, n_exps, ddof=1) res = [] for i in range(y.shape[0]): a_y = y[i] mod = np.zeros((len(x), 2)) mod[:,0] = 1 mod[:, 1] = x.squeeze() beta = np.linalg.lstsq(mod, a_y.mean(0), rcond=-1)[0] y_hat = np.dot(beta[np.newaxis], mod.T).squeeze() r2c, r2 = rc.r2c_n2m(x.T, a_y) r2_pc = rc.r2_SE_corrected(x.squeeze(), a_y) r2_upsilon = rc.upsilon(y_hat, a_y) r2_hsu = rc.cc_norm_split(x.squeeze(), a_y)**2 r2_yd = rc.r2_SB_normed(x.squeeze(), a_y) r2_sl = rc.normalized_spe(y_hat, a_y)