Import SigmaSwiftStatistics
masterTo use the library in your Swift source code, add the following import statement. If you are using the file setup method instead of a package manager, you may not need this.
import SigmaSwiftStatisticsrepository·master·Indexed 20 days ago
https://github.com/evgenyneu/sigmaswiftstatisticsA Swift statistics library providing functions for statistical calculations, including averages, moments, covariance, distributions, and more. It includes implementations for population and sample variance, standard deviation, kurtosis, skewness, Pearson correlation, and nine different sample quantile methods based on Hyndman and Fan (1996).
To use the library in your Swift source code, add the following import statement. If you are using the file setup method instead of a package manager, you may not need this.
import SigmaSwiftStatisticsTo install SigmaSwiftStatistics using Swift Package Manager in Xcode 11 or later:
https://github.com/evgenyneu/SigmaSwiftStatistics.githttps://github.com/evgenyneu/SigmaSwiftStatistics.gitYou can integrate the SigmaSwiftStatistics library into your project using one of the following four methods:
SigmaDistrib.swift file to your project.Cartfile and run carthage update.Podfile and run pod install.# Carthage
github "evgenyneu/SigmaSwiftStatistics" ~> 9.0
# CocoaPods
use_frameworks!
target 'Your target name' do
pod 'SigmaSwiftStatistics', '~> 9.0'
endCalculates the Pearson product-moment correlation coefficient between two variables x and y.
Note:
nil if arrays have different lengths or are empty.CORREL in Excel/Google Sheets.let x = [1, 2, 3.5, 3.7, 8, 12]
let y = [0.5, 1, 2.1, 3.4, 3.4, 4]
Sigma.pearson(x: x, y: y)Computes the variance of a dataset.
nil if the array is empty.VAR.P or VARPA in Excel.Sigma.variancePopulation([1, 12, 19.5, -5, 3, 8])nil if the array is empty or contains a single value.VAR or VAR.S in Excel.Sigma.varianceSample([1, 12, 19.5, -5, 3, 8])Returns the skewness of the dataset.
nil if the dataset has less than 3 values or if all values are identical.SKEW in Excel/Google Sheets.Sigma.skewnessA([4, 2.1, 8, 21, 1])nil if the dataset has less than 3 values or if all values are identical.SKEW.P in Excel and the "moments" R package.Sigma.skewnessB([4, 2.1, 8, 21, 1])Returns a dictionary where keys are the unique numbers from the input array and values are their respective frequencies.
Sigma.frequencies([1, 2, 3, 4, 5, 4, 4, 3, 5])
// Result: [2:1, 3:2, 4:3, 5:2, 1:1]Calculates the percentile value for a given dataset.
Note:
nil if the array is empty or if percentile is not in the range [0, 1].Sigma.percentile([35, 20, 50, 40, 15], percentile: 0.4)Returns the kurtosis of a series of numbers.
nil if the dataset has less than 4 values or if all values are identical.KURT in Excel/Google Sheets.Sigma.kurtosisA([2, 1, 3, 4.1, 19, 1.5])nil if the dataset has less than 2 values or if all values are identical.Sigma.kurtosisB([2, 1, 3, 4.1, 19, 1.5])A collection of nine functions that calculate sample quantiles corresponding to a given probability. These implement the nine algorithms described in the Hyndman and Fan (1996) paper.
Note:
nil if the dataset is empty or probability is outside [0, 1].Sigma.quantiles.method1: Inverse of the empirical distribution function.Sigma.quantiles.method2: Inverted empirical distribution function with averaging.Sigma.quantiles.method3: Standard quantile method.Sigma.quantiles.method4: Linear interpolation of the empirical distribution function.Sigma.quantiles.method5: Piecewise linear function using mid-step knots.Sigma.quantiles.method6: Used in Excel (PERCENTILE.EXC), Minitab, and SPSS.Sigma.quantiles.method7: Used in S, Excel (PERCENTILE/PERCENTILE.INC), and Google Sheets.Sigma.quantiles.method8: Approximately median-unbiased.Sigma.quantiles.method9: Approximately unbiased for normally distributed data.Sigma.quantiles.method1([1, 12, 19.5, -5, 3, 8], probability: 0.5)Simple utility functions for array manipulation.
Sigma.sum(array): Computes the sum of values.Sigma.max(array): Returns the maximum value (returns nil if empty).Sigma.min(array): Returns the minimum value (returns nil if empty).Sigma.uniqueValues(array): Returns an unsorted array of unique values without duplicates.Sigma.sum([1, 3, 8])
Sigma.max([1, 8, 3])
Sigma.min([7, 2, 3])
Sigma.uniqueValues([2, 1, 3, 4, 5, 4, 3, 5])