Calculate variance of discrete random variable (#844)