# Statistics

public class Statistics : NSObject

The class that helps to process numerical data

Statistics was designed to help with the mathematics of the collection, organization, and interpretation of numerical data, especially the analysis of population characteristics by inference from sampling.

•  list 

The list used for statistical computations

#### Declaration

Swift

public var list: [BigNumber]
•  init(list:) 

Creates a Statistics object

#### Declaration

Swift

public init(list: [BigNumber])

#### Parameters

  list  A list of BigDouble used for statistical computations
•  init(_:) 

Creates a Statistics object

Example:

Statistics(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)


#### Declaration

Swift

public init(_ list: Double...)

#### Parameters

  list  A list of Double used for statistical computations

### Average

•  average 

Return the arithmetic mean (average) of the list

The arithmetic mean of a set of values is the quantity commonly called “the” mean or the average. It’s simply the sum of all the terms in a list, divided by the number of elements in the list.

#### Declaration

Swift

var average: BigNumber { get }
•  mean 

Alias for average

#### Declaration

Swift

var mean: BigNumber { get }
•  MAD 

Returns the average of the absolute deviations of data points from their mean. It is a measure of the variability in a data set.

#### Declaration

Swift

var MAD: BigDouble { get }
•  devSquared 

Returns the sum of squares of deviations of data points from their sample mean.

#### Declaration

Swift

var devSquared: BigDouble { get }
•  geometricMean 

Returns the geometric mean.

In mathematics, the geometric mean is a mean or average, which indicates the central tendency or typical value of a set of numbers by using the product of their values (as opposed to the arithmetic mean which uses their sum). The geometric mean is defined as the nth root of the product of n numbers, i.e., for a set of numbers x_1, x_2, …, x_n, the geometric mean is defined as

\left(\prod_{i=1}^n x_i\right)^\frac{1}{n} = \sqrt[n]{x_1 x_2 \cdots x_n}

#### Declaration

Swift

var geometricMean: BigDouble { get }
•  harmonicMean 

Returns the harmonic mean

In mathematics, the harmonic mean (sometimes called the subcontrary mean) is one of several kinds of average, and in particular, one of the Pythagorean means. Typically, it is appropriate for situations when the average of rates is desired.

The harmonic mean can be expressed as the reciprocal of the arithmetic mean of the reciprocals of the given set of observations. As a simple example, the harmonic mean of 1, 4, and 4 is

\left(\frac{1^{-1} + 4^{-1} + 4^{-1}}{3}\right)^{-1} = \frac{3}{\frac{1}{1} + \frac{1}{4} + \frac{1}{4}} = \frac{3}{1.5} = 2

#### Declaration

Swift

var harmonicMean: BigDouble { get }
•  average(coefficients:) 

Return the weighted arithmetic mean (average) of the list with the given coefficients

The weighted arithmetic mean is similar to an ordinary arithmetic mean (the most common type of average), except that instead of each of the data points contributing equally to the final average, some data points contribute more than others. The notion of weighted mean plays a role in descriptive statistics and also occurs in a more general form in several other areas of mathematics.

If all the weights are equal, then the weighted mean is the same as the arithmetic mean. While weighted means generally behave in a similar fashion to arithmetic means, they do have a few counterintuitive properties, as captured for instance in Simpson’s paradox.

#### Declaration

Swift

func average(coefficients: [BigNumber]) throws -> BigNumber

#### Parameters

  coefficients  The weighted coefficients you want to use to multiply the original list.

### Correlation

•  correlation(with:) 

This function returns the correlation coefficient of two cell ranges.

Use the correlation coefficient to determine the relationship between two properties. For example, you can examine the relationship between a location’s average temperature and the use of air conditioners.

#### Declaration

Swift

func correlation(with list: [BigNumber]) throws -> BigNumber

#### Parameters

  list  A second array to be compared with.

### Fisher

•  fisher(at:) 

Returns the Fisher transformation at x. This transformation produces a function that is normally distributed rather than skewed. Use this function to perform hypothesis testing on the correlation coefficient.

#### Declaration

Swift

static func fisher(at x: BigDouble) -> BigDouble

#### Parameters

  x  A numeric value for which you want the transformation.

#### Return Value

The Fisher transformation at x.

•  inverseFisher(at:) 

Returns the inverse of the Fisher transformation. Use this transformation when analyzing correlations between ranges or arrays of data. If y = fisher(x), then inverseFisher(y) = x.

#### Declaration

Swift

static func inverseFisher(at y: BigDouble) -> BigDouble

#### Parameters

  y  The image of x using the fisher transformation

#### Return Value

The inverse of the Fisher transformation.

### Gauss

•  ERF(at:) 

In mathematics, the error function (also called the Gauss error function), often denoted by erf, is a complex function of a complex variable defined as:

\operatorname{erf} z = \frac{2}{\sqrt\pi}\int_0^z e^{-t^2}\,dt

#### Declaration

Swift

static func ERF(at x: BigDouble) -> BigDouble

#### Parameters

  x  Any number

#### Return Value

\operatorname{erf}(x)

•  gauss(at:) 

Integral of the Gauss function

Computed using:

\int_{0}^{x}\frac{1}{\sqrt{2\pi}}*e^{-\frac{x^{2}}{2}}dx = \frac{1}{2}\cdot \operatorname{erf}\left( \frac{x}{\sqrt{2}} \right)

#### Declaration

Swift

static func gauss(at x: BigDouble) -> BigDouble

#### Parameters

  x  Any number

### Median & Quantile

•  median 

Returns the median of the given numbers. The median is the number in the middle of a set of numbers.

If there is an even number of numbers in the set, then MEDIAN calculates the average of the two numbers in the middle.

#### Declaration

Swift

var median: BigNumber { get }
•  quantile(percentage:) 

Returns corresponding quantile

In statistics and probability quantiles are cut points dividing the range of a probability distribution into continuous intervals with equal probabilities, or dividing the observations in a sample in the same way. There is one fewer quantile than the number of groups created. Thus quartiles are the three cut points that will divide a dataset into four equal-sized groups. Common quantiles have special names: for instance quartile, decile (creating 10 groups: see below for more). The groups created are termed halves, thirds, quarters, etc., though sometimes the terms for the quantile are used for the groups created, rather than for the cut points.

#### Declaration

Swift

func quantile(percentage: Double) throws -> BigNumber

#### Parameters

  percentage  The percentage of distribution (ex: 0.25 is the first quartile)

### Regression

•  linearRegression(points:) 

Linear regression on a set of points

Returns an affine function going through the set of point.

#### Declaration

Swift

static func linearRegression(points: [Point]) throws -> Polynomial

#### Parameters

  points  A set of points

### Variance

•  standardDeviation 

Returns the standard deviation of the list

The standard deviation (SD, also represented by the lower case Greek letter sigma σ for the population standard deviation or the Latin letter s for the sample standard deviation) is a measure of the amount of variation or dispersion of a set of values. A low standard deviation indicates that the values tend to be close to the mean (also called the expected value) of the set, while a high standard deviation indicates that the values are spread out over a wider range.

Computed using:

\sigma = \sqrt{\frac{\sum_{}^{}(x-\bar{x})^2}{n-1}}

#### Declaration

Swift

var standardDeviation: BigNumber { get }
•  variance 

Returns the variance of the list

In probability theory and statistics, variance is the expectation of the squared deviation of a random variable from its mean. Informally, it measures how far a set of (random) numbers are spread out from their average value.

Computed using:

V = \sigma^2 = \frac{\sum_{}^{}(x-\bar{x})^2}{n-1}

#### Declaration

Swift

var variance: BigNumber { get }