def plot_change_width_scatter(data, fitter, fits): bin_edges = fits.change_distribution_params.bin_edges bin_centers = fits.change_distribution_params.bin_centers shape = fitter.shape def get_width(weights): return change_distribution_width_cumsum(bin_centers, weights) width_pairs = [] for fit in iterate_fits(fits): weights_single = calc_change_distribution(shape, fit.theta, bin_edges) width_single = get_width(weights_single) width_bootstrap = get_width(fit.change_distribution_weights) width_pairs.append( (width_single, width_bootstrap) ) width_single,width_bootstrap = zip(*width_pairs) fig = plt.figure() ax = fig.add_axes([0.12,0.12,0.8,0.8]) maxw = int(math.ceil(max(max(width_single), max(width_bootstrap)))) minw = int(math.floor(min(min(width_single), min(width_bootstrap)))) ax.scatter(width_single, width_bootstrap, alpha=0.8) ax.plot(np.mean(width_single), np.mean(width_bootstrap), 'rx', markersize=8, markeredgewidth=2, label='mean') ax.plot([minw, maxw], [minw, maxw],'k--') ax.set_xlim(minw,maxw) ax.set_ylim(minw,maxw) ticks = range(minw, maxw+1) ax.set_yticks(ticks) ax.set_xticks(ticks) ax.set_xticklabels([str(t) for t in ticks], fontsize=cfg.fontsize) ax.set_yticklabels([str(t) for t in ticks], fontsize=cfg.fontsize) ax.set_xlabel('width of single fit', fontsize=cfg.fontsize) ax.set_ylabel('width by bootstrap', fontsize=cfg.fontsize) ax.set_title('change distribution of single fit vs. bootstrap', fontsize=cfg.fontsize) return fig
def plot_change_width_scatter(data, fitter, fits): bin_edges = fits.change_distribution_params.bin_edges bin_centers = fits.change_distribution_params.bin_centers shape = fitter.shape def get_width(weights): return change_distribution_width_cumsum(bin_centers, weights) width_pairs = [] for fit in iterate_fits(fits): weights_single = calc_change_distribution(shape, fit.theta, bin_edges) width_single = get_width(weights_single) width_bootstrap = get_width(fit.change_distribution_weights) width_pairs.append((width_single, width_bootstrap)) width_single, width_bootstrap = zip(*width_pairs) fig = plt.figure() ax = fig.add_axes([0.12, 0.12, 0.8, 0.8]) maxw = int(math.ceil(max(max(width_single), max(width_bootstrap)))) minw = int(math.floor(min(min(width_single), min(width_bootstrap)))) ax.scatter(width_single, width_bootstrap, alpha=0.8) ax.plot(np.mean(width_single), np.mean(width_bootstrap), 'rx', markersize=8, markeredgewidth=2, label='mean') ax.plot([minw, maxw], [minw, maxw], 'k--') ax.set_xlim(minw, maxw) ax.set_ylim(minw, maxw) ticks = range(minw, maxw + 1) ax.set_yticks(ticks) ax.set_xticks(ticks) ax.set_xticklabels([str(t) for t in ticks], fontsize=cfg.fontsize) ax.set_yticklabels([str(t) for t in ticks], fontsize=cfg.fontsize) ax.set_xlabel('width of single fit', fontsize=cfg.fontsize) ax.set_ylabel('width by bootstrap', fontsize=cfg.fontsize) ax.set_title('change distribution of single fit vs. bootstrap', fontsize=cfg.fontsize) return fig
data = GeneData.load('both').scale_ages(age_scaler) shape = Sigslope('sigslope80') fitter = Fitter(shape, sigma_prior='normal') bin_edges, bin_centers = get_bins(data) GRs = [ ('GLRA2', 'STC', (5, 12)), ('HTR2B', 'MD', (3.5, 6)), ('SLC18A2', 'HIP', (3.5, 5.5)), ] for g, r, yrange in GRs: print 'Doing {}@{}...'.format(g, r) series = data.get_one_series(g, r) theta, sigma, _, _ = fitter.fit(series.ages, series.single_expression) weights = calc_change_distribution(shape, theta, bin_edges) fig = plot_one_series(series, shape, theta, bin_centers, weights, yrange) save_figure(fig, 'RP/fit-examples-{}-{}.png'.format(g, r), under_results=True) # now with bootstrap estimate of change distribution print 'Doing bootstrap...' theta_samples = fitter.parametric_bootstrap(series.ages, theta, sigma) weights = calc_bootstrap_change_distribution(shape, theta_samples, bin_edges) fig = plot_one_series(series, shape, theta, bin_centers, weights, yrange) save_figure(fig, 'RP/fit-examples-{}-{}-bootstrap.png'.format(g, r), under_results=True)
cfg.verbosity = 1 age_scaler = LogScaler() data = GeneData.load('both').scale_ages(age_scaler) shape = Sigslope('sigslope80') fitter = Fitter(shape, sigma_prior='normal') bin_edges, bin_centers = get_bins(data) GRs = [ ('GLRA2','STC', (5, 12)), ('HTR2B','MD', (3.5, 6)), ('SLC18A2','HIP', (3.5, 5.5)), ] for g,r,yrange in GRs: print 'Doing {}@{}...'.format(g,r) series = data.get_one_series(g,r) theta,sigma,_,_ = fitter.fit(series.ages, series.single_expression) weights = calc_change_distribution(shape, theta, bin_edges) fig = plot_one_series(series, shape, theta, bin_centers, weights, yrange) save_figure(fig,'RP/fit-examples-{}-{}.png'.format(g,r), under_results=True) # now with bootstrap estimate of change distribution print 'Doing bootstrap...' theta_samples = fitter.parametric_bootstrap(series.ages, theta, sigma) weights = calc_bootstrap_change_distribution(shape, theta_samples, bin_edges) fig = plot_one_series(series, shape, theta, bin_centers, weights, yrange) save_figure(fig,'RP/fit-examples-{}-{}-bootstrap.png'.format(g,r), under_results=True)