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

Implement model-fitting statistics using compute-panel functions #30

Open
tillrose opened this issue Oct 6, 2022 · 8 comments
Open
Assignees
Labels
enhancement New feature or request

Comments

@tillrose
Copy link

tillrose commented Oct 6, 2022

Is it right that ggpmisc does not support lm models without interactions? Any easy way to handle it?

@tillrose tillrose added the enhancement New feature or request label Oct 6, 2022
@aphalo
Copy link
Owner

aphalo commented Oct 7, 2022

I am not sure to understand your question. Within ggplot2 one can only define a model using as variables the name of aesthetics, as statistics do not have accesses to the user's data. There more than one statistic that supports lm, so please explain in more detail what you are trying to do.

@aphalo aphalo added question Further information is requested on hold waiting until I know more and removed enhancement New feature or request labels Oct 7, 2022
@tillrose
Copy link
Author

tillrose commented Oct 7, 2022

Within ggplot2 all grouping variables are always added with full interaction to the statistical model:
y ~ x * group

but in an analysis it is sometimes wanted to add the grouping variable without interaction:
y ~ x + group

It is easy to add model predictions of such a predefined model but to add the model equations is hard. It would be great if ggpmisc could handle these cases but I fully understand that it is against the framework.

@aphalo
Copy link
Owner

aphalo commented Oct 7, 2022

I guess you are using stat_poly_eq(). There are two ways in which statistics can be defined. Many are defined using computations per group. So, what you are seeing is not that the interaction is included in the model, but that a simple y ~ x model is being fit separately to each group. It is in possible to define stats using computations by panel, so I could in principle write a new statistic for the behaviour you wish, but the difficulty is that building the equations automatically becomes much more complex. So, the formatting of the equation is difficult to automate unless some restriction is imposed. At the moment the only stat in 'ggpmisc' defined to work by panel is stat_fit_tb() but its output is formatted to make it easy to add ANOVA and summary tables as insets. It should be possible, but not too easy to use the coefficient estimates from the summary table to assemble the model equation within the call to aes(). Anyway, it should be easy for me to create a variation of stat_fit_tb() that makes it easier to build equations or a new version of stat_poly_eq() that handles specifically the kind of models you want to use.

@aphalo aphalo added enhancement New feature or request and removed question Further information is requested on hold waiting until I know more labels Oct 7, 2022
@aphalo aphalo added this to the 0.5.1 milestone Oct 7, 2022
@aphalo
Copy link
Owner

aphalo commented Oct 7, 2022

@tillrose Thanks for suggesting this enhancement!

@tillrose
Copy link
Author

tillrose commented Oct 7, 2022

Thanks for your positive reply. I think, you already got what I mean. But because I have a figure at hand, I just add an example.
example

@aphalo
Copy link
Owner

aphalo commented Oct 7, 2022

Thanks! o.k, got it now. You fit a single model but still want to have one equation for each group.

@aphalo
Copy link
Owner

aphalo commented Dec 17, 2022

Moved to a later milestone. Requires implementing a new set of stats based on compute_panel() functions.

@aphalo aphalo modified the milestones: 0.5.2, 0.5.3 and later Dec 17, 2022
@aphalo aphalo changed the title lm models that are grouped by facet or aesthetics without interaction Implement model-fitting statistics using compute-panel functions May 23, 2024
@aphalo
Copy link
Owner

aphalo commented May 23, 2024

A possible way of handling this request is to implement new statistics using compute panel functions and include the grouping in the model formula. This can be fairly tricky with multiple groupings unless we use an approach similar to that used for grp.label and ignore the groupings created by mappings to true aesthetics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants