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

estimate_contrasts(): Different results using as.factor() within or outside formula #230

Open
rempsyc opened this issue Jul 2, 2023 · 0 comments

Comments

@rempsyc
Copy link
Member

rempsyc commented Jul 2, 2023

estimate_contrasts(): Different results using as.factor() within or outside formula:

library(modelbased)

# as.factor within model = 2 levels
model <- lm(mpg ~ as.factor(cyl) + wt * hp, mtcars)
estimate_contrasts(model)
#> No variable was specified for contrast estimation. Selecting `contrast = "cyl"`.
#> Marginal Contrasts Analysis
#> 
#> Level1 | Level2 | Difference |        95% CI |   SE | t(26) |     p
#> -------------------------------------------------------------------
#> cyl4   |   cyl8 |       1.45 | [-2.79, 5.70] | 2.06 |  0.70 | 0.487
#> 
#> Marginal contrasts estimated at cyl
#> p-value adjustment method: Holm (1979)

# as.factor outside model = 3 levels
mtcars2 <- mtcars
mtcars2$cyl <- as.factor(mtcars2$cyl)
model <- lm(mpg ~ cyl + wt * hp, mtcars2)
estimate_contrasts(model)
#> No variable was specified for contrast estimation. Selecting `contrast = "cyl"`.
#> Marginal Contrasts Analysis
#> 
#> Level1 | Level2 | Difference |        95% CI |   SE | t(26) |      p
#> --------------------------------------------------------------------
#> cyl4   |   cyl6 |       1.26 | [-2.55, 5.07] | 1.49 |  0.85 | > .999
#> cyl4   |   cyl8 |       1.45 | [-3.83, 6.74] | 2.06 |  0.70 | > .999
#> cyl6   |   cyl8 |       0.20 | [-3.64, 4.03] | 1.50 |  0.13 | > .999
#> 
#> Marginal contrasts estimated at cyl
#> p-value adjustment method: Holm (1979)

Created on 2023-07-02 with reprex v2.0.2

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

1 participant