-- Confidence Intervals
-- Data values
values = [41,40,36,26,27,37,45,47] :: [Double]
-- T-table value
t = 2.13145 :: Double
-- Change the input values and *POFF* the answers appear
ci :: IO ()
ci = do let a1 = lower mean t deviation n
let a2 = higher mean t deviation n
putStrLn ""
putStrLn $ "N: " ++ show n
putStrLn $ "Mean: " ++ show mean
putStrLn $ "Var: " ++ show variance
putStrLn $ "S D: " ++ show deviation
putStrLn ""
putStrLn $ "Low: " ++ show a1
putStrLn $ "High: " ++ show a2
-- Useful functions using the data values
n = fromIntegral $ length values :: Double
mean = (sum values) / n
variance = sum $ map (\x->(x-mean)^2 / (n-1)) values
deviation = sqrt(variance)
-- Lower and higher functions
lower :: Double -> Double -> Double -> Double -> Double
lower mean tvalue deviation n = mean - ((tvalue * deviation) / (sqrt(n)))
higher :: Double -> Double -> Double -> Double -> Double
higher mean tvalue deviation n = mean + ((tvalue * deviation) / (sqrt(n)))