diff --git a/.gitignore b/.gitignore index 549d241..53b2b64 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ dist/ dist-newstyle/ *.pdf *.ps +*~ diff --git a/statistics.racket/shell.nix b/statistics.racket/shell.nix new file mode 100644 index 0000000..c73c880 --- /dev/null +++ b/statistics.racket/shell.nix @@ -0,0 +1,4 @@ +{ pkgs ? import {} }: +pkgs.mkShell { + packages = [ pkgs.racket ]; +} diff --git a/statistics.racket/statistics.rkt b/statistics.racket/statistics.rkt new file mode 100644 index 0000000..e033179 --- /dev/null +++ b/statistics.racket/statistics.rkt @@ -0,0 +1,15 @@ +#lang typed/racket + +(: sum (-> (Listof Number) Number)) +(define (sum list) (foldr + 0 list)) + +(: mean (-> (Listof Number) Number)) +(define (mean sample) + (/ (sum sample) (length sample))) + +(: standard-deviation (-> (Listof Number) Number)) +(define (standard-deviation sample) + (let* ((degrees-of-freedom (- (length sample) 1)) + (sample-mean (mean sample)) + (sum-of-squared-errors (sum (map (lambda (xi) (expt (- xi sample-mean) 2)) sample)))) + (sqrt (/ sum-of-squared-errors degrees-of-freedom)))) \ No newline at end of file