Created
September 7, 2022 13:33
-
-
Save runarorama/87c5392afe28a5203b62cc773936132a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CombineEstimates[es_] := Module[{result, ds, var, tvals, newe, t}, | |
(*Gets the standard deviation for a confidence interval `e`.*) | |
Deviation[e_, | |
confidence_] := (Max[e] - | |
Min[e])/(InverseCDF[NormalDistribution[], confidence]*2); | |
(*Gets the confidence for an interval given its standard | |
deviation.*) | |
Confidence[e_, dev_] := | |
CDF[NormalDistribution[], ((Max[e] - Min[e])/dev)/2]; | |
ds = Map[Deviation @@ # &, es]; | |
(*Find the minimum variation `var` and | |
the t-values that yield it.*) | |
{var, tvals} = | |
Minimize[{Plus @@ Table[t[i]^2*ds[[i]]^2, {i, 1, Length[ds]}], | |
Plus @@ Table[t[i], {i, 1, Length[ds]}] == 1}, | |
Table[t[i], {i, 1, Length[ds]}]]; | |
(*The combined estimate*) | |
newe = | |
Fold[#1 + #2[[1]]*#2[[2]] &, 0, | |
Transpose[{es[[All, 1]], Values[tvals]}]]; | |
result = {newe, Confidence[newe, Sqrt[var]]} | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment