@@ -42,7 +42,7 @@ width(::ConstantTerm) = 1
4242 FormulaTerm{L,R} <: AbstractTerm
4343
4444Represents an entire formula, with a left- and right-hand side. These can be of
45- any type (captured by the type parameters).
45+ any type (captured by the type parameters).
4646
4747# Fields
4848
@@ -64,7 +64,7 @@ data table.
6464
6565The `FunctionTerm` _also_ captures the arguments of the original call and parses
6666them _as if_ they were part of a special DSL call, applying the rules to expand
67- `*`, distribute `&` over `+`, and wrap symbols in `Term`s.
67+ `*`, distribute `&` over `+`, and wrap symbols in `Term`s.
6868
6969By storing the original function as a type parameter _and_ pessimistically
7070parsing the arguments as if they're part of a special DSL call, this allows
@@ -78,7 +78,7 @@ on `apply_schema(f::FunctionTerm{typeof(special_syntax)}, schema,
7878* `forig::Forig`: the original function (e.g., `log`)
7979* `fanon::Fanon`: the generated anonymous function (e.g., `(a, b) -> log(1+a+b)`)
8080* `exorig::Expr`: the original expression passed to `@formula`
81- * `args_parsed::Vector`: the arguments of the call passed to `@formula`, each
81+ * `args_parsed::Vector`: the arguments of the call passed to `@formula`, each
8282 parsed _as if_ the call was a "special" DSL call.
8383
8484# Type parameters
@@ -113,7 +113,7 @@ julia> modelcols(f.rhs, (a=3, b=4))
113113julia> modelcols(f.rhs, (a=[3, 4], b=[4, 5]))
1141142-element Array{Float64,1}:
115115 2.0794415416798357
116- 2.302585092994046
116+ 2.302585092994046
117117```
118118"""
119119struct FunctionTerm{Forig,Fanon,Names} <: AbstractTerm
@@ -132,7 +132,7 @@ Base.:(==)(a::FunctionTerm, b::FunctionTerm) = a.forig == b.forig && a.exorig ==
132132"""
133133 InteractionTerm{Ts} <: AbstractTerm
134134
135- Represents an _interaction_ between two or more individual terms.
135+ Represents an _interaction_ between two or more individual terms.
136136
137137Generated by combining multiple `AbstractTerm`s with `&` (which is what calls to
138138`&` in a `@formula` lower to)
@@ -223,8 +223,8 @@ Represents a categorical term, with a name and [`ContrastsMatrix`](@ref)
223223# Fields
224224
225225* `sym::Symbol`: The name of the variable
226- * `contrasts::ContrastsMatrix`: A contrasts matrix that captures the unique
227- values this variable takes on and how they are mapped onto numerical
226+ * `contrasts::ContrastsMatrix`: A contrasts matrix that captures the unique
227+ values this variable takes on and how they are mapped onto numerical
228228 predictors.
229229"""
230230struct CategoricalTerm{C,T,N} <: AbstractTerm
@@ -242,9 +242,9 @@ CategoricalTerm(sym::Symbol, contrasts::ContrastsMatrix{C,T}) where {C,T} =
242242
243243A collection of terms that should be combined to produce a single numeric matrix.
244244
245- A matrix term is created by [`apply_schema`](@ref) from a tuple of terms using
245+ A matrix term is created by [`apply_schema`](@ref) from a tuple of terms using
246246[`collect_matrix_terms`](@ref), which pulls out all the terms that are matrix
247- terms as determined by the trait function [`is_matrix_term`](@ref), which is
247+ terms as determined by the trait function [`is_matrix_term`](@ref), which is
248248true by default for all `AbstractTerm`s.
249249"""
250250struct MatrixTerm{Ts<: TupleTerm } <: AbstractTerm
@@ -311,7 +311,7 @@ is_matrix_term(::Type{<:AbstractTerm}) = true
311311
312312
313313"""
314- capture_call(f_orig::Function, f_anon::Function, argnames::NTuple{N,Symbol},
314+ capture_call(f_orig::Function, f_anon::Function, argnames::NTuple{N,Symbol},
315315 ex_orig::Expr, args_parsed::Vector{AbstractTerm})
316316
317317When the [`@formula`](@ref) macro encounters a call to a function that's not
@@ -404,6 +404,7 @@ Base.:&(terms::AbstractTerm...) = InteractionTerm(terms)
404404Base.:& (term:: AbstractTerm ) = term
405405Base.:& (it:: InteractionTerm , terms:: AbstractTerm... ) = InteractionTerm ((it. terms... , terms... ))
406406
407+ Base.:+ (a:: AbstractTerm ) = a
407408Base.:+ (a:: AbstractTerm , b:: AbstractTerm ) = a== b ? a : (a, b)
408409Base.:+ (as:: TupleTerm , b:: AbstractTerm ) = b in as ? as : (as... , b)
409410Base.:+ (a:: AbstractTerm , bs:: TupleTerm ) = a in bs ? bs : (a, bs... )
437438"""
438439 modelcols(ts::NTuple{N, AbstractTerm}, data) where N
439440
440- When a tuple of terms is provided, `modelcols` broadcasts over the individual
441+ When a tuple of terms is provided, `modelcols` broadcasts over the individual
441442terms. To create a single matrix, wrap the tuple in a [`MatrixTerm`](@ref).
442443
443444# Example
@@ -448,7 +449,7 @@ julia> using StableRNGs; rng = StableRNG(1);
448449julia> d = (a = [1:9;], b = rand(rng, 9), c = repeat(["d","e","f"], 3));
449450
450451julia> ts = apply_schema(term.((:a, :b, :c)), schema(d))
451- a(continuous)
452+ a(continuous)
452453b(continuous)
453454c(DummyCoding:3→2)
454455
@@ -498,8 +499,8 @@ modelcols(t::CategoricalTerm, d::NamedTuple) = t.contrasts[d[t.sym], :]
498499"""
499500 reshape_last_to_i(i::Int, a)
500501
501- Reshape `a` so that its last dimension moves to dimension `i` (+1 if `a` is an
502- `AbstractMatrix`).
502+ Reshape `a` so that its last dimension moves to dimension `i` (+1 if `a` is an
503+ `AbstractMatrix`).
503504"""
504505reshape_last_to_i (i, a) = a
505506reshape_last_to_i (i, a:: AbstractVector ) = reshape (a, ones (Int, i- 1 )... , :)
@@ -557,7 +558,7 @@ Return the name(s) of column(s) generated by a term. Return value is either a
557558StatsBase. coefnames (t:: FormulaTerm ) = (coefnames (t. lhs), coefnames (t. rhs))
558559StatsBase. coefnames (:: InterceptTerm{H} ) where {H} = H ? " (Intercept)" : []
559560StatsBase. coefnames (t:: ContinuousTerm ) = string (t. sym)
560- StatsBase. coefnames (t:: CategoricalTerm ) =
561+ StatsBase. coefnames (t:: CategoricalTerm ) =
561562 [" $(t. sym) : $name " for name in t. contrasts. termnames]
562563StatsBase. coefnames (t:: FunctionTerm ) = string (t. exorig)
563564StatsBase. coefnames (ts:: TupleTerm ) = reduce (vcat, coefnames .(ts))
@@ -580,7 +581,7 @@ omitsintercept(t::TermOrTerms) =
580581
581582hasresponse (t) = false
582583hasresponse (t:: FormulaTerm ) =
583- t. lhs != = nothing &&
584+ t. lhs != = nothing &&
584585 t. lhs != = ConstantTerm (0 ) &&
585586 t. lhs != = InterceptTerm {false} ()
586587
0 commit comments