Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Bug or feaure request? #235

Closed
andybeet opened this issue Jul 17, 2024 · 5 comments
Closed

Bug or feaure request? #235

andybeet opened this issue Jul 17, 2024 · 5 comments

Comments

@andybeet
Copy link

Not sure if it is a bug or something that is not yet been considered

mtcarsnew <- mtcars |> 
  dplyr::mutate(cyl = as.factor(cyl))

fit <- lm(formula = mpg ~ wt:cyl,data = mtcarsnew)
equatiomatic::extract_eq(fit)

$$ mpg = \alpha + \beta_{1}() + \beta_{2}() + \beta_{3}() + \epsilon $$

Created on 2024-07-17 with reprex v2.1.0

The output should be something like:

$$ mpg = \alpha + \beta_{j}(wt) + \epsilon $$

@phgrosjean
Copy link
Collaborator

Well, you want to adjust a model containing only interactions ? Does it make sense ? I don't think so. You probably mean here mpg ~ cyl, which produces a correct equation using extract_eq().

For other variants, if you use mpg ~ wt + wt:cyl, extract_eq() works correctly, also with mpg ~ wt + cyl.

@andybeet
Copy link
Author

No, this is not a model with interactions. This equation is simply a model representing different slopes. Standard model. You would then test the H0: beta_j = beta.

@phgrosjean
Copy link
Collaborator

With the default treatment contrast matrix, the first level is considered as reference and the other betas are change in the slope. Hence, if you want a model with a different slope for each level of cyl, you have to use mpg ~ wt + wt:cyl. Then, you got the following equation:

$$ mpg = \alpha + \beta_{1}(wt) + \beta_{2}(wt \times wt_{cyl6}) + \beta_{3}(wt \times wt_{cyl8}) + \epsilon $$

beta_1 is the slope adjusted to cyl = 4, then beta_2 and beta_3 are changes from the beta_1 slope, respectively for cyl = 6 and cyl = 8. I think this is what you are looking for, although parameterized differently. mpg ~ wt:cyl does not match H0: beta_j = beta in R, at least with the default contrast treatments. It is not the way lm()was programmed.

@phgrosjean
Copy link
Collaborator

Here, you have to check that beta_2 and beta_3 are not significantly different to zero to match your H0:beta_j = beta hypothesis.

@andybeet
Copy link
Author

Thanks @phgrosjean . I am just looking for a clean representation of a formula. I am not using lm. I just used lm to create an example model that i can translate through this package into a form that i want. And the specific example i gave is just that. I am not using mtcars for anything, just to give an example of a representation of a formula i was hoping your package might be able to translate. You have a nice package i'll use it for other things but probably not for this project

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

No branches or pull requests

2 participants