# API

StandardizedPredictors.CenterType
struct Center

Represents a centering scheme, akin to StatsModels.AbstractContrasts. Pass as value in Dict as hints to schema (or as contrasts kwarg for fit).

Examples

Can specify center value to use:

julia> schema((x=collect(1:10), ), Dict(:x => Center(5)))
StatsModels.Schema with 1 entry:
x => center(x, 5)

You can use a function to compute the center value:

julia> schema((x=collect(1:10), ), Dict(:x => Center(median))) StatsModels.Schema with 1 entry: x => x(centered: 5.5)

Or center will be automatically computed if omitted:

julia> schema((x=collect(1:10), ), Dict(:x => Center()))
StatsModels.Schema with 1 entry:
x => center(x, 5.5)
source
StandardizedPredictors.CenteredTermType
struct CenteredTerm{T,C} <: AbstractTerm

A lazily centered term. A wrapper around an T<:AbstractTerm which will produce centered values with modelcols by subtracting center from each element generated by the wrapped term with modelcols.

Fields

• term::T: The wrapped term.
• center::C: The center value subtracted from the resulting modelcols.

Examples

Directly construct with given center:

julia> d = (x=collect(1:10), );

julia> t = concrete_term(term(:x), d)
x(continuous)

julia> tc = CenteredTerm(t, 5)
x(centered: 5)

julia> hcat(modelcols(t + tc, d)...)
10×2 Matrix{Int64}:
1  -4
2  -3
3  -2
4  -1
5   0
6   1
7   2
8   3
9   4
10   5

Construct with lazy centering via Center

julia> tc = concrete_term(term(:x), d, Center())
center(x, 5.5)

julia> hcat(modelcols(t + tc, d)...)
10×2 Matrix{Float64}:
1.0  -4.5
2.0  -3.5
3.0  -2.5
4.0  -1.5
5.0  -0.5
6.0   0.5
7.0   1.5
8.0   2.5
9.0   3.5
10.0   4.5

Or similarly via schema hints:

julia> sch = schema(d, Dict(:x => Center()))
StatsModels.Schema with 1 entry:
x => center(x, 5.5)
source
StandardizedPredictors.ScaleType
struct Scale

Represents a scaling scheme, akin to StatsModels.AbstractContrasts. Pass as value in Dict as hints to schema (or as contrasts kwarg for fit).

Examples

Can specify scale value to use:

julia> schema((x=collect(1:10), ), Dict(:x => Scale(5)))
StatsModels.Schema with 1 entry:
x => x(scaled: 5))

You can use a function to compute the scale value:

julia> schema((x=collect(1:10), ), Dict(:x => Scale(mad))) StatsModels.Schema with 1 entry: x => x(scaled: 3.71)

Or scale will be automatically computed if left out:

julia> schema((x=collect(1:10), ), Dict(:x => Scale()))
StatsModels.Schema with 1 entry:
x => x(scaled: 3.03)
source
StandardizedPredictors.ScaledTermType
struct ScaledTerm{T,S} <: AbstractTerm

A lazily scaled term. A wrapper around an T<:AbstractTerm which will produce scaled values with modelcols by dividing each element by scale.

Fields

• term::T: The wrapped term.
• scale::S: The scale value which the resulting modelcols are divided by.

Examples

Directly construct with given scale:

julia> d = (x=collect(1:10), );

julia> t = concrete_term(term(:x), d)
x(continuous)

julia> ts = ScaledTerm(t, 5)
x(scaled: 5)

julia> hcat(modelcols(t + ts, d)...)
10×2 Matrix{Float64}:
1.0  0.2
2.0  0.4
3.0  0.6
4.0  0.8
5.0  1.0
6.0  1.2
7.0  1.4
8.0  1.6
9.0  1.8
10.0  2.0

Construct with lazy scaling via Scale

julia> ts = concrete_term(term(:x), d, Scale())
x(scaled: 3.03)

julia> hcat(modelcols(t + ts, d)...)
10×2 Matrix{Float64}:
1.0  0.330289
2.0  0.660578
3.0  0.990867
4.0  1.32116
5.0  1.65145
6.0  1.98173
7.0  2.31202
8.0  2.64231
9.0  2.9726
10.0  3.30289

Or similarly via schema hints:

julia> sch = schema(d, Dict(:x => Scale()))
StatsModels.Schema with 1 entry:
x => scale(x, 3.03)
source
StandardizedPredictors.ZScoreType
struct ZScore

Represents a z-scoring scheme, akin to StatsModels.AbstractContrasts. Pass as value in Dict as hints to schema (or as contrasts kwarg for fit).

Examples

Can specify the center and scale values to use:

julia> schema((x=collect(1:10), ), Dict(:x => ZScore(; center=5, scale=3)))
StatsModels.Schema with 1 entry:
x => x(centered: 5 scaled: 3)

Or scale will be automatically computed if left out:

julia> schema((x=collect(1:10), ), Dict(:x => ZScore()))
StatsModels.Schema with 1 entry:
x => x(centered: 5.5 scaled: 3.03)
source
StandardizedPredictors.ZScoredTermType
struct ZScoredTerm{T,C,S} <: AbstractTerm

A lazily z-scored term. A wrapper around an T<:AbstractTerm which will produce scaled values with modelcols by subtracting center from each element and then dividing by scale.

Fields

• term::T: The wrapped term.
• center::C: The center value which is subtracted from the resulting modelcols.
• scale::S: The scale value which the resulting modelcols are divided by.

Examples

Directly construct with given scale:

julia> d = (x=collect(1:10), );

julia> t = concrete_term(term(:x), d)
x(continuous)

julia> ts = ZScoredTerm(t, 3, 5)
x(centered: 3 scaled: 5)

julia> hcat(modelcols(t + ts, d)...)
10×2 Matrix{Float64}:
1.0  -0.4
2.0  -0.2
3.0   0.0
4.0   0.2
5.0   0.4
6.0   0.6
7.0   0.8
8.0   1.0
9.0   1.2
10.0   1.4

Construct with lazy scaling via ZScore

julia> ts = concrete_term(term(:x), d, ZScore())
x(centered: 5.5 scaled: 3.03)

julia> hcat(modelcols(t + ts, d)...)
10×2 Matrix{Float64}:
1.0  -1.4863
2.0  -1.15601
3.0  -0.825723
4.0  -0.495434
5.0  -0.165145
6.0   0.165145
7.0   0.495434
8.0   0.825723
9.0   1.15601
10.0   1.4863

Or similarly via schema hints:

julia> sch = schema(d, Dict(:x => ZScore()))
StatsModels.Schema with 1 entry:
x => x(centered: 5.5 scaled: 3.03)
source
StandardizedPredictors._standardMethod
_standard(xs::AbstractArray, val)

Translate an abstract standardization value to a concrete one based on xs.

nothing and already concrete Number vals are passed through. Otherwise, val(xs) is returned.

source
StandardizedPredictors.scale!Method
scale(f=std, x, y=f(skipmissing(x)))

Scale an array x in place by a scalar y.

Warning

This only scales and does not center the values, unlike scale in R. See StatsBase.zscore for that functionality.

See also scale

source
StandardizedPredictors.scaleMethod
scale(f=std, x, y=f(skipmissing(x)))

Scale an array x by a scalar y.

Warning

This only scales and does not center the values, unlike scale in R. See StatsBase.zscore for that functionality.

See also scale!

source