  We present an automated algorithm for unified rejection and repair of bad
trials in magnetoencephalography (MEG) and electroencephalography (EEG)
signals. Our method capitalizes on cross-validation in conjunction with a
robust evaluation metric to estimate the optimal peak-to-peak threshold -- a
quantity commonly used for identifying bad trials in M/EEG. This approach is
then extended to a more sophisticated algorithm which estimates this threshold
for each sensor yielding trial-wise bad sensors. Depending on the number of bad
sensors, the trial is then repaired by interpolation or by excluding it from
subsequent analysis. All steps of the algorithm are fully automated thus
lending itself to the name Autoreject.
  In order to assess the practical significance of the algorithm, we conducted
extensive validation and comparison with state-of-the-art methods on four
public datasets containing MEG and EEG recordings from more than 200 subjects.
Comparison include purely qualitative efforts as well as quantitatively
benchmarking against human supervised and semi-automated preprocessing
pipelines. The algorithm allowed us to automate the preprocessing of MEG data
from the Human Connectome Project (HCP) going up to the computation of the
evoked responses. The automated nature of our method minimizes the burden of
human inspection, hence supporting scalability and reliability demanded by data
analysis in modern neuroscience.
