Skip to content

Commit

Permalink
add confidence interval calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
bvenn committed Jun 10, 2020
1 parent bca8f92 commit b2017c0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/FSharp.Stats/ConfidenceInterval.fs
@@ -0,0 +1,19 @@
namespace FSharp.Stats

module ConfidenceInterval =

open FSharp.Stats.Distributions

// The deviation from the sample mean is calculated by using a t distribution. Common ciLevel = 0.95
let ciDeviation ciLevel (sample : seq<float>)=
let n = float (Seq.length sample)
let stDev = Seq.stDev sample
let t = Continuous.getCriticalTValue (float n - 1.) (1. - ciLevel) Continuous.TwoTailed
let delta = t * stDev / sqrt (float n)
delta

// The confidence interval is calculated by using a t distribution. Common ciLevel = 0.95
let ci ciLevel (sample : seq<float>)=
let mean = Seq.mean sample
let delta = ciDeviation ciLevel sample
Intervals.create (mean - delta) (mean + delta)
3 changes: 2 additions & 1 deletion src/FSharp.Stats/FSharp.Stats.fsproj
Expand Up @@ -104,8 +104,8 @@
<Compile Include="Testing\SAM.fs" />
<Compile Include="Testing\FisherHotelling.fs" />
<Compile Include="Testing\RMT.fs" />
<Compile Include="Fitting\CrossValidation.fs" />
<!-- Fitting -->
<Compile Include="Fitting\CrossValidation.fs" />
<Compile Include="Fitting\LinearRegression.fs" />
<Compile Include="Fitting\NonLinearRegression.fs" />
<Compile Include="Fitting\GoodnessOfFit.fs" />
Expand All @@ -125,6 +125,7 @@
<Compile Include="ML\Unsupervised\GapStatistics.fs" />
<!-- MISC -->
<Compile Include="FSIPrinters.fs" />
<Compile Include="ConfidenceInterval.fs" />
<None Include="paket.references" />
<None Include="paket.template" />
</ItemGroup>
Expand Down

0 comments on commit b2017c0

Please sign in to comment.