Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coefnames returns symbols #169

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Tokazama
Copy link

This PR begins to address #113. Right now it errors on the statsmodels tests. It's due to a problem with CoefTable. I think I would need to make a PR to StatsBase giving NoQuote the ability to handle Symbol. Other than that it seems to pass all tests.

So if you like this PR I'll take the next step and see if I can fix the problem in StatsBase.

@kleinschmidt
Copy link
Member

kleinschmidt commented Jan 20, 2020 via email

@mkborregaard
Copy link
Contributor

This looks nice

Copy link
Member

@kleinschmidt kleinschmidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This generally seems fine by me. I'm honestly not quite sure what the knock-on effects of this would be; at the very least packages like MixedModels that use this API would have to be updated, and maybe others. So it would be pretty disruptive but maybe worth it. I think a little more justification for why this is necessary is needed before we merge it though, as well as a bit of clean up.

coefnames(ll.term) .* "_$opname$(ll.nsteps)"
end
StatsBase.coefnames(ll::LeadLagTerm{<:Any, F}) where F = _llcoef(ll, coefnames(ll.term), string(nameof(F.instance)))
_llcoef(ll::LeadLagTerm, t::Symbol, opname) = Symbol(t, "_$opname$(ll.nsteps)")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why can't you use the original broadcast based solution?

@@ -543,18 +543,48 @@ 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.
`Symbol` or an iterable of `String`s.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missed a String

["$(t.sym): $name" for name in t.contrasts.termnames]
StatsBase.coefnames(t::FunctionTerm) = string(t.exorig)
StatsBase.coefnames(ts::TupleTerm) = reduce(vcat, coefnames.(ts))
StatsBase.coefnames(::InterceptTerm{H}) where {H} = H ? Symbol(:Intercept) : [] # this seems like the wrong thing to return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep the parens? Then you'd have Symbol("(Intercept)").

"""
coef(term::AbstractTerm, s::Symbol)
"""
function StatsBase.coef(f::FormulaTerm, s::Symbol)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see what the point of this is, or rather why it's called coef (which means something different in statsbase). can you explain what your goal is here? in any case, this needs tests if it's going to be included, and it seems like it would be better in a separate PR.

also, it doesn't seem like this works for categorical terms or for interactions, even if you specify the full coefficient name, since coefnames will be a vector of symbols.

and the RHS can have other things than just a MatrixTerm (e.g., MixedModels has a tuple of fixed and random effect matrices which are of different types)

@kleinschmidt
Copy link
Member

One nice consequence of this would be is that it would be easier to create named tuples from various kinds of model outputs (I just found myself converting coefnames into Symbols to do this).

@nalimilan
Copy link
Member

Let's discuss whether it's a good idea or not at #113.

@Tokazama
Copy link
Author

Thanks for taking a look at this. I'll address the issues if people agree it's a good idea. It was admittedly a messy first attempt to see how practical implementing it would be

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants