easystats / easystats/modelbased

Plotting contrasts for categorical model with interaction

Open
#267 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Plot :sparkler:
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.