Permalink
Browse files

standardDeviation

  • Loading branch information...
1 parent e9ed42a commit dde7293018e5096eb8fe6df6d1256667656e63bd @thomaschrstnsn committed Jun 28, 2011
Showing with 11 additions and 3 deletions.
  1. +7 −1 src/Data/List/Statistics.hs
  2. +4 −2 src/Daytum/Stats.hs
@@ -1,6 +1,6 @@
module Data.List.Statistics
(
- mean, median
+ mean, median, standardDeviation
)
where
@@ -22,3 +22,9 @@ median xs = if even len
twoMiddle = take 2 $ drop (halfLen - 1) xs'
avgMiddle = mean twoMiddle
+
+standardDeviation :: Floating a => [a] -> a
+standardDeviation xs = sqrt $ mean squareDiffs
+ where
+ meanValue = mean xs
+ squareDiffs = map (\x -> x*x) $ map (meanValue -) xs
View
@@ -28,15 +28,17 @@ data NumStats a =
{ order :: OrderedStats a,
mean :: a,
median :: a,
+ stdDev :: a,
range :: a
} deriving Show
-numStats :: (Fractional a, Ord a) => [a] -> NumStats a
-numStats xs = NumStats { order = oStats, mean = mean, median = median, range = range }
+numStats :: (Floating a, Ord a) => [a] -> NumStats a
+numStats xs = NumStats { order = oStats, mean = mean, median = median, stdDev = stdDev, range = range }
where
oStats = orderedStats xs
mean = DLS.mean xs
median = DLS.median xs
+ stdDev = DLS.standardDeviation xs
range = maximum oStats - minimum oStats
amountStats :: [DaytumRecord] -> NumStats Double

0 comments on commit dde7293

Please sign in to comment.