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

Improved q-q plot error bands #299

Merged
merged 10 commits into from
Aug 30, 2023
Merged

Improved q-q plot error bands #299

merged 10 commits into from
Aug 30, 2023

Conversation

mattansb
Copy link
Member

Closes easystats/performance#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

R/plot.check_normality.R Outdated Show resolved Hide resolved
R/plot.check_normality.R Show resolved Hide resolved
@mattansb
Copy link
Member Author

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

@strengejacke
Copy link
Member

@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?

- Make titles for p-p plots parallel to those for q-q plots
- Change default to `type = "qq"`
- Add details for the `type` argument to documentation (and add similar details for functions that previously imported the `type` argument from `plot.see_check_normality`
@bwiernik
Copy link
Contributor

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?

bwiernik added a commit to easystats/performance that referenced this pull request Jul 23, 2023
Also change default to `verbose = FALSE`
@mattansb
Copy link
Member Author

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

@mattansb
Copy link
Member Author

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

@mattansb
Copy link
Member Author

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
Copy link
Contributor

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

@mattansb
Copy link
Member Author

Done!

@strengejacke
Copy link
Member

Can this be merged?

@bwiernik
Copy link
Contributor

Yep

@strengejacke strengejacke merged commit b32cec8 into main Aug 30, 2023
17 of 26 checks passed
@strengejacke strengejacke deleted the ell-bands branch August 30, 2023 16:11
@strengejacke
Copy link
Member

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
Copy link
Contributor

bwiernik commented Aug 30, 2023

after_stat(.data$sample), etc

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

@strengejacke
Copy link
Member

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

@bwiernik
Copy link
Contributor

bwiernik commented Aug 31, 2023

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.

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

Successfully merging this pull request may close these issues.

Improved q-q plot error bands?
3 participants