  Bayesian model selection provides the cosmologist with an exacting tool to
distinguish between competing models based purely on the data, via the Bayesian
evidence. Previous methods to calculate this quantity either lacked general
applicability or were computationally demanding. However, nested sampling
(Skilling 2004), which was recently applied successfully to cosmology by
Muhkerjee et al. 2006, overcomes both of these impediments. Their
implementation restricts the parameter space sampled, and thus improves the
efficiency, using a decreasing ellipsoidal bound in the n-dimensional parameter
space centred on the maximum likelihood point. However, if the likelihood
function contains any multi-modality, then the ellipse is prevented from
constraining the sampling region efficiently. In this paper we introduce a
method of clustered ellipsoidal nested sampling which can form multiple
ellipses around each individual peak in the likelihood.
  In addition we have implemented a method for determining the expectation and
variance of the final evidence value without the need to use sampling error
from repetitions of the algorithm ; this further reduces the computational load
by at least an order of magnitude. We have applied our algorithm to a pair of
toy models and one cosmological example where we demonstrate that the number of
likelihood evaluations required is ~ 4% of that necessary for using previous
algorithms.
  We have produced a fortran library containing our routines which can be
called from any sampling code, in addition for convenience we have incorporated
it into the popular CosmoMC code as CosmoClust. Both are available for download
at http://www.mrao.cam.ac.uk/software/cosmoclust .
