Statistics
Collection of low-level, pure-julia, efficient functions for computing statistics and data transformations.
These functions are heavely used internally by the package. You do not need them to carry out permutation tests, however they are exported because they may turn useful. For general usage of this package you can skip this page altogheter.
Scalars functions of vectors (statistics)
| Function | descriptiion | expression |
|---|---|---|
∑(x) | sum | $\sum_{i=1}^{N}x_i$ |
∑of²(x) | sum of squares | $\sum_{i=1}^{N}x_i^2$ |
∑∑of²(x) | sum and sum of squares | $\sum_{i=1}^{N}x_i$ and $\sum_{i=1}^{N}x_i^2$ in one pass |
μ(x) | mean | $\frac{1}{N} \sum_{i=1}^{N}x_i$ |
dispersion(x) | sum of squared deviations | $\sum_{i=1}^{N}(x_i- \mu (x))^2$ |
σ²(x) | variance | $\frac{1}{N} \sum_{i=1}^{N}(x_i- \mu (x))^2$ |
σ(x) | standard deviation | $\sqrt{\sigma^2(x)}$ |
∑(x, y) | sum of (x + y) | $\sum_{i=1}^{N}(x_i+y_i)$ |
Π(c) | product | $\prod_{i=1}^{N}x_i$ |
∑ofΠ(x, y) | inner product of two vectors | $x \cdot y = \sum_{i=1}^{N}(x_i \cdot y_i)$ |
Vector functions of vectors (data transformations)
| Function | descriptiion |
|---|---|
μ0(x) | recenter (zero mean): $x_i \gets x_i- \mu (x), \forall i=1 \dots N$ |
σ1(x) | equalize (unit standard deviation): $x_i \gets \frac{x_i}{\sigma (x)}, \forall i=1 \dots N$ |
μ0σ1(x) | standardize (zero mean and unit standard deviation): $x_i \gets \frac{x_i- \mu (x)}{\sigma (x)}, \forall i=1 \dots N$ |
PermutationTests.∑ — Function
function (x::UniData)Alias for julia sum(x). Sum of the elements in x.
PermutationTests.∑of² — Function
function ∑of²(x::UniData)Sum of squares of the elements in x
PermutationTests.∑∑of² — Function
function ∑∑of²(x::UniData)Compute the sum and sum of squares of the elements in x in one pass and return them as a 2-tuple.
Examples
using PermutationTests
x=randn(10)
s, s² = ∑∑of²(x)PermutationTests.μ — Function
function μ(x::UniData) Alias for julia mean(x). Arithmetic mean of the elements in x.
PermutationTests.dispersion — Function
function dispersion(x::UniData, mean::Real)Sum of squared deviations of the elements in x around mean.
mean must be provided and must be a real number.
Examples
using PermutationTests
x=randn(10)
d=dispersion(x, μ(x))function dispersion(x::UniData;
centered::Bool=false, mean::Realo=nothing)If centered is true, return the sum of the squares of the elements in x,
otherwise,
if mean is provided return the sum of squared deviations of the elements in x from mean,
otherwise,
return the sum of squared deviations of the elements in x from their mean.
Examples
using PermutationTests
x=randn(10)
x0=μ0(x)
μx=μ(x)
m=μ(x)
# in decreasing order of efficiency
d1=dispersion(x0)
d2=dispersion(x, mean=μx)
d3=dispersion(x)
d1==d2==d3 # -> truePermutationTests.σ² — Function
function σ²(x::UniData;
corrected::Bool=false,
centered::Bool=false,
mean::Realo=nothing) Population variance of the $N$ elements in x (default), or its unbiased sample estimator if corrected is true.
If centered is true return the sum of the squared elements in x divided by $N$, or $N-1$ if corrected is true,
otherwise,
call julia standard function var with arguments corrected and mean.
PermutationTests.σ — Function
function σ(x::UniData;
corrected::Bool=false,
centered::Bool=false,
mean::Realo=nothing) Population standard deviation of the elements in x or its unbiased sample estimator.
Call σ² with the same arguments and return its square root.
PermutationTests.Π — Function
function Π(x::UniData)Product of the elements in x. Alias of julia function prod.
PermutationTests.∑ofΠ — Function
function ∑ofΠ(x::Union{UniData, Tuple}, y::UniData) Inner product of x and y.
PermutationTests.μ0 — Function
function μ0(x::UniData;
mean::Realo=nothing) Return x centered (zero mean).
Center around mean if it is provided. mean must be a real number.
PermutationTests.σ1 — Function
σ1(x::UniData;
corrected::Bool=false,
centered::Bool=false,
mean::Realo=nothing,
sd::Realo=nothing)Return x equalized (unit standard deviation).
If sd is provided, return x equalized with respect to it,
otherwise call σ with optional arguments corrected, centered and mean and equalize x.
Examples
using PermutationTests
x=randn(3)
μx=μ(x) # mean
σx=σ(x) # sd
xμ0=μ0(x) # centered data
# in decreasing order of efficiency
e1=σ1(xμ0; sd=σx, centered=true)
e2=σ1(xμ0; centered=true)
e3=σ1(x; mean=μx, sd=σx)
e4=σ1(x; mean=μx)
println(σ(e4)≈1.0 ? "OK" : "Error") # -> "OK"PermutationTests.μ0σ1 — Function
μ0σ1(x::UniData;
corrected::Bool=false,
centered::Bool=false,
mean::Realo=nothing,
sd::Realo=nothing)Return x standardized (zero mean and unit standard deviation).
If centered is true, equalize x by calling σ1 with optional arguents corrected, centered and sd,
otherwise standardize x after computing the mean, if it is not provided as mean, and the standard deviation, if it is not provided, calling σ[@ref] with optional arguments corrected and centered.
Examples
using PermutationTests
x=randn(3)
μx=μ(x) # mean
σx=σ(x) # sd
xμ0=μ0(x) # centered data
# in decreasing order of efficiency
z1=μ0σ1(xμ0; sd=σx, centered=true)
z2=μ0σ1(xμ0; centered=true)
z3=μ0σ1(x; mean=μx, sd=σx)
z4=μ0σ1(x; mean=μx)
z5=μ0σ1(x; sd=σx)
z6=μ0σ1(x)
println(μ(z6)≈0. ? "OK" : "Error") # -> "Ok"
println(σ(z6)≈1. ? "OK" : "Error") # -> 'OK"