easystats / easystats/modelbased
Plotting contrasts for categorical model with interaction
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 263
- Forks
- 22
- Avg merge
- 1h 22m
- Merged PRs (30d)
- 11
Description
When plotting contrasts for a model with an interaction term between two categorical variables, is it possible to split the lighthouse plots into facets?
It seems to me that the contrast are correctly calculated, but the output plot is not what I would expect.
library(ggplot2)
library(modelbased)
library(see)
data("Arabidopsis", package = "lme4")
model = lm(total.fruits ~ amd*status, Arabidopsis)
means = estimate_means(model)
#> We selected `by = c("amd", "status")`.
contrasts = estimate_contrasts(model, contrast = "amd", by = "status")
contrasts
#> Marginal Contrasts Analysis
#>
#> Level1 | Level2 | status | Difference | 95% CI | SE | t(619) | p
#> ----------------------------------------------------------------------------------------
#> clipped | unclipped | Normal | -5.73 | [-14.02, 2.56] | 4.22 | -1.36 | 0.175
#> clipped | unclipped | Petri.Plate | -4.62 | [-21.61, 12.38] | 8.65 | -0.53 | 0.594
#> clipped | unclipped | Transplant | 0.37 | [-12.48, 13.21] | 6.54 | 0.06 | 0.955
#>
#> Marginal contrasts estimated at amd
#> p-value adjustment method: Holm (1979)
plot(contrasts, means) +
facet_wrap(vars(status))

Created on 2024-10-28 with reprex v2.1.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied Arabidopsis example with estimate_means(), estimate_contrasts(), and plot(contrasts, means), including facet_wrap(vars(status)). Inspect how the plotting entry point combines contrasts and means; the work is done when the categorical interaction contrasts render in separate status facets without changing their calculated values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100