it.grypho.scala.leonardo.statistics

Members list

Type members

Classlikes

The two-sample statistics.

The two-sample statistics.

Attributes

Companion
object
Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object PairStatKind

Attributes

Companion
enum
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
enum StatKind

The single-sample statistics.

The single-sample statistics.

Attributes

Companion
object
Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object StatKind

Attributes

Companion
enum
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
StatKind.type
enum TestKind

The inference tests.

The inference tests.

Attributes

Companion
object
Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object TestKind

Attributes

Companion
enum
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
TestKind.type
case class _PairStatistic(kind: PairStatKind, a: _Expression, b: _Expression) extends _Expression

A statistic of two equally long samples.

A statistic of two equally long samples.

Value parameters

a

the first sample

b

the second

kind

the statistic

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait _Expression
class Object
trait Matchable
class Any
Show all
case class _Regress(x: _Expression, y: _Expression) extends _Expression

Ordinary least squares: regress(X, y).

Ordinary least squares: regress(X, y).

Returns the p × 1 coefficient vector. No intercept column is added: a constant term is a column of ones the caller supplies, because a silently inserted column would make regress compute something other than what was written, with no way to opt out.

Value parameters

x

the design matrix

y

the response vector

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait _Expression
class Object
trait Matchable
class Any
Show all
case class _Statistic(kind: StatKind, arg: _Expression) extends _Expression

A statistic of one argument, which may be a sample or a distribution.

A statistic of one argument, which may be a sample or a distribution.

Dispatching on the argument is what lets mean and variance mean one thing each. A distribution delegates to probability, which owns its own moments; a matrix is treated as a sample. This is why statistics imports probability and not the reverse.

Note the n/n − 1 distinction that follows from the dispatch: variance(sample) is the unbiased estimator, while variance(distribution) is the population variance, because a distribution is not a sample and has no n to correct for. See the package overview.

Value parameters

arg

the sample or distribution

kind

the statistic

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait _Expression
class Object
trait Matchable
class Any
Show all
case class _Test(kind: TestKind, a: _Expression, b: _Expression) extends _Expression

An inference test.

An inference test.

Thin wrappers: the work was in the incomplete beta and gamma kernels and in the distribution carrier, both of which already existed. What this adds is the test statistics themselves and the routing.

Value parameters

a

the sample (or observed counts)

b

the null mean, the confidence level, or the expected counts

kind

the test

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait _Expression
class Object
trait Matchable
class Any
Show all

Value members

Concrete methods

def fitted(x: _MatrixValue, beta: _MatrixValue): Option[_MatrixValue]

The fitted values X·β.

The fitted values X·β.

Value parameters

beta

the coefficients

x

the design matrix

Attributes

Fits y ≈ X·β by ordinary least squares.

Fits y ≈ X·β by ordinary least squares.

No intercept is added. A constant term is a column of ones in X, which the caller supplies — silently inserting one would make regress mean something different from what was written, and there is no way to opt out of a hidden column.

Value parameters

x

the design matrix, n × p, with n ≥ p

y

the response, n × 1 or 1 × n

Attributes

Returns

the p × 1 coefficient vector, or None when the shapes do not conform or the design is rank-deficient (qrDecompose refuses it, so nonsense is not produced)

def residualSumOfSquares(x: _MatrixValue, y: _MatrixValue, beta: _MatrixValue): Option[Double]

The residual sum of squares of a fit, which the inference tier needs.

The residual sum of squares of a fit, which the inference tier needs.

Value parameters

beta

the coefficients

x

the design matrix

y

the response, n × 1

Attributes

def sampleCorrelation(xs: Vector[_Value], ys: Vector[_Value], env: Environment): Option[_Value]

The Pearson correlation coefficient.

The Pearson correlation coefficient.

Scale-invariant, so the n − 1 cancels between the covariance and the two standard deviations — this is the one statistic here for which the population/sample choice makes no difference at all.

Value parameters

env

supplies the working precision

xs

the first sample

ys

the second, which must be the same length

Attributes

Returns

the correlation in [-1, 1], or None if either sample is constant

def sampleCovariance(xs: Vector[_Value], ys: Vector[_Value], env: Environment): Option[_Value]

The covariance of two equally long samples, dividing by n − 1.

The covariance of two equally long samples, dividing by n − 1.

Value parameters

env

supplies the reduction policy

xs

the first sample

ys

the second, which must be the same length

Attributes

Returns

the covariance — exact when both samples are

def sampleMean(xs: Vector[_Value], env: Environment): Option[_Value]

The arithmetic mean.

The arithmetic mean.

Value parameters

env

supplies the reduction policy for the exact path

xs

the sample, which must be non-empty

Attributes

Returns

the mean — exact when the sample is

def sampleOf(r: Either[_Expression, _Value]): Option[Vector[_Value]]

Reads an evaluated expression as a sample: every entry of a matrix, row-major.

Reads an evaluated expression as a sample: every entry of a matrix, row-major.

Accepts both carriers, which matters for exact input: an exactly-written matrix stays a symbolic _Matrix rather than collapsing to the dense one, and that is precisely the case where an exact statistic is worth having.

Value parameters

r

the evaluated argument

Attributes

Returns

the entries, or None when the argument is not a matrix of values

def sampleStdDev(xs: Vector[_Value], ddof: Int, env: Environment): Option[_Value]

The standard deviation — the square root of sampleVariance.

The standard deviation — the square root of sampleVariance.

A square root is not closed over the rationals, so an exact sample gives an exact variance but only a working-precision standard deviation. That is the same contract every irrational result in the library carries, and it goes through the same kernel.

Value parameters

ddof

1 for the sample standard deviation, 0 for the population one

env

supplies the working precision

xs

the sample

Attributes

def sampleVariance(xs: Vector[_Value], ddof: Int, env: Environment): Option[_Value]

The variance, dividing by n − ddof.

The variance, dividing by n − ddof.

Two-pass, deliberately. The textbook one-pass form E[X²] − E[X]² subtracts two nearly equal quantities whenever the sample has a large mean relative to its spread, and loses most of its significant digits doing so — the same catastrophic cancellation that already cost this project the quadratic formula's small root. Computing the mean first and then summing squared deviations has no such subtraction in it.

Value parameters

ddof

1 for the unbiased sample variance, 0 for the population variance

env

supplies the reduction policy for the exact path

xs

the sample

Attributes

Returns

the variance — exact when the sample is