- | Covariance of sample of pairs. For empty sample it's set to
--   zero
covariance :: (G.Vector v (Double,Double), G.Vector v Double)
           => v (Double,Double)
           -> Double
covariance xy
  | n == 0    = 0
  | otherwise = mean $ G.zipWith (*)
                         (G.map (\x -> x - muX) xs)
                         (G.map (\y -> y - muY) ys)
  where
    n       = G.length xy
    (xs,ys) = G.unzip xy
    muX     = mean xs
    muY     = mean ys
{
covariance :: (G.Vector v (Double,Double), G.Vector v Double)
           => v (Double,Double)
           -> Double
covariance xy
  | n == 0    = 0
  | otherwise = mean $ G.zipWith (*)
                         (G.map (\x -> x - muX) xs)
                         (G.map (\y -> y - muY) ys)
  where
    n       = G.length xy
    (xs,ys) = G.unzip xy
    muX     = mean xs
    muY     = mean ys

covariance xy
  | n == 0    = 0
  | otherwise = mean $ G.zipWith (*)
                         (G.map (\x -> x - muX) xs)
                         (G.map (\y -> y - muY) ys)
  where
    n       = G.length xy
    (xs,ys) = G.unzip xy
    muX     = mean xs
    muY     = mean ys
