errorbars moved out of model comparison
@@ -15,7 +15,7 @@ from matplotlib import cm
import networkx as nx
from networkx.algorithms.clique import find_cliques as maximal_cliques
from scipy.spatial.distance import squareform
-from rsatoolbox.util.inference_util import all_tests
+from rsatoolbox.util.inference_util import all_tests, get_errorbars
from rsatoolbox.util.rdm_utils import batch_to_vectors
@@ -326,47 +326,10 @@ def plot_model_comparison(result, sort=False, colors=None,
color=colors, bottom=np.min(perf))
else:
ax.bar(np.arange(evaluations.shape[1]), perf, color=colors)
- if error_bars is True:
- error_bars = 'sem'
if error_bars:
- if error_bars.lower() == 'sem':
- errorbar_low = np.sqrt(np.maximum(model_var, 0))
- errorbar_high = np.sqrt(np.maximum(model_var, 0))
- elif error_bars[0:2].lower() == 'ci':
- if len(error_bars) == 2:
- CI_percent = 95.0
- else:
- CI_percent = float(error_bars[2:])
- prop_cut = (1 - CI_percent / 100) / 2
- if test_type == 'bootstrap':
- framed_evals = np.concatenate(
- (np.tile(np.array((-np.inf, np.inf)).reshape(2, 1),
- (1, n_models)),
- evaluations),
- axis=0)
- errorbar_low = -(np.quantile(framed_evals, prop_cut, axis=0)
- - perf)
- errorbar_high = (np.quantile(framed_evals, 1 - prop_cut,
- axis=0)
- - perf)
- else:
- tdist = scipy.stats.t
- std_eval = np.sqrt(np.maximum(model_var, 0))
- errorbar_low = std_eval \
- * tdist.ppf(prop_cut, dof)
- errorbar_high = std_eval \
- * tdist.ppf(prop_cut, dof)
- else:
- raise Exception('plot_model_comparison: Argument ' +
- 'error_bars is incorrectly defined as '
- + str(error_bars) + '.')
- limits = np.concatenate((errorbar_low, errorbar_high))
- if np.isnan(limits).any() or (abs(limits) == np.inf).any():
- raise Exception(
- 'plot_model_comparison: Too few bootstrap samples for the ' +
- 'requested confidence interval: ' + error_bars + '.')
+ limits = get_errorbars(result, error_bars)
ax.errorbar(np.arange(evaluations.shape[1]), perf,
- yerr=[errorbar_low, errorbar_high], fmt='none', ecolor='k',
+ yerr=limits, fmt='none', ecolor='k',
capsize=0, linewidth=3)
# Test whether model performance exceeds 0 (one sided)
