Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ To install StatKit using the [Swift Package Manager](https://swift.org/package-m
let package = Package(
...
dependencies: [
.package(url: "https://github.com/JimmyMAndersson/StatKit.git", from: "0.6.0")
.package(url: "https://github.com/JimmyMAndersson/StatKit.git", from: "0.8.0")
],
...
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public extension Collection {
///
/// Since there is no notion of correlation in collections with less than two elements,
/// this method returns NaN if the array count is less than two.
/// The time complexity of this method is O(n).
@inlinable
func pearsonR<T, U>(
of X: KeyPath<Element, T>,
Expand Down Expand Up @@ -52,7 +51,6 @@ public extension Collection {
/// Since there is no notion of correlation in collections with less than two
/// elements or when one of the variables are constant,
/// this method returns NaN if the array count is less than two.
/// The time complexity of this method is O(n).
@inlinable
func spearmanR<T, U>(
of X: KeyPath<Element, T>,
Expand Down Expand Up @@ -119,7 +117,6 @@ public extension Collection {
///
/// Since there is no notion of correlation in collections with less than two elements,
/// this method returns NaN if the array count is less than two.
/// The time complexity of this method is O(n).
func kendallTau<T, U>(
of X: KeyPath<Element, T>,
and Y: KeyPath<Element, U>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ public extension Collection {
/// - returns: The mean of all items.
///
/// Since the arithmetic mean has no meaning on an empty set, this method returns a NaN if the collection is empty.
/// The time complexity of this method is O(n).
@inlinable
func mean<T: ConvertibleToReal>(
variable: KeyPath<Element, T>,
Expand All @@ -24,8 +23,6 @@ public extension Collection {
///
/// - important: This method has undefined behavior on collections containing elements that are incomparable.
/// For example, an array containing NaN's will produce unpredictable results.
///
/// - complexity: O(n log n), where n is the length of the collection.
@inlinable
func median<T: Comparable & ConvertibleToReal>(
variable: KeyPath<Element, T>,
Expand All @@ -49,8 +46,6 @@ public extension Collection {
///
/// - important: This method has undefined behavior on collections containing elements that are incomparable.
/// For example, an array containing NaN's will produce unpredictable results.
///
/// - complexity: O(n), where n is the length of the collection.
@inlinable
func mode<T: Hashable>(
variable: KeyPath<Element, T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ extension MeanStrategy {
/// - parameter variable: The random variable for which to calculate the mean.
/// - parameter collection: The collection of values.
/// - returns: The specified mean value.
/// The time complexity of this method is O(n).
@usableFromInline
internal func compute<C: Collection, T: ConvertibleToReal>(
for variable: KeyPath<C.Element, T>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ extension MedianStrategy {
/// - parameter variable: The random variable for which to calculate the mean.
/// - parameter collection: The collection of values.
/// - returns: The specified mean value.
///
/// - complexity: O(n log n), where n is the length of the collection.
@usableFromInline
internal func compute<T, C>(
for variable: KeyPath<C.Element, T>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ public extension Collection {
/// - returns: The range of the selected variable.
///
/// The range is the difference between the lowest and highest number in a collection.
/// The time complexity of this method is O(n).
func range<T: Comparable & ConvertibleToReal>(
of variable: KeyPath<Element, T>
) -> Double {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ public extension Collection {
/// - parameter variable: The variable over which to calculate the variance.
/// - parameter composition: The composition of the collection.
/// - returns: The variance of the collection.
///
/// The time complexity of this method is O(n).
@inlinable
func variance<T: ConvertibleToReal>(
variable: KeyPath<Element, T>,
Expand Down Expand Up @@ -39,8 +37,6 @@ public extension Collection {
/// - parameter variable: The variable over which to calculate the standard deviation.
/// - parameter composition: The composition of the collection.
/// - returns: The standard deviation of the collection, rounded to a representable value.
///
/// The time complexity of this method is O(n).
@inlinable
func standardDeviation<T: ConvertibleToReal>(
variable: KeyPath<Element, T>,
Expand All @@ -57,7 +53,6 @@ public extension Collection {
///
/// Since there is no notion of covariance in collections with less than two elements,
/// this method returns NaN if the array count is less than two.
/// The time complexity of this method is O(n).
@inlinable
func covariance<T, U>(
of X: KeyPath<Element, T>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public struct GammaDistribution: ContinuousDistribution, UnivariateDistribution
/// Creates a Gamma Distribution with a specified alpha and beta parameters.
/// - parameter alpha: The distribution alpha parameter.
/// - parameter beta: The distribution beta parameter.
///
/// - important: This initializer is deprecated. Use ``init(shape:scale:)`` or ``init(shape:rate:)`` instead.
@available(*, deprecated, renamed: "init(shape:scale:)")
public init(alpha: Double, beta: Double) {
precondition(0 < alpha, "The shape parameter needs to be greater than 0.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public struct NormalDistribution: ContinuousDistribution, UnivariateDistribution
self.variance = variance
}

/// Create a Normal Distribution with a specified mean and standard deviation.
/// - parameter mean: The mean value of this distribution.
/// - parameter standardDeviation: The standard deviation for this distribution.
public init(mean: Double, standardDeviation: Double) {
precondition(
0 < standardDeviation,
Expand Down
2 changes: 0 additions & 2 deletions Sources/StatKit/Descriptive Statistics/Ranking/Ranking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ public extension Collection {
/// - important: This method triggers a precondition failure if attempting to rank a collection
/// of instances that do not compare equal to themselves. For example, attempting to rank a collection
/// of floating point numbers that contain NaN's will fail, since `Double.nan == Double.nan` is false.
///
/// The time complexity of this method is O(n).
func rank<T: Comparable & Hashable>(
variable: KeyPath<Element, T>,
by order: @escaping (_ lhs: T, _ rhs: T) -> Bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,31 @@ protocol RankingStrategyProtocol {

/// A calculation strategy for ranking comparable variables.
public enum RankingStrategy: CaseIterable, Sendable {
/// The Fractional ranking strategy.
/// Tied elements receive the average of the ranks they would otherwise occupy.
///
/// For example, two elements tied for 2nd place both receive rank 2.5, and the next element receives rank 4.
case fractional
/// The Standard Competition ranking strategy.

/// Tied elements share the lowest rank in their group, and the next rank skips over the tie count.
///
/// For example, two elements tied for 2nd place both receive rank 2, and the next element receives rank 4.
case standardCompetition
/// The Modified Competition ranking strategy.

/// Tied elements share the highest rank in their group.
///
/// For example, two elements tied for 2nd place both receive rank 3, and the next element receives rank 4.
case modifiedCompetition
/// The Ordinal ranking strategy.

/// Tied elements are assigned consecutive ranks based on their order in the collection, with no averaging.
///
/// For example, two elements tied for 2nd place receive ranks 2 and 3 respectively,
/// and the next element receives rank 4.
case ordinal
/// The Dense ranking strategy.

/// Tied elements share the same rank, and the next distinct rank is always incremented by one
/// regardless of tie count.
///
/// For example, two elements tied for 2nd place both receive rank 2, and the next element receives rank 3.
case dense

/// A calculator object that can be used to compute the specified rank.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ public extension Collection {
/// Calculates the sum of all contained elements.
/// - parameter variable: The variable over which to calculate the sum.
/// - returns: The sum of the variable in the collection.
///
/// - complexity: O(n), where n is the length of the collection.
@inlinable
func sum<T: AdditiveArithmetic>(
over variable: KeyPath<Element, T>
Expand Down
14 changes: 0 additions & 14 deletions Sources/StatKit/StatKit.docc/Combinatorial Extensions.md

This file was deleted.

7 changes: 2 additions & 5 deletions Sources/StatKit/StatKit.docc/Distributions.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,12 @@ These types define common distributions used to make theoretical calculations or
- ``ExponentialDistribution``
- ``LogisticDistribution``
- ``LogLogisticDistribution``
- ``FiskDistribution``
- ``NormalDistribution``
- ``BetaDistribution``
- ``GammaDistribution``
- ``ChiSquaredDistribution``
- ``ErlangDistribution``

### Discrete Multivariate Distributions


### Continuous Multivariate Distributions
### Type Aliases

- ``FiskDistribution``
24 changes: 24 additions & 0 deletions Sources/StatKit/StatKit.docc/Mathematical Functions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Mathematical Functions

Compute special mathematical functions used in probability and statistics.

## Overview

StatKit exposes a set of special mathematical functions that are commonly used in probability theory and statistics.

## Topics

### Binomial Coefficients

- ``choose(n:k:)``

### Beta Functions

- ``beta(alpha:beta:logarithmic:)``
- ``regularizedIncompleteBeta(x:alpha:beta:)``

### Gamma Functions

- ``incompleteGamma(lower:upper:alpha:logarithmic:)``
- ``incompleteGamma(lower:upper:alpha:)``
- ``regularizedIncompleteGamma(lower:upper:alpha:logarithmic:)``
2 changes: 1 addition & 1 deletion Sources/StatKit/StatKit.docc/Ranking.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Put rankings on data points such that, for any two items, they are either ranked

## Overview

There are several ways of ranking items. The most common ones are implemented as a `RankingStrategy`, allowing for immediate use.
There are several ways of ranking items. The most common ones are implemented as a `RankingStrategy`, allowing for immediate use. The strategies differ in how they handle tied observations, so choose the one that matches the convention expected by your analysis.

## Topics

Expand Down
7 changes: 2 additions & 5 deletions Sources/StatKit/StatKit.docc/StatKit.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@ StatKit provides Swift developers with tools to describe data sets and make pred

### Descriptive Statistics

- <doc:Centeral-Tendency>
- <doc:Central-Tendency>
- <doc:Association>
- <doc:Dispersion>
- <doc:Ranking>
- <doc:Summation>
- <doc:Partitioning>
- <doc:Distributions>
- <doc:Combinatorial-Extensions>

### Inferential Statistics

- <doc:Mathematical-Functions>

### Module Specific Protocols
- ``ConvertibleToReal``
8 changes: 3 additions & 5 deletions Sources/StatKit/StatKit.docc/Summation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

Sum over variables in a data set.

@Comment {
## Overview

Maybe we don't need an overview for this?
}
## Overview

Summation is a fundamental building block in statistical computation, underpinning everything from means to more complex aggregations.

## Topics

Expand Down
Loading