calculate statistics with a moving window