Copied/modified from hackage: A collection of commonly used statistical functions.