From 9eb7772e286ce9e60291fcd6ecc24679bbdb403e Mon Sep 17 00:00:00 2001 From: Milan Bouchet-Valat Date: Thu, 7 Sep 2023 16:00:12 +0200 Subject: [PATCH] Slighltly improve `coefnames` with no intercept Adopt improvements from `termnames`. --- src/terms.jl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/terms.jl b/src/terms.jl index 188120b1..dd41aadf 100644 --- a/src/terms.jl +++ b/src/terms.jl @@ -567,13 +567,15 @@ vectorize(x) = [x] """ coefnames(term::AbstractTerm) -Return the name(s) of column(s) generated by a term. Return value is either a -`String` or an iterable of `String`s. +Return the name(s) of column(s) generated by a term. + +Return value is either a `String`, an iterable of `String`s or the empty vector +if there is no associated column (e.g. `coefnames(InterceptTerm{false}())`). See also [`termnames`](@ref). """ StatsAPI.coefnames(t::FormulaTerm) = (coefnames(t.lhs), coefnames(t.rhs)) -StatsAPI.coefnames(::InterceptTerm{H}) where {H} = H ? "(Intercept)" : [] +StatsAPI.coefnames(::InterceptTerm{H}) where {H} = H ? "(Intercept)" : String[] StatsAPI.coefnames(t::ContinuousTerm) = string(t.sym) StatsAPI.coefnames(t::CategoricalTerm) = ["$(t.sym): $name" for name in t.contrasts.coefnames]