# stig/Statistics

A stab at a very simple statistics class for Objective-C
Objective-C
Latest commit 35ddbb3 Aug 20, 2015 Merge pull request #7 from stevepeak/patch-1
Debugging coverage reports
 Failed to load latest commit information. Classes Documentation English.lproj Statistics-ios Statistics-iosTests Statistics.xcodeproj Tests .gitignore .travis.yml Info.plist Readme.md Statistics_Prefix.pch Tests-Info.plist

# Statistics

Statistics is a Foundation framework for calculating—no points for guessing it—statistics. It is inspired by Perl's Statistics::Descriptive and like it consists of two main classes.

SBStatistics calculates a range of statistical measurements on the fly as each data point is added. The data is then immediately discarded, giving it a very low memory footprint.

SBFullStatistics in turn subclasses SBStatistics and records each data point. It is therefore able to provide more advanced statistical functions. The trade-off is that it can consume a lot of memory if you are collecting a lot of data.

## Examples

The following example assumes you have included the @p Statistics/Statistics.h header and somehow linked to the Statistics framework:

// Create statistics object
SBStatistics *stat = [SBStatistics new];

// Add some random data points
for (int i = 0; i < 1000; i++)

// Format report
id fmt = [NSMutableArray array];
[fmt addObject:@"Data set consists of %u data points."];

// Print it
NSLog([fmt componentsJoinedByString:@"\n"],
stat.count,
stat.min,
stat.max,
stat.mean,
[stat variance],
[stat standardDeviation]
);

The SBFullStatistics class can do other interesting stuff:

// Create statistics object
SBFullStatistics *stat = [SBFullStatistics new];

for (int i = 0; i < 1e4; i++)

// Produce 10 equally-sized buckets covering the entire range
id buckets = [stat bucketsWithCount:10];

// Calculate frequency distributions.
id freq = [stat frequencyDistributionWithBuckets:buckets
cumulative:NO];
id cfreq = [stat frequencyDistributionWithBuckets:buckets
cumulative:YES];

// Iterate over the buckets and output the values
for (id bucket in buckets)
NSLog(@"%@ => %@ => %@",
bucket,
[freq objectForKey:bucket],
[cfreq objectForKey:bucket]);