SSCrosstab

public struct SSCrosstab<N, R, C, FPT> : Codable where N : Comparable, N : Decodable, N : Encodable, N : Hashable, R : Comparable, R : Decodable, R : Encodable, R : Hashable, C : Comparable, C : Decodable, C : Encodable, C : Hashable, FPT : Decodable, FPT : Encodable, FPT : SSFloatingPoint

Struct provides a matrix-like crosstable. Elements are accessible by c[row, column].

Precondition

Rows and columns must be named. Row- and column- names are defined as generics. The content of one cell is generic too.
  • Number of rows

    Declaration

    Swift

    public var rowCount: Int { get }
  • Number of columns

    Declaration

    Swift

    public var columnCount: Int { get }
  • Returns the first row

    Declaration

    Swift

    public var firstRow: Array<N> { get }
  • Returns the last row

    Declaration

    Swift

    public var lastRow: Array<N> { get }
  • Returns the first column

    Declaration

    Swift

    public var firstColumn: Array<N> { get }
  • Returns the last column

    Declaration

    Swift

    public var lastColumn: Array<N> { get }
  • Returns the row-names or nil

    Declaration

    Swift

    public var rowNames: Array<R>? { get }
  • Returns the column-names or nil

    Declaration

    Swift

    public var columnNames: Array<C>? { get }
  • Defines the level od measurement of the column variable

    Declaration

    Swift

    public var columnLevelOfMeasurement: SSLevelOfMeasurement { get set }
  • Defines the level of measurement of the row variable

    Declaration

    Swift

    public var rowLevelOfMeasurement: SSLevelOfMeasurement { get set }
  • Undocumented

    Declaration

    Swift

    public var isNumeric: Bool
  • Encodes the instance to an encoder

    Declaration

    Swift

    public func encode(to encoder: Encoder) throws
  • Decodes from a decoder

    Declaration

    Swift

    public init(from decoder: Decoder) throws
  • Returns true if rows = 2 and columns = 2

    Declaration

    Swift

    public var is2x2Table: Bool { get }
  • Returns true if the table is empty

    Declaration

    Swift

    public var isEmpty: Bool { get }
  • Returns true if row-count == column-count

    Declaration

    Swift

    public var isSquare: Bool { get }

Validity checking

  • Returns the row at rowIndex

    Throws

    An error of type SSSwiftyStatsError

    Declaration

    Swift

    public func row(at idx: Int, sorted: Bool! = false) throws -> Array<N>
  • Returns the column at columnIndex

    Throws

    An error of type SSSwiftyStatsError

    Declaration

    Swift

    public func column(at idx: Int, sorted: Bool! = false) throws -> Array<N>
  • Returns the row with name rowName or nil

    Throws

    An error of type SSSwiftyStatsError

    Declaration

    Swift

    public func rowNamed(_ rowName: R, sorted: Bool! = false) throws -> Array<N>?
  • Returns the column with name columnName or nil

    Throws

    An error of type SSSwiftyStatsError

    Declaration

    Swift

    public func columnNamed(_ columnName: C, sorted: Bool = false) throws -> Array<N>?
  • Appends a row

    Throws

    An error of type SSSwiftyStatsError

    Declaration

    Swift

    public mutating func appendRow(_ row: Array<N>, name: R?) throws
  • Appends a column

    Throws

    An error of type SSSwiftyStatsError

    Declaration

    Swift

    public mutating func appendColumn(_ column: Array<N>, name: C?) throws
  • Removes the row with name

    Throws

    An error of type SSSwiftyStatsError

    Declaration

    Swift

    public mutating func removeRow(rowName name: R) throws -> Array<N>
  • Removes the column with name

    Throws

    An error of type SSSwiftyStatsError

    Declaration

    Swift

    public mutating func removeColumn(columnName name: C) throws -> Array<N>
  • Remove row at index

    Declaration

    Swift

    public mutating func removeRow(at index: Int) -> Array<N>
  • Remove column at index

    Declaration

    Swift

    public mutating func removeColumn(at idx: Int) -> Array<N>
  • Sets a row at a given index

    Throws

    An error of type SSSwiftyStatsError

    Declaration

    Swift

    public mutating func setRow(at idx: Int, newRow: Array<N>) throws
  • Sets a row at a given index

    Throws

    An error of type SSSwiftyStatsError

    Declaration

    Swift

    public mutating func setRow(name: R, newRow: Array<N>) throws
  • Sets a column at a given index

    Throws

    An error of type SSSwiftyStatsError

    Declaration

    Swift

    public mutating func setColumn(name: C, newColumn: Array<N>) throws
  • Sets a column at a given index

    Throws

    An error of type SSSwiftyStatsError

    Declaration

    Swift

    public mutating func setColumn(at idx: Int, newColumn: Array<N>) throws
  • Inserts a row at index at

    Throws

    An error of type SSSwiftyStatsError

    Declaration

    Swift

    public mutating func insertRow(newRow: Array<N>, at idx: Int, name: R?) throws
  • Inserts a column at index at

    Throws

    An error of type SSSwiftyStatsError

    Declaration

    Swift

    public mutating func insertColumn(newColumn: Array<N>, at idx: Int, name: C?) throws
  • Replaces the row at a given index

    Throws

    An error of type SSSwiftyStatsError

    Declaration

    Swift

    public mutating func replaceRow(newRow: Array<N>, at idx: Int, name: R?) throws
  • Replaces the column at a given index

    Throws

    An error of type SSSwiftyStatsError

    Declaration

    Swift

    public mutating func replaceColumn(newColumn: Array<N>, at idx: Int, name: C?) throws
  • Sets the rows names. Length of rowNames must be equal to self.rows

    Throws

    An error of type SSSwiftyStatsError

    Declaration

    Swift

    public mutating func setRowNames(rowNames: Array<R>) throws
  • Sets the column names. Length of columnNames must be equal to self.columns

    Throws

    An error of type SSSwiftyStatsError

    Declaration

    Swift

    public mutating func setColumnNames(columnNames: Array<C>) throws
  • Description string

    Declaration

    Swift

    public var description: String { get }
  • Returns the row sums as an array with self.rowCount values

    Declaration

    Swift

    public var rowSums: Array<FPT>? { get }
  • Returns the column sums as an array with self.columnCount values

    Declaration

    Swift

    public var columnSums: Array<FPT>? { get }
  • Returns the sum of a row

    Declaration

    Swift

    public func rowSum(row: Int) -> FPT
  • Sum of row named rowName

    Declaration

    Swift

    public func rowSum(rowName: R) -> FPT
  • The sum of a column

    Declaration

    Swift

    public func columnSum(column: Int) -> FPT
  • Sum of column named columnName

    Declaration

    Swift

    public func columnSum(columnName: C) throws -> FPT
  • Returns the name of the column or nil if there is no name

    Declaration

    Swift

    public func nameOfColumn(column: Int) -> C?
  • Returns the name of the row or nil if there is no name

    Declaration

    Swift

    public func nameOfRow(row: Int) -> R?
  • Returns the index of the column with name columnName or nil if there is no column with that name.

    Declaration

    Swift

    public func firstIndexOfColumn(columnName: C) -> Int?
  • Returns the index of the row with name rowName or nil if there is no row with that name.

    Declaration

    Swift

    public func firstIndexOfRow(rowName: R) -> Int?
  • Returns the total

    Declaration

    Swift

    public var total: FPT { get }
  • Returns the sum of all rows

    Declaration

    Swift

    public func rowTotal() -> FPT
  • Returns the sum of all columns

    Declaration

    Swift

    public func colummTotal() -> FPT
  • Returns the largets row total

    Throws

    SSSwiftyStatsError.missingData if there are no data

    Declaration

    Swift

    public func largestRowTotal() throws -> FPT

    Return Value

    FPT Type or FPT.nan

  • Returns the largest cell count for column

    Declaration

    Swift

    public func largestCellCount(atColumn: Int) -> FPT
  • Returns the largest cell count for row

    Declaration

    Swift

    public func largestCellCount(atRow: Int) -> FPT
  • Returns the relative total frequency of a cell at [row, column]

    Declaration

    Swift

    public func relativeTotalFrequency(row: Int, column: Int) -> FPT
  • Returns the relative frequency of [rowName, columnName]

    Declaration

    Swift

    public func relativeTotalFrequency(rowName: R, columnName: C) throws -> FPT
  • Returns the relative row frequency of cell[row, column]

    Declaration

    Swift

    public func relativeRowFrequency(row: Int, column: Int) -> FPT
  • Returns the relative column frequency of cell[row, column]

    Declaration

    Swift

    public func relativeColumnFrequency(row: Int, column: Int) -> FPT
  • Returns the relative margin row frequency of [row]

    Declaration

    Swift

    public func relativeRowMarginFrequency(row: Int) -> FPT
  • Returns the relative margin row frequency of [row]

    Declaration

    Swift

    public func relativeColumnMarginFrequency(column: Int) -> FPT
  • Returns the expected frequency for cell[row, column]

    Declaration

    Swift

    public func expectedFrequency(row: Int, column: Int) -> FPT
  • Returns the expected frequency for cell[rowName, columnName]

    Declaration

    Swift

    public func expectedFrequency(rowName: R, columnName: C) throws -> FPT
  • Returns the residual for cell[row, column]

    Declaration

    Swift

    public func residual(row: Int, column: Int) -> FPT
  • Returns the standardized residual for cell[row, column]

    Declaration

    Swift

    public func standardizedResidual(row: Int, column: Int) -> FPT
  • Returns the adjusted residual for cell[row, column]

    Declaration

    Swift

    public func adjustedResidual(row: Int, column: Int) -> FPT
  • Degrees of freedom

    Declaration

    Swift

    public var degreesOfFreedom: FPT { get }
  • Returns Pearson’s Chi-Square

    Precondition

    Measurements must be at least nominally scaled

    Declaration

    Swift

    public var chiSquare: FPT { get }
  • Returns the Chi-Square Likelihood Ratio

    Precondition

    at least nominally scaled measurements

    Declaration

    Swift

    public var chiSquareLikelihoodRatio: FPT { get }
  • Returns the Yates continuity corrected Chi-Square for a 2 x 2 table

    Precondition

    at least nominally scaled measurements

    Declaration

    Swift

    public var chiSquareYates: FPT { get }
  • Returns the covariance

    Precondition

    at least interval-scaled measurements

    Declaration

    Swift

    public var covariance: FPT { get }
  • Returns the product moment correlation r (Pearson’s r)

    Precondition

    At least interval-scaled measurements

    Declaration

    Swift

    public var pearsonR: FPT { get }
  • Returns the Mantel-Haenszel Chi-Square

    Declaration

    Swift

    public var chiSquareMH: FPT { get }
  • phi

    Returns Phi

    Declaration

    Swift

    public var phi: FPT { get }
  • Returns the coefficient of contingency

    Declaration

    Swift

    public var ccont: FPT { get }
  • Returns the coefficient of contingency

    Declaration

    Swift

    public var coefficientOfContingency: FPT { get }
  • Returns Cramer’s V

    Declaration

    Swift

    public var cramerV: FPT { get }
  • Returns “Column|Row -Lambda”

    Declaration

    Swift

    public func lambda_C_R() throws -> FPT
  • Returns the “Row|Column”-Lambda

    Declaration

    Swift

    public func lambda_R_C() throws -> FPT
  • r0

    Returns the Odds Ratio

    • Preconditions: Only applicable to a 2x2 table

    Declaration

    Swift

    public var r0: FPT { get }
  • r1

    Returns the relative risk in a cohort study for column 1

    Precondition

    Only applicable to a 2x2 table

    Declaration

    Swift

    public var r1: FPT { get }