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

Inconsistent behavior when adding two "duplicate" functional terms with @formula #204

Closed
junyuan-chen opened this issue Dec 24, 2020 · 2 comments · Fixed by #205
Closed

Comments

@junyuan-chen
Copy link

This seems to be a minor issue, but I decide to report it here anyway.
Here is an example when two functional terms that are supposed to be identical are handled differently with and without @formula.

julia> using StatsModels

julia> @formula (y ~ lag(x,1) + lag(x,1))
FormulaTerm
Response:
  y(unknown)
Predictors:
  (x)->lag(x, 1)
  (x)->lag(x, 1)

julia> @formula (y ~ x + x)
FormulaTerm
Response:
  y(unknown)
Predictors:
  x(unknown)

julia> term(:y) ~ lag(term(:x),1) + lag(term(:x),1)
FormulaTerm
Response:
  y(unknown)
Predictors:
  lag(x, 1)

julia> term(:y) ~ term(:x) + term(:x)
FormulaTerm
Response:
  y(unknown)
Predictors:
  x(unknown)

Since an instance of FunctionalTerm created by @formula involves an anonymous function, the two lag(x,1)s inside @formula are not considered identical and hence the "uniqueness" is not handled.

@junyuan-chen junyuan-chen changed the title Inconsistent behavior when adding two "duplicate" functional terms with @formula Inconsistent behavior when adding two "duplicate" functional terms with @formula Dec 24, 2020
@kleinschmidt
Copy link
Member

Thanks for the report, that's a real issue since we try to ensure that terms are
unique in a context, as you noted. I also agree with your diagnosis of the
underlying issue, which (I think) should be fixed by #183. In the mean time I
think we can add a specialized method for comparing two function terms...

kleinschmidt added a commit that referenced this issue Dec 29, 2020
kleinschmidt added a commit that referenced this issue Jan 5, 2021
* confirm failing test for #204

* equality for FuncionTerm check function and original expression

* test that adding two non-equal FunctionTerms works correctly
@kleinschmidt
Copy link
Member

This is fixed in v0.6.18 so ] up should fix it JuliaRegistries/General#27443

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

Successfully merging a pull request may close this issue.

2 participants