easystats / see

:art: Visualisation toolbox for beautiful and publication-ready figures
https://easystats.github.io/see/
Other
891 stars 44 forks source link

Improved q-q plot error bands #299

Closed mattansb closed 1 year ago

mattansb commented 1 year ago

Closes https://github.com/easystats/performance/issues/599

@bwiernik Should this be the new default qq/pp-band method?

Note that currently the default plot is a density plot.... I would rather it be a qq-plot, don't you think?

library(performance)
library(see)

m <- lm(mpg ~ ., mtcars)

Old qq-plot

check_normality(m) |> plot(type = "qq", method = "pointwise") + 
  ggplot2::coord_cartesian(ylim = c(-2, 2))

qq-plots with the new "ell" default

check_normality(m) |> plot(type = "qq") + 
  ggplot2::coord_cartesian(ylim = c(-2, 2))


# Compare to `qqconf`
qqconf::qq_conf_plot(rstandard(m))
#> no dparams supplied. Estimating parameters from the data...

pp-plots with the new "ell" default

check_normality(m) |> plot(type = "pp")


# Compare to `qqconf`
qqconf::pp_conf_plot(rstandard(m))
#> no dparams supplied. Estimating parameters from the data...

Created on 2023-07-20 with reprex v2.0.2

mattansb commented 1 year ago

@strengejacke Should we change the default plot type to type = "qq"?

strengejacke commented 1 year ago

@strengejacke Should we change the default plot type to type = "qq"?

I think we had a reason to default to "pp" (though it was more like a choice of personal preference). For check_model(), we default to qq anyway. So, yes, maybe we can change the default plot type. But this needs to be done in performance?

bwiernik commented 1 year ago

I changed the default to "qq" here as suggested. I also updated the detrend argument to be TRUE by default when qqplotr is installed; detrending is generally recommended because it makes it easier to compare distances from the line in the tails.

I'll open a similar PR in performance.

I'm good with the PR now. Ready to merge?

mattansb commented 1 year ago

Yes, I think so. Not sure there is anything to update in performance though.

mattansb commented 1 year ago

Actually, we can also detrend without qqplotr. I'll make a commit.

mattansb commented 1 year ago

Okay, detrend now works without qqplotr:

m <- lm(mpg ~ wt + cyl + gear + disp, data = mtcars)
result <- performance::check_normality(m)

plot(result)
#> For confidence bands, please install `qqplotr`.

Created on 2023-07-23 with reprex v2.0.2

(And also with)

m <- lm(mpg ~ wt + cyl + gear + disp, data = mtcars)
result <- performance::check_normality(m)

plot(result)

Created on 2023-07-23 with reprex v2.0.2

bwiernik commented 1 year ago

Perfect! Can you change the PR on performance linked above to have detrend = TRUE on check_model?

mattansb commented 1 year ago

Done!

strengejacke commented 1 year ago

Can this be merged?

bwiernik commented 1 year ago

Yep

strengejacke commented 1 year ago

hm, this code line

ggplot2::aes(y = ggplot2::after_stat("sample") - ggplot2::after_stat("theoretical"))

worked on one computer, but not on the other one and tests also fail. The line was

ggplot2::aes(y = ggplot2::after_stat(sample) - ggplot2::after_stat(theoretical))

(i.e. no quotes), but this gave the "undefined global vars" issue. Any idea how to handle this?

bwiernik commented 1 year ago

after_stat(.data$sample), etc

I think we do already, but if not, we also need to import .data from rlang or ggplot2

strengejacke commented 1 year ago

I think we can't use the data pronoun here, because sample and theoretical refer to functions, not variables. But adding .. worked: ..sample...

bwiernik commented 1 year ago

They aren't functions, they are columns of the data frame returned after by stat function. The ..sample.. syntax is deprecated and shouldn't be used.