C#程式設計中常用統計學公式
Being able to apply statistics is like having a secret superpower.
Where most people see averages, you see confidence intervals.
When someone says “7 is greater than 5,” you declare that they're really the same.
In a cacophony of noise, you hear a cry for help.
Unfortunately, not enough programmers have this superpower. That's a shame, because the application of statistics can almost always enhance the display and interpretation of data.
As my modest contribution to developer-kind, I've collected together the statistical formulas that I find to be most useful; this page presents them all in one place, a sort of statistical cheat-sheet for the practicing programmer.
Most of these formulas can be found in Wikipedia, but others are buried in journal articles or in professors' web pages. They are all classical (not Bayesian), and to motivate them I have added concise commentary. I've also added links and references, so that even if you're unfamiliar with the underlying concepts, you can go out and learn more. Wearing a red cape is optional.
Send suggestions and corrections to [email protected]
Table of Contents
1. Formulas For Reporting Averages
One of the first programming lessons in any language is to compute an average. But rarely does anyone stop to ask: what does the average actually tell us about the underlying data?
1.1 Corrected Standard Deviation
The standard deviation is a single number that reflects how spread out the data actually is. It should be reported alongside the average (unless the user will be confused).
Where:
N is the number of observationsxi is the value of thei th observationx¯ is the average value ofxi
1.2 Standard Error of the Mean
From a statistical point of view, the "average" is really just an estimate of an underlying population mean. That estimate has uncertainty that is summarized by the standard error.
1.3 Confidence Interval Around the Mean
A confidence interval reflects the set of statistical hypotheses that won't be rejected at a given significance level. So the confidence interval around the mean reflects all possible values of the mean that can't be rejected by the data. It is a multiple of the standard error added to and subtracted from the mean.
Where:
α is the significance level, typically 5% (one minus the confidence level)tα/2 is the1−α/2 quantile of a t-distribution withN−1 degrees of freedom
1.4 Two-Sample T-Test
A two-sample t-test can tell whether two groups of observations differ in their mean.
The test statistic is given by:
The hypothesis of equal means is rejected if
2. Formulas For Reporting Proportions
It's common to report the relative proportions of binary outcomes or categorical data, but in general these are meaningless without confidence intervals and tests of independence.
2.1 Confidence Interval of a Bernoulli Parameter
A Bernoulli parameter is the proportion underlying a binary-outcome event (for example, the percent of the time a coin comes up heads). The confidence interval is given by: