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

Minus sign in FixedEffectModels not handled #164

Open
eloualiche opened this issue Aug 16, 2024 · 1 comment
Open

Minus sign in FixedEffectModels not handled #164

eloualiche opened this issue Aug 16, 2024 · 1 comment

Comments

@eloualiche
Copy link

eloualiche commented Aug 16, 2024

This might an edge case coming from FixedEffectModels permissive formulas.
Fixedeffectmodels allows for some "calculations" inside the formulas, one of them being a substraction. This returns a valid result in fixedeffectmodels but triggers an error once inside of regtable

using DataFrames
using RDatasets
using RegressionTables
using FixedEffectModels
iris = dataset("datasets", "iris")
r1 = reg(iris, @formula(SepalLength  ~ SepalWidth - PetalLength ))
regtable(r1; render = AsciiTable())

The output is

julia> r1 = reg(iris, @formula(SepalLength  ~ SepalWidth - PetalLength ))
                                    FixedEffectModel
=========================================================================================
Number of obs:                          150   Converged:                             true
dof (model):                              1   dof (residuals):                        147
R²:                                   0.638   R² adjusted:                          0.635
F-statistic:                        260.425   P-value:                              0.000
=========================================================================================
                           Estimate  Std. Error    t-stat  Pr(>|t|)  Lower 95%  Upper 95%
─────────────────────────────────────────────────────────────────────────────────────────
SepalWidth - PetalLength  -0.332045   0.0205758  -16.1377    <1e-33  -0.372708  -0.291383
(Intercept)                5.61068    0.0433073  129.555     <1e-99   5.52509    5.69627
=========================================================================================


julia> regtable(r1; render = AsciiTable())
ERROR: MethodError: no method matching iterate(::FunctionTerm{typeof(-), Vector{Term}})
...

I am not sure it's worth doing anything about. Maybe people can find this issue if they run into something similar.
I do believe this is new behavior that showed up as I was running some old code (could not tell you the version though).

@junder873
Copy link
Collaborator

Thank you for bringing this to my attention.

Looked into this, turns out the issue isn't necessarily the subtraction term but the singe right hand side term. For example:

r1 = reg(iris, @formula(SepalLength ~ log1p(SepalWidth))
regtable(r1)

Also causes an error.

I am working on a fix, but if you need a quick fix you can add the intercept directly which will solve the issue:

r1 = reg(iris, @formula(SepalLength ~ 1 + (SepalWidth - PetalLength))
regtable(r1)
--------------------------------------
                           SepalLength
--------------------------------------
(Intercept)                   5.611***
                               (0.043)
SepalWidth - PetalLength     -0.332***
                               (0.021)
--------------------------------------
N                                  150
R2                               0.638
--------------------------------------

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

2 participants