This project has moved and is read-only. For the latest updates, please go here.
The Sample class is a data container for experiments consisting of independent measurements of a singe variable. Suppose, for example that you have time-to-failure measurements of a random sample of components produced by some manufacturing process. The time-to-failure values are: 1.0, 1.3, 1.5, 1.7, and 1.9. This data can be stored in a Sample class as follows:

using Meta.Numerics.Statistics;

// store data in a sample
Sample sample = new Sample();
sample.Add(1.0, 1.3, 1.5, 1.7, 1.9);

To control the contents of the sample, you can also use the Add overload that accepts a single value, the Remove method to remove a single value, and the Clear method to remove all values. There is a Load method that facilitates drawing data from a database or Excel spreadsheet.

Descriptive Statistics

The Sample class provides property for summary statistics for the sample and estimates of summary statistics for the underlying population.

// get the sample standard deviation
double sampleStandardDeviation = sample.StandardDeviation;
// get estimates (with standard errors!) of population moments
UncertainValue populationMean = sample.PopulationMean;
UncertainValue populationStandardDeviation = sample.PopulationStandardDeviation;
UncertainValue populationThirdMoment = sample.PopulationMomentAboutMean(3);

It's easy to convert those error bars into confidence intervals:

// find 95% confidence interval on population mean
Interval meanInverval = sample.PopulationMean.ConfidenceInterval(0.95);

Statistical Tests

The Sample class supports several statistical tests appropriate to univariate samples. For example, you can perform a Student t-test to determine whether you can state with some critical confidence level whether the sample was drawn from a population with a mean above or below some reference level. Suppose, for example, that our customer wishes us to guarantee, with 95% confidence, that the mean-time-to-failure of our component is above 1.25.

// test whether mu > 1.25 with 95% confidence
TestResult t = sample.StudentTTest(1.25);
if (t.LeftProbability > 0.95) {
    Console.WriteLine("95% confident that mu > 1.25");
} else {
    Console.WriteLine("not 95% confident that mu > 1.25");

The Sample class also supports the F-test, the z-test, the sign test, the two-sample t-test, the Mann-Whitney U test, the one-way ANOVA, the Kruskal-Wallis test, and both Kolmogorov-Smirnov and Kuiper tests against a Distribution or another sample.

Fitting to a Distribution

You may want to fit your sample to a parameterized distribution. Suppose, for example, we wish to fit our time-to-failure data to a Weibull distribution.

using Meta.Numerics.Statistics.Distributions;

// fit to a Weibull distribution
FitResut fit = WeibullDistribution.FitToSample(sample);
// write out the fit parameters parameters and their associated uncertainties
for (int i = 0; i < fit.Dimension; i++) {
    UncertainValue parameter = fit.Parameter(0);
    Console.WriteLine("a[{0}] = {1}", i, parameter);

Last edited Apr 6, 2011 at 6:38 AM by ichbin, version 6


No comments yet.