Closed mattansb closed 3 years ago
Isn't it what's there https://github.com/easystats/modelbased#understand-interactions-between-two-continuous-variables ?
Oh it is!
Need some vignettes........ (:
But actually, can add the split into sig/non-sig regions?
Let's make the argument control fill
either as a value to threshold or a continuous gradient (probably of log(p)).
you mean here to map the sig/non-sig aesthetic unto the ribbon's fill rather than the line color? I initially tried that, but ended up with the problem that the same colour parts get connected together, creating junction artifacts.
How could we change the plot?
library(modelbased)
model <- lm(mpg ~ hp * wt, data = mtcars)
slopes <- estimate_slopes(model, trend = "hp", modulate = "wt")
modelbased::visualisation_recipe(slopes)
#> Layer 1
#> --------
#> Geom type: hline
#> data = [10 x 10]
#> yintercept = 0
#> linetype = 'dashed'
#>
#> Layer 2
#> --------
#> Geom type: ribbon
#> data = [10 x 10]
#> aes_string(
#> y = 'Coefficient'
#> x = 'wt'
#> ymin = 'CI_low'
#> ymax = 'CI_high'
#> )
#> alpha = 0.3333333
#>
#> Layer 3
#> --------
#> Geom type: line
#> data = [10 x 10]
#> aes_string(
#> y = 'Coefficient'
#> x = 'wt'
#> color = 'Confidence'
#> group = 1
#> )
#>
#> Layer 4
#> --------
#> Geom type: labs
#> y = 'Effect of hp'
#> color = 'Confidence'
#> title = 'Estimated Coefficients (mpg ~ hp * wt)'
Created on 2021-07-07 by the reprex package (v2.0.0)
How do we do it with the bayestestR density regions? How does ggdist do it (and the gradient versions)?
I initially tried that, but ended up with the problem that the same colour parts get connected together, creating junction artifacts.
Ah, that what this super ugly part of code does!
transform(.part.group = {function(x) rep(seq_along(x$lengths), x$length)}(rle(.sig))) |> # trust me this ugliness is needed
where's this code from?
Its part of the code I wrote in the first comment on this issue.
Or do you mean how on earth did I figure that out? Because man, that was not easy at all...............
haha yes it seems to work, in that case indeed I can swap the line's color for the ribbon's fill
👍
library(modelbased)
model <- lm(Petal.Length ~ poly(Sepal.Width, 4), data = iris)
x <- estimate_slopes(model, modulate = "Sepal.Width", length = 20)
#> No numeric variable was specified for slope estimation. Selecting `trend = "Sepal.Width"`.
plot(visualisation_recipe(x))
Created on 2021-07-09 by the reprex package (v2.0.0)
What are those spaces?
Marginally significant
Spaces can be minimized by increasing the length
model <- lm(Petal.Length ~ poly(Sepal.Width, 4), data = iris)
plot(modelbased::estimate_slopes(model, modulate = "Sepal.Width", length = 500))
#> No numeric variable was specified for slope estimation. Selecting `trend = "Sepal.Width"`.
Created on 2021-07-09 by the reprex package (v2.0.0)
Oh, it's the same dealio as with visualization grid generally. Got it
Beautiful!
FYI: It's common to mark the range of observed values in the data (I think in case the region of sig is just on the edge of this range? dunno...)
Yeah in the "interaction" packages that implements the JN plots the range is indeed extended by some amount of both sides, and then the actual range is marked. IMHO it clutters the plot, and it suggests that the results beyond the observed range are fine to be interpreted (and opens the door to statements like "even though in our data the effect of var1 is not significant BUT IF var2 was bigger then it would have been - so we can say it's significant 👍"). We shouldn't extrapolate too much, and I think it's just more readable and clear to show what's happening within the range of the data
I agree. I like keeping the plot showing the actual data range
As I understand we're using
emmeans
as the backend, here's how to do it with emmeans:Linear interaction
GAMs
Created on 2021-07-06 by the reprex package (v2.0.0)