Maths.Sampling
Confidence intervals for quantities estimated from a single sample. The bounds agree with those of the equivalent commands in R, i.e.
t.test and binom.test.Methods
EntropyInterval
#Compute an approximate confidence interval for the Shannon entropy, in bits, of the distribution behind the provided values.
Remarks: Unlike the other intervals here these bounds are approximate, and they have no counterpart in R. Three things are worth knowing before trusting them. Values are binned by exact equality, so this is the entropy of the discrete distribution of repeated values, not the differential entropy of a continuous one. The estimate carries the Miller-Madow correction for the downward bias of the plug-in estimator, which is itself only a first order correction. And the bounds come from the delta method, so they are asymptotic: they mean little unless every distinct value has been observed a good number of times.
Parameters:
| values (IEnumerable<double>) | Sample values. Invalid numbers are ignored. |
| confidenceLevel (double) | Desired likelihood of the interval containing the true entropy. Must be larger than zero and smaller than one. |
Returns: The confidence interval, in bits.
Exceptions:
| ArgumentException | If fewer than two valid values were provided, or all distinct values occur equally often. |
MeanInterval
#Compute a Student-t confidence interval for the true mean of the process which generated the provided values.
Parameters:
| values (IEnumerable<double>) | Sample values. Invalid numbers are ignored, they neither affect the mean nor contribute to the degrees of freedom. This mirrors the default behaviour of R's t.test. |
| confidenceLevel (double) | Desired likelihood of the interval containing the true mean. Must be larger than zero and smaller than one. |
Returns: The confidence interval, which is centred on the sample mean. If all values are identical the interval collapses onto that single value.
Exceptions:
| ArgumentNullException | If the values are null. |
| ArgumentOutOfRangeException | If the confidence level is outside the unit interval. |
| ArgumentException | If fewer than two valid values were provided. |
MeanInterval
#public static Interval MeanInterval(MeanKind kind, IEnumerable<double> values, double confidenceLevel)
Compute a confidence interval for a given kind of true mean of the process which generated the provided values.
Parameters:
| kind (Maths.MeanKind) | Kind of mean to bound. Only the arithmetic, geometric and harmonic means have a confidence interval, as only they are means of the values under some invertible, monotonic rescaling. |
| values (IEnumerable<double>) | Sample values. Invalid numbers are ignored. |
| confidenceLevel (double) | Desired likelihood of the interval containing the true mean. Must be larger than zero and smaller than one. |
Returns: The confidence interval.
Exceptions:
| ArgumentException | If the kind of mean admits no confidence interval, if the values are outside the domain of the rescaling, or if fewer than two valid values were provided. |
SuccessFractionInterval
#Compute the Clopper-Pearson confidence interval for the true success probability behind an observed number of successful trials.
Parameters:
| successes (int) | Number of observed successes, between zero and trials. |
| trials (int) | Number of trials, at least one. |
| confidenceLevel (double) | Desired likelihood of the interval containing the true success probability. Must be larger than zero and smaller than one. |
Returns: The confidence interval, which is always contained in the unit interval but is not in general centred on the observed fraction.
Exceptions:
| ArgumentOutOfRangeException | If any of the arguments is outside its valid range. |
Ttest
#Perform a classical, two-sided, one-sample Student t-test on the provided data, against the null hypothesis that the true mean is zero.
Parameters:
| x (IEnumerable<double>) | Sample values. Invalid numbers are ignored. |
| confidenceLevel (double) | Desired likelihood of the confidence interval containing the true mean. Must be larger than zero and smaller than one. |
Returns: The sample mean, a confidence interval for the true mean, and the probability of observing an at least as extreme sample if the true mean were exactly zero.
Exceptions:
| ArgumentNullException | If the values are null. |
| ArgumentOutOfRangeException | If the confidence level is outside the unit interval. |
| ArgumentException | If fewer than two valid values were provided. |