Created
May 4, 2011 15:58
-
-
Save jmoody/955463 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
- (NSDecimalNumber *) standardDeviationWithPreviousPoints:(NSArray *) dataPoints | |
event:(CountEvent *) event { | |
NSDecimalNumber *result; | |
if ([self canComputeNonMeanStatistics:dataPoints]) { | |
NSDecimalNumber *accumulator = [NSDecimalNumber zero]; | |
NSArray *allMeans = [self arrayWithDataPoints:dataPoints event:event]; | |
NSDecimalNumber *mean = [self mean:allMeans]; | |
NSDecimalNumber *variance; | |
for (NSDecimalNumber *number in allMeans) { | |
variance = [self varianceWithActual:number mean:mean]; | |
accumulator = [accumulator decimalNumberByAdding:variance]; | |
} | |
// we need n - 1, but thankfully, that is what we have here | |
// because we added the current variance before iterating over | |
// the points | |
NSDecimalNumber *n = [LjsDecimalAide dnWithInt:[self dataPointsCount:dataPoints]]; | |
NSDecimalNumber *sigmaSquared = [accumulator decimalNumberByDividingBy:n]; | |
result = [self squareRootWithDecimal:sigmaSquared]; | |
} else { | |
result = self.uncomputableStatistic; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment