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

Missing method for fe(:a) * fe(:d) is missing when using term() #258

Closed
IljaK91 opened this issue Jul 19, 2022 · 4 comments
Closed

Missing method for fe(:a) * fe(:d) is missing when using term() #258

IljaK91 opened this issue Jul 19, 2022 · 4 comments

Comments

@IljaK91
Copy link

IljaK91 commented Jul 19, 2022

Hi everyone, I was sent over from FixedEffectModels.jl as the problem seems to stem from StatsModels.jl

Here is the link to the thread: FixedEffects/FixedEffectModels.jl#206

Here is the original issue:

The following throws an error when using *

df = DataFrame(a=rand(10), b=rand(10), c=[1, 1, 1, 0, 0, 0, 0, 0, 0, 0], d=[0,0,0,0,0, 1, 1, 1, 1, 1 ])

reg(df, term(:a) ~ term(:b) + fe(:c) * fe(:d)) # This throws an error
reg(df, term(:a) ~ term(:b) + fe(:c) & fe(:d)) # This works
reg(df, term(:a) ~ term(:b) + fe(:c) + fe(:d) + fe(:c) & fe(:d)) # This works

error message:

ERROR: MethodError: no method matching *(::FixedEffectModels.FixedEffectTerm, ::FixedEffectModels.FixedEffectTerm)
Closest candidates are:
  *(::Any, ::Any, ::Any, ::Any...) at C:\Users\kantorov\.julia\juliaup\julia-1.7.3+0~x64\share\julia\base\operators.jl:655
  *(::Union{MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}, MathOptInterface.VectorAffineFunction{T}, MathOptInterface.VectorQuadraticFunction{T}}, ::T) where T at C:\Users\kantorov\.julia\packages\MathOptInterface\AiEiQ\src\Utilities\functions.jl:3270
  *(::ChainRulesCore.AbstractThunk, ::Any) at C:\Users\kantorov\.julia\packages\ChainRulesCore\16PWJ\src\tangent_arithmetic.jl:125
  ...
Stacktrace:
 [1] top-level scope
   @ c:\Users\kantorov\Desktop\mwe.jl:13
@kleinschmidt
Copy link
Member

Among other things, this is fixed by #183 IIRC.

@kleinschmidt
Copy link
Member

As for why, it's because the formula syntax (distributed/associative rules for + and &, * expansion) are handled inside the @formula macro currently, and not at runtime. I decided at some point that it was better to have one source of truth for how these expansions worked or else you're in danger of getting different results from superficially similar formulae (at run-time vs. @formula). #183 changes that one source of truth to be the run-time operators themselves, so everything is handled by the methods like *(::AbstractTerm, ::AbstractTerm)

@matthieugomez
Copy link
Contributor

Thanks! This can be closed now — this code snippet no longer throws an error with the latest version of FixedEffectModels.

@kleinschmidt
Copy link
Member

* expansion shoudl work at run-time with all AbstractTerms now with this line merged and released:

Base.:*(a::TermOrTerms, b::TermOrTerms) = a + b + a&b

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

No branches or pull requests

3 participants