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

Error in estimte_slopes when trend is a factor #305

Open
DominiqueMakowski opened this issue Jan 9, 2025 · 2 comments
Open

Error in estimte_slopes when trend is a factor #305

DominiqueMakowski opened this issue Jan 9, 2025 · 2 comments
Labels
Bug 🐛 Something isn't working

Comments

@DominiqueMakowski
Copy link
Member

model <- lm(Sepal.Length ~ Species * Sepal.Width, data = iris)
modelbased::estimate_slopes(model, trend="Species", by="Sepal.Width")
#> Error in Summary.factor(structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, : 'range' not meaningful for factors

Created on 2025-01-09 with reprex v2.1.1

@strengejacke strengejacke added the Bug 🐛 Something isn't working label Jan 9, 2025
@strengejacke
Copy link
Member

It works with the marginaleffects backend, though, but I'm not sure which output is expected?

model <- lm(Sepal.Length ~ Species * Sepal.Width, data = iris)
modelbased::estimate_slopes(
  model,
  trend = "Species",
  by = "Sepal.Width",
  backend = "marginaleffects"
)
#> Estimated Marginal Effects
#> 
#> Parameter |          Comparison | Sepal.Width | Coefficient |   SE
#> ------------------------------------------------------------------
#> Species   | versicolor - setosa |        2.00 |        1.25 | 0.30
#> Species   |  virginica - setosa |        2.00 |        1.69 | 0.32
#> Species   | versicolor - setosa |        2.27 |        1.30 | 0.23
#> Species   |  virginica - setosa |        2.27 |        1.75 | 0.25
#> Species   | versicolor - setosa |        2.53 |        1.34 | 0.18
#> Species   |  virginica - setosa |        2.53 |        1.80 | 0.19
#> Species   | versicolor - setosa |        2.80 |        1.39 | 0.14
#> Species   |  virginica - setosa |        2.80 |        1.86 | 0.14
#> Species   | versicolor - setosa |        3.07 |        1.44 | 0.12
#> Species   |  virginica - setosa |        3.07 |        1.92 | 0.11
#> Species   | versicolor - setosa |        3.33 |        1.48 | 0.14
#> Species   |  virginica - setosa |        3.33 |        1.97 | 0.11
#> Species   | versicolor - setosa |        3.60 |        1.53 | 0.19
#> Species   |  virginica - setosa |        3.60 |        2.03 | 0.15
#> Species   | versicolor - setosa |        3.87 |        1.58 | 0.25
#> Species   |  virginica - setosa |        3.87 |        2.08 | 0.21
#> Species   | versicolor - setosa |        4.13 |        1.62 | 0.31
#> Species   |  virginica - setosa |        4.13 |        2.14 | 0.27
#> Species   | versicolor - setosa |        4.40 |        1.67 | 0.37
#> Species   |  virginica - setosa |        4.40 |        2.20 | 0.33
#> 
#> Parameter |       95% CI |     t |      p
#> -----------------------------------------
#> Species   | [0.67, 1.83] |  4.23 | < .001
#> Species   | [1.07, 2.31] |  5.35 | < .001
#> Species   | [0.84, 1.76] |  5.53 | < .001
#> Species   | [1.25, 2.24] |  6.92 | < .001
#> Species   | [0.99, 1.69] |  7.51 | < .001
#> Species   | [1.43, 2.18] |  9.36 | < .001
#> Species   | [1.12, 1.66] | 10.19 | < .001
#> Species   | [1.58, 2.13] | 13.24 | < .001
#> Species   | [1.20, 1.67] | 11.79 | < .001
#> Species   | [1.70, 2.13] | 17.74 | < .001
#> Species   | [1.20, 1.76] | 10.31 | < .001
#> Species   | [1.75, 2.19] | 17.37 | < .001
#> Species   | [1.16, 1.90] |  8.04 | < .001
#> Species   | [1.73, 2.33] | 13.25 | < .001
#> Species   | [1.09, 2.06] |  6.37 | < .001
#> Species   | [1.68, 2.49] | 10.02 | < .001
#> Species   | [1.02, 2.23] |  5.24 | < .001
#> Species   | [1.61, 2.67] |  7.95 | < .001
#> Species   | [0.94, 2.40] |  4.46 | < .001
#> Species   | [1.54, 2.85] |  6.60 | < .001
#> Marginal effects estimated for Species

Created on 2025-01-09 with reprex v2.1.1

@DominiqueMakowski
Copy link
Member Author

That seems correct, the expected output would be all the species-related parameters (i.e., virginica and versicolor (minus the ref) unfolded over Sepal.Width

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants