Statistics for Quantum Error Correction and Quantum Metrology with Non-Markovian Noise