Statistical Analysis of Nearest Neighbor Methods for Anomaly Detection