{"id":19712554,"url":"https://github.com/evgenyneu/sigmaswiftstatistics","last_synced_at":"2025-04-04T09:07:16.355Z","repository":{"id":31745458,"uuid":"35311530","full_name":"evgenyneu/SigmaSwiftStatistics","owner":"evgenyneu","description":"A collection of functions for statistical calculation written in Swift.","archived":false,"fork":false,"pushed_at":"2022-02-08T06:34:59.000Z","size":791,"stargazers_count":705,"open_issues_count":10,"forks_count":62,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-03-28T08:05:22.080Z","etag":null,"topics":["statistics","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/evgenyneu.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-09T02:21:46.000Z","updated_at":"2025-01-30T11:46:07.000Z","dependencies_parsed_at":"2022-08-20T22:20:25.663Z","dependency_job_id":null,"html_url":"https://github.com/evgenyneu/SigmaSwiftStatistics","commit_stats":null,"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evgenyneu%2FSigmaSwiftStatistics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evgenyneu%2FSigmaSwiftStatistics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evgenyneu%2FSigmaSwiftStatistics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evgenyneu%2FSigmaSwiftStatistics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evgenyneu","download_url":"https://codeload.github.com/evgenyneu/SigmaSwiftStatistics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247149500,"owners_count":20891954,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["statistics","swift"],"created_at":"2024-11-11T22:17:37.833Z","updated_at":"2025-04-04T09:07:16.321Z","avatar_url":"https://github.com/evgenyneu.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# σ (sigma) - statistics library written in Swift\n\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![CocoaPods Version](https://img.shields.io/cocoapods/v/SigmaSwiftStatistics.svg?style=flat)](http://cocoadocs.org/docsets/SigmaSwiftStatistics)\n[![License](https://img.shields.io/cocoapods/l/SigmaSwiftStatistics.svg?style=flat)](http://cocoadocs.org/docsets/SigmaSwiftStatistics)\n[![Platform](https://img.shields.io/cocoapods/p/SigmaSwiftStatistics.svg?style=flat)](http://cocoadocs.org/docsets/SigmaSwiftStatistics)\n\nThis library is a collection of functions that perform statistical calculations in Swift. It can be used in Swift apps for Apple devices and in open source Swift programs on other platforms.\n\n* [average](#average--mean)\n* [centralMoment](#central-moment)\n* [covariancePopulation](#covariance-of-a-population)\n* [covarianceSample](#covariance-of-a-sample)\n* [coefficientOfVariationSample](#coefficient-of-variation-of-a-sample)\n* [frequencies](#frequencies)\n* [kurtosisA](#kurtosis-a)\n* [kurtosisB](#kurtosis-b)\n* [max](#max)\n* [median](#median)\n* [medianHigh](#median-high)\n* [medianLow](#median-low)\n* [min](#min)\n* [normalDistribution](#normal-distribution)\n* [normalDensity](#normal-density)\n* [normalQuantile](#normal-quantile)\n* [pearson](#pearson-correlation-coefficient)\n* [percentile](#percentile)\n* [quantiles](#quantiles)\n* [rank](#rank)\n* [skewnessA](#skewness-a)\n* [skewnessB](#skewness-b)\n* [standardDeviationPopulation](#standard-deviation-of-a-population)\n* [standardDeviationSample](#standard-deviation-of-a-sample)\n* [standardErrorOfTheMean](#standard-error-of-the-mean)\n* [sum](#sum)\n* [uniqueValues](#unique-values)\n* [variancePopulation](#variance-of-a-population)\n* [varianceSample](#variance-of-a-sample)\n\n\u003cimg src='https://raw.githubusercontent.com/evgenyneu/SwiftStatistics/master/Graphics/logo.png' width='256' alt='Statistical library for Swift'\u003e\n\n## Setup\n\nThere are four ways you can add Sigma to your project.\n\n**Add source (iOS 7+)**\n\nSimply add [SigmaDistrib.swift](https://github.com/evgenyneu/SigmaSwiftStatistics/blob/master/Distrib/SigmaDistrib.swift) file to your project.\n\n#### Setup with Carthage (iOS 8+)\n\nAlternatively, add `github \"evgenyneu/SigmaSwiftStatistics\" ~\u003e 9.0` to your Cartfile and run `carthage update`.\n\n#### Setup with CocoaPods (iOS 8+)\n\nIf you are using CocoaPods add this text to your Podfile and run `pod install`.\n\n    use_frameworks!\n    target 'Your target name'\n    pod 'SigmaSwiftStatistics', '~\u003e 9.0'\n\n\n#### Setup with Swift Package Manager\n\n* In Xcode 11+ select *File \u003e Packages \u003e Add Package Dependency...*.\n* Enter this project's URL: https://github.com/evgenyneu/SigmaSwiftStatistics.git\n\n\n\n### Legacy Swift versions\n\nSetup a [previous version](https://github.com/evgenyneu/SigmaSwiftStatistics/wiki/Legacy-Swift-versions) of the library if you use an older version of Swift.\n\n\n## Usage\n\nAdd `import SigmaSwiftStatistics` to your source code unless you used the file setup method.\n\n\n### Average / mean\n\nComputes [arithmetic mean](http://en.wikipedia.org/wiki/Arithmetic_mean) of values in the array.\n\n**Note**:\n\n  * Returns nil for an empty array.\n  * Same as AVERAGE in Microsoft Excel and Google Docs Sheets.\n\n#### Formula\n\n\u003e A = Σ(x) / n\n\nWhere:\n\n  * *n* is the number of values.\n\n```Swift\nSigma.average([1, 3, 8])\n// Result: 4\n```\n\n\n\n### Central moment\n\nComputes [central moment](https://en.wikipedia.org/wiki/Central_moment) of the dataset.\n\nNote:\n\n  * Returns nil for an empty array.\n  * Same as in Wolfram Alpha and \"moments\" R package.\n\n#### Formula\n\n\u003e Σ(x - m)^k / n\n\nWhere:\n\n  * *m* is the sample mean.\n  * *k* is the order of the moment (0, 1, 2, 3, ...).\n  * *n* is the sample size.\n\n```Swift\nSigma.centralMoment([3, -1, 1, 4.1, 4.1, 0.7], order: 3)\n// Result: -1.5999259259\n```\n\n\n\n### Covariance of a population\n\nComputes [covariance](http://en.wikipedia.org/wiki/Covariance) of the entire population\nbetween two variables: x and y.\n\n**Note**:\n\n  * Returns nil if arrays x and y have different number of values.\n  * Returns nil for empty arrays.\n  * Same as COVAR and COVARIANCE.P functions in Microsoft Excel and COVAR in Google Docs Sheets.\n\n#### Formula\n\n\u003e cov(x,y) = Σ(x - mx)(y - my) / n\n\nWhere:\n\n  * *mx* is the population mean of the first variable.\n  * *my* is the population mean of the second variable.\n  * *n* is the total number of values.\n\n```Swift\nlet x = [1, 2, 3.5, 3.7, 8, 12]\nlet y = [0.5, 1, 2.1, 3.4, 3.4, 4]\nSigma.covariancePopulation(x: x, y: y)\n// Result: 4.19166666666667\n```\n\n\n\n### Covariance of a sample\n\nComputes [sample covariance](http://en.wikipedia.org/wiki/Sample_mean_and_sample_covariance) between two variables: x and y.\n\nNote:\n\n  * Returns nil if arrays x and y have different number of values.\n  * Returns nil for empty arrays or arrays containing a single element.\n  * Same as COVARIANCE.S function in Microsoft Excel.\n\n#### Formula\n\n\u003e cov(x,y) = Σ(x - mx)(y - my) / (n - 1)\n\nWhere:\n\n  * *mx* is the sample mean of the first variable.\n  * *my* is the sample mean of the second variable.\n  * *n* is the total number of values.\n\n```Swift\nlet x = [1, 2, 3.5, 3.7, 8, 12]\nlet y = [0.5, 1, 2.1, 3.4, 3.4, 4]\nSigma.covarianceSample(x: x, y: y)\n// Result: 5.03\n```\n\n\n### Coefficient of variation of a sample\n\nComputes [coefficient of variation](https://en.wikipedia.org/wiki/Coefficient_of_variation) based on a sample.\n\n\nNote:\n\n  * Returns nil when the array is empty or contains a single value.\n  * Returns `Double.infinity` if the mean is zero.\n  * Same as in Wolfram Alfa and in \"raster\" R package (expressed as a percentage in \"raster\").\n\n#### Formula\n\n\u003e CV = s / m\n\nWhere:\n\n  * *s* is the sample standard deviation.\n  * *m* is the mean.\n\n```Swift\nSigma.coefficientOfVariationSample([1, 12, 19.5, -5, 3, 8])\n// Result: 1.3518226672\n```\n\n\n### Frequencies\n\nReturns a dictionary with the keys containing the numbers from the input array and the values corresponding to the frequencies of those numbers.\n\n\n```Swift\nSigma.frequencies([1, 2, 3, 4, 5, 4, 4, 3, 5])\n// Result: [2:1, 3:2, 4:3, 5:2, 1:1]\n```\n\n\n### Kurtosis A\n\nReturns the [kurtosis](https://en.wikipedia.org/wiki/Kurtosis) of a series of numbers.\n\n**Note**:\n\n  * Returns nil if the dataset contains less than 4 values.\n  * Returns nil if all the values in the dataset are the same.\n  * Same as KURT in Microsoft Excel and Google Docs Sheets.\n\n#### Formula\n\n\n\u003cimg src='https://github.com/evgenyneu/SigmaSwiftStatistics/raw/master/Graphics/formulas/kurtosis_a.png' width='480' alt='Kurtosis formula'\u003e\n\n\n```Swift\nSigma.kurtosisA([2, 1, 3, 4.1, 19, 1.5])\n// Result: 5.4570693277\n```\n\n\n\n\n### Kurtosis B\n\nReturns the [kurtosis](https://en.wikipedia.org/wiki/Kurtosis) of a series of numbers.\n\n**Note**:\n\n  * Returns nil if the dataset contains less than 2 values.\n  * Returns nil if all the values in the dataset are the same.\n  * Same as in Wolfram Alpha and \"moments\" R package.\n\n#### Formula\n\n\n\u003cimg src='https://github.com/evgenyneu/SigmaSwiftStatistics/raw/master/Graphics/formulas/kurtosis_b.png' width='550' alt='Kurtosis formula'\u003e\n\n\n```Swift\nSigma.kurtosisB([2, 1, 3, 4.1, 19, 1.5])\n// Result: 4.0138523409\n```\n\n\n\n\n### Max\n\nReturns the maximum value in the array.\n\n**Note**: returns nil for an empty array.\n\n```Swift\nSigma.max([1, 8, 3])\n// Result: 8\n```\n\n\n### Median\n\nReturns the [median value](http://en.wikipedia.org/wiki/Median) from the array.\n\n**Note**:\n\n * Returns nil when the array is empty.\n * Returns the mean of the two middle values if there is an even number of items in the array.\n * Same as MEDIAN in Microsoft Excel and Google Docs Sheets.\n\n```Swift\nSigma.median([1, 12, 19.5, 3, -5])\n// Result: 3\n```\n\n\n### Median high\n\nReturns the [median value](http://en.wikipedia.org/wiki/Median) from the array.\n\n**Note**:\n\n* Returns nil when the array is empty.\n* Returns the higher of the two middle values if there is an even number of items in the array.\n\n```Swift\nSigma.medianHigh([1, 12, 19.5, 10, 3, -5])\n// Result: 10\n```\n\n\n\n### Median low\n\nReturns the [median value](http://en.wikipedia.org/wiki/Median) from the array.\n\n**Note**:\n\n* Returns nil when the array is empty.\n* Returns the lower of the two middle values if there is an even number of items in the array.\n\n```Swift\nSigma.medianLow([1, 12, 19.5, 10, 3, -5])\n// Result: 3\n```\n\n\n### Min\n\nReturns the minimum value in the array.\n\n**Note**: returns nil for an empty array.\n\n```Swift\nSigma.min([7, 2, 3])\n// Result: 2\n```\n\n\n\n### Normal distribution\n\nReturns the [normal distribution](https://en.wikipedia.org/wiki/Normal_distribution) for the given values of `x`, `μ` and `σ`. The returned value is the area under the normal curve to the left of the value `x`.\n\n**Note**:\n\n  * Returns nil if σ is zero or negative.\n  * Defaults: `μ = 0`, `σ = 1`.\n  * Same as NORM.S.DIST, NORM.DIST and NORMDIST Excel functions and NORMDIST function in Google Docs sheet with `cumulative` argument equal to `true`.\n\n```Swift\nSigma.normalDistribution(x: -1, μ: 0, σ: 1)\n// Result: 0.1586552539314570\n```\n\n\n### Normal density\n\nReturns density of the [normal function](https://en.wikipedia.org/wiki/Normal_distribution) for the given values of `x`, `μ` and `σ`.\n\n**Note**:\n\n  * Returns nil if σ is zero or negative.\n  * Defaults: `μ = 0`, `σ = 1`.\n  * Same as NORM.S.DIST, NORM.DIST and NORMDIST Excel functions and NORMDIST function in Google Docs sheet with `cumulative` argument equal to `false`.\n\n\n#### Formula\n\n\u003cimg src='https://github.com/evgenyneu/SigmaSwiftStatistics/raw/master/Graphics/formulas/normal_density.png' width='150' alt='Nodemal density function'\u003e\n\nWhere:\n\n  * *x* is the input value of the normal density function.\n  * *μ* is the mean.\n  * *σ* is the standard deviation.\n\n\n```Swift\nSigma.normalDensity(x: 0, μ: 0, σ: 1)\n// Result: 0.3989422804014327\n```\n\n\n### Normal quantile\n\nReturns the quantile function for the [normal distribution](https://en.wikipedia.org/wiki/Normal_distribution) (the inverse of normal distribution). The `p` argument is the probability, or the area under the normal curve to the left of the returned value.\n\n**Note**:\n\n  * Returns nil if σ is zero or negative.\n  * Returns nil if p is negative or greater than one.\n  * Returns `-Double.infinity` if p is zero, and `Double.infinity` if p is one.\n  * Defaults: `μ = 0`, `σ = 1`.\n  * Same as NORM.INV, NORM.S.INV and NORMINV Excel functions and NORMINV, NORMSINV Google Docs sheet functions.\n\n```Swift\nSigma.normalQuantile(p: 0.025, μ: 0, σ: 1)\n// -1.9599639845400538\n```\n\n\n\n### Pearson correlation coefficient\n\nCalculates the\n[Pearson product-moment correlation coefficient](http://en.wikipedia.org/wiki/Pearson_product-moment_correlation_coefficient)\nbetween two variables: x and y.\n\n**Note**:\n\n  * Returns nil if arrays x and y have different number of values.\n  * Returns nil for empty arrays.\n  * Same as CORREL and PEARSON functions in Microsoft Excel and Google Docs Sheets.\n\n#### Formula\n\n\u003e p(x,y) = cov(x,y) / (σx * σy)\n\nWhere:\n\n  * *cov* is the population covariance.\n  * *σ* is the population standard deviation.\n\n```Swift\nlet x = [1, 2, 3.5, 3.7, 8, 12]\nlet y = [0.5, 1, 2.1, 3.4, 3.4, 4]\nSigma.pearson(x: x, y: y)\n// Result: 0.843760859352745\n```\n\n\n\n### Percentile\n\nCalculates the [Percentile value](https://en.wikipedia.org/wiki/Percentile) for the given dataset.\n\n**Note**:\n\n * Returns nil when the `values` array is empty.\n * Returns nil when supplied `percentile` parameter is negative or greater than 1.\n * Same as PERCENTILE or PERCENTILE.INC in Microsoft Excel and PERCENTILE in Google Docs Sheets.\n * Same as the 7th sample quantile method from the [Hyndman and Fan paper (1996)](https://www.jstor.org/stable/2684934).\n\nSee the [Percentile method](https://github.com/evgenyneu/SigmaSwiftStatistics/wiki/Percentile-1-method) documentation for more information.\n\n```Swift\n// Calculate 40th percentile\nSigma.percentile([35, 20, 50, 40, 15], percentile: 0.4)\n// Result: 29\n\n// Same as\nSigma.quantiles.method7([35, 20, 50, 40, 15], probability: 0.4)\n```\n\n### Quantiles\n\nCollection of nine functions that calculate [sample quantiles](https://en.wikipedia.org/wiki/Quantile) corresponding to the given probability. This is an implementation of the nine algorithms described in the [Hyndman and Fan paper (1996)](https://www.jstor.org/stable/2684934). The documentation of the functions is based on [R](http://stat.ethz.ch/R-manual/R-devel/library/stats/html/quantile.html) and [Wikipedia](https://en.wikipedia.org/wiki/Quantile).\n\n**Note**:\n\n  * Returns nil if the dataset is empty.\n  * Returns nil if the probability is outside the [0, 1] range.\n  * Same as `quantile` function in R.\n\n\n#### Quantile method 1\n\nThis method calculates quantiles using the inverse of the empirical distribution function.\n\n```Swift\nSigma.quantiles.method1([1, 12, 19.5, -5, 3, 8], probability: 0.5)\n// Result: 3\n```\n\n#### Quantile method 2\n\nThis method uses inverted empirical distribution function with averaging.\n\n```Swift\nSigma.quantiles.method2([1, 12, 19.5, -5, 3, 8], probability: 0.5)\n// Result: 5.5\n```\n\n#### Quantile method 3\n\n```Swift\nSigma.quantiles.method3([1, 12, 19.5, -5, 3, 8], probability: 0.5)\n// Result: 3\n```\n\n#### Quantile method 4\n\nThe method uses linear interpolation of the empirical distribution function.\n\n```Swift\nSigma.quantiles.method4([1, 12, 19.5, -5, 3, 8], probability: 0.17)\n// Result: -4.88\n```\n\n#### Quantile method 5\n\nThis method uses a piecewise linear function where the knots are the values midway through the steps of the empirical distribution function.\n\n```Swift\nSigma.quantiles.method5([1, 12, 19.5, -5, 3, 8], probability: 0.11)\n// Result: -4.04\n```\n\n#### Quantile method 6\n\nThis method is implemented in Microsoft Excel (PERCENTILE.EXC), Minitab and SPSS. It uses linear interpolation of the expectations for the order statistics for the uniform distribution on [0,1].\n\n```Swift\nSigma.quantiles.method6([1, 12, 19.5, -5, 3, 8], probability: 0.1999)\n// Result: -2.6042\n```\n\n#### Quantile method 7\n\nThis method is implemented in S, Microsoft Excel (PERCENTILE or PERCENTILE.INC) and Google Docs Sheets (PERCENTILE). It uses linear interpolation of the modes for the order statistics for the uniform distribution on [0, 1].\n\n```Swift\nSigma.quantiles.method7([1, 12, 19.5, -5, 3, 8], probability: 0.00001)\n// Result: -4.9997\n```\n\n#### Quantile method 8\n\nThe quantiles returned by the method are approximately median-unbiased regardless of the distribution of x.\n\n```Swift\nSigma.quantiles.method8([1, 12, 19.5, -5, 3, 8], probability: 0.11)\n// Result: -4.82\n```\n\n#### Quantile method 9\n\nThe quantiles returned by this method are approximately unbiased for the expected order statistics if x is normally distributed.\n\n```Swift\nSigma.quantiles.method9([1, 12, 19.5, -5, 3, 8], probability: 0.10001)\n// Result: -4.999625\n```\n\n\n### Rank\n\nReturns the [ranks](https://en.wikipedia.org/wiki/Ranking) of the values in the dataset.\n\n**Note**:\n\n  * Receives an optional `ties` parameter that determines how the ranks for the equal values ('ties') are calculated. Default value is `.average`. Possible values:\n\n    * `.average`: uses the average rank. Same as RANK.AVG in Microsoft Excel and Google Docs Sheets.\n    * `.min`, `.max`: uses the minimum/maximum rank. The value `.min` is the same as RANK and RANK.EQ in Microsoft Excel and Google Docs Sheets.\n    * `.first`, `.last`: the ranks are incremented/decremented.\n\n  * Same as rank function in R.\n\n\n```Swift\nSigma.rank([2, 3, 6, 5, 3], ties: .average)\n// Result: [1.0, 2.5, 5.0, 4.0, 2.5]\n```\n\n\n\n### Skewness A\n\nReturns the [skewness](https://en.wikipedia.org/wiki/Skewness) of the dataset.\n\n**Note**:\n\n  * Returns nil if the dataset contains less than 3 values.\n  * Returns nil if all the values in the dataset are the same.\n  * Same as SKEW in Microsoft Excel and Google Docs Sheets.\n\n#### Formula\n\n\n\u003cimg src='https://github.com/evgenyneu/SigmaSwiftStatistics/raw/master/Graphics/formulas/skewness_a.png' width='450' alt='Skewness formula'\u003e\n\n\n```Swift\nSigma.skewnessA([4, 2.1, 8, 21, 1])\n// Result: 1.6994131524\n```\n\n\n\n### Skewness B\n\nReturns the [skewness](https://en.wikipedia.org/wiki/Skewness) of the dataset.\n\n**Note**:\n\n  * Returns nil if the dataset contains less than 3 values.\n  * Returns nil if all the values in the dataset are the same.\n  * Same as in Wolfram Alpha, SKEW.P in Microsoft Excel and `skewness` function in \"moments\" R package.\n\n#### Formula\n\n\n\u003cimg src='https://github.com/evgenyneu/SigmaSwiftStatistics/raw/master/Graphics/formulas/skewness_b.png' width='450' alt='Skewness formula'\u003e\n\n\n```Swift\nSigma.skewnessB([4, 2.1, 8, 21, 1])\n// Result: 1.1400009992\n```\n\n\n\n### Standard deviation of a population\n\nComputes [standard deviation](http://en.wikipedia.org/wiki/Standard_deviation) of entire population.\n\n**Note**:\n\n  * Returns nil for an empty array.\n  * Same as STDEVP and STDEV.P in Microsoft Excel and STDEVP in Google Docs Sheets.\n\n#### Formula\n\n\u003e  σ = sqrt( Σ( (x - m)^2 ) / n )\n\nWhere:\n\n  * *m* is the population mean.\n  * *n* is the population size.\n\n```Swift\nSigma.standardDeviationPopulation([1, 12, 19.5, -5, 3, 8])\n// Result: 7.918420858282849\n```\n\n\n\n### Standard deviation of a sample\n\nComputes [standard deviation](http://en.wikipedia.org/wiki/Standard_deviation) based on a sample.\n\n**Note**:\n\n  * Returns nil when the array is empty or contains a single value.\n  * Same as STDEV and STDEV.S in Microsoft Excel and STDEV in Google Docs Sheets.\n\n#### Formula\n\n\u003e  s = sqrt( Σ( (x - m)^2 ) / (n - 1) )\n\nWhere:\n\n  * *m* is the sample mean.\n  * *n* is the sample size.\n\n```Swift\nSigma.standardDeviationSample([1, 12, 19.5, -5, 3, 8])\n// Result: 8.674195447801869\n```\n\n\n### Standard error of the mean\n\nComputes [standard error](http://en.wikipedia.org/wiki/Standard_error) of the mean.\n\n**Note**:\n\n  * Returns nil when the array is empty or contains a single value.\n\n#### Formula\n\n\u003e  SE = s / sqrt(n)\n\nWhere:\n\n  * *s* is the sample standard deviation.\n  * *n* is the sample size.\n\n```Swift\nSigma.standardErrorOfTheMean([1, 12, 19.5, -5, 3, 8])\n// Result: 3.5412254627\n```\n\n\n\n### Sum\n\nComputes sum of values from the array.\n\n```Swift\nSigma.sum([1, 3, 8])\n// Result: 12\n```\n\n\n### Unique values\n\nReturns an unsorted array containing all values that occur within the input array without the duplicates.\n\n\n```Swift\nSigma.uniqueValues([2, 1, 3, 4, 5, 4, 3, 5])\n// Result: [2, 3, 4, 5, 1]\n```\n\n\n### Variance of a population\n\nComputes [variance](http://en.wikipedia.org/wiki/Variance) of entire population.\n\n**Note**:\n\n  * Returns nil when the array is empty.\n  * Same as VAR.P or VARPA in Microsoft Excel and VARP or VARPA in Google Docs Sheets.\n\n#### Formula\n\n\u003e  σ^2 = Σ( (x - m)^2 ) / n\n\nWhere:\n\n  * *m* is the population mean.\n  * *n* is the population size.\n\n```Swift\nSigma.variancePopulation([1, 12, 19.5, -5, 3, 8])\n// Result: 62.70138889\n```\n\n\n### Variance of a sample\n\nComputes [variance](http://en.wikipedia.org/wiki/Variance) based on a sample.\n\n**Note**:\n\n  * Returns nil when the array is empty or contains a single value.\n  * Same as VAR, VAR.S or VARA in Microsoft Excel and VAR or VARA in Google Docs Sheets.\n\n#### Formula\n\n\u003e  s^2 = Σ( (x - m)^2 ) / (n - 1)\n\nWhere:\n\n  * *m* is the sample mean.\n  * *n* is the sample size.\n\n```Swift\nSigma.varianceSample([1, 12, 19.5, -5, 3, 8])\n// Result: 75.24166667\n```\n\n\n\n\n## Feedback is welcome\n\nIf you need help or want to extend the library feel free to create an issue or submit a pull request.\n\n\u003e Help will always be given at Hogwarts to those who ask for it.\n\n-- J.K. Rowling, Harry Potter\n\n\n## Contributors\n\n* [John Clema](https://github.com/JohnClema)\n* [Thomas Fankhauser](https://github.com/southdesign)\n* [Alan J. Salmoni](https://github.com/salmoni)\n\n\n## License\n\nSigma is released under the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevgenyneu%2Fsigmaswiftstatistics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevgenyneu%2Fsigmaswiftstatistics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevgenyneu%2Fsigmaswiftstatistics/lists"}