SigmaSwiftStatistics

repository·master·Indexed 20 days ago

https://github.com/evgenyneu/sigmaswiftstatistics

A 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).

Tokens
2.5K
Snippets
13
Records
21
Agent score
22%

What's inside SigmaSwiftStatistics

  1. Setup with Swift Package Manager

    master

    To install SigmaSwiftStatistics using Swift Package Manager in Xcode 11 or later:

    1. In Xcode, select File > Packages > Add Package Dependency....
    2. Enter the following URL: https://github.com/evgenyneu/SigmaSwiftStatistics.git
    https://github.com/evgenyneu/SigmaSwiftStatistics.git
  2. Install SigmaSwiftStatistics

    master

    You can integrate the SigmaSwiftStatistics library into your project using one of the following four methods:

    1. Add Source (iOS 7+): Manually add the SigmaDistrib.swift file to your project.
    2. Carthage (iOS 8+): Add the dependency to your Cartfile and run carthage update.
    3. CocoaPods (iOS 8+): Add the pod to your Podfile and run pod install.
    4. Swift Package Manager (Xcode 11+): Add the repository URL via the Xcode Package Manager interface.
    # Carthage
    github "evgenyneu/SigmaSwiftStatistics" ~> 9.0
    
    # CocoaPods
    use_frameworks!
    target 'Your target name' do
      pod 'SigmaSwiftStatistics', '~> 9.0'
    end
  3. Calculate Pearson Correlation Coefficient

    master

    Calculates the Pearson product-moment correlation coefficient between two variables x and y.

    Note:

    • Returns nil if arrays have different lengths or are empty.
    • Equivalent to 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)
  4. Calculate Variance (Population and Sample)

    master

    Computes the variance of a dataset.

    Variance of a Population

    • Returns nil if the array is empty.
    • Equivalent to VAR.P or VARPA in Excel.
    Sigma.variancePopulation([1, 12, 19.5, -5, 3, 8])

    Variance of a Sample

    • Returns nil if the array is empty or contains a single value.
    • Equivalent to VAR or VAR.S in Excel.
    Sigma.varianceSample([1, 12, 19.5, -5, 3, 8])
  5. Calculate Skewness (A and B)

    master

    Returns the skewness of the dataset.

    Skewness A

    • Returns nil if the dataset has less than 3 values or if all values are identical.
    • Equivalent to SKEW in Excel/Google Sheets.
    Sigma.skewnessA([4, 2.1, 8, 21, 1])

    Skewness B

    • Returns nil if the dataset has less than 3 values or if all values are identical.
    • Equivalent to SKEW.P in Excel and the "moments" R package.
    Sigma.skewnessB([4, 2.1, 8, 21, 1])
  6. Calculate Kurtosis (A and B)

    master

    Returns the kurtosis of a series of numbers.

    Kurtosis A

    • Returns nil if the dataset has less than 4 values or if all values are identical.
    • Equivalent to KURT in Excel/Google Sheets.
    Sigma.kurtosisA([2, 1, 3, 4.1, 19, 1.5])

    Kurtosis B

    • Returns nil if the dataset has less than 2 values or if all values are identical.
    • Equivalent to Wolfram Alpha and the "moments" R package.
    Sigma.kurtosisB([2, 1, 3, 4.1, 19, 1.5])
  7. Calculate Quantiles (Methods 1-9)

    master

    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:

    • Returns nil if the dataset is empty or probability is outside [0, 1].

    Available Methods

    • 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)
  8. Basic Array Operations (Sum, Max, Min, Unique)

    master

    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])