sinhrks / ggfortify

Define fortify and autoplot functions to allow ggplot2 to handle some popular R packages.
Other
525 stars 65 forks source link

Switch to use range of leverages to check for constant leverage to be consistent with plot.lm() #217

Closed ZexiCAI closed 2 years ago

ZexiCAI commented 2 years ago

The original source codes for checking constant leverage are functionally different from "plot.lm" function for base plot, which essentially produces a "Constant Leverage" plot for "which=5" with many datasets (if not most of them). The proposed changes follow from the source codes of "plot.lm", which uses the range of the leverages to check for constant leverage.

terrytangyuan commented 2 years ago

Could you update the PR title as well?

ZexiCAI commented 2 years ago

Thank you for your prompt response! You may try the following codes:

test_fit1 <- lm(Sepal.Length ~ ., data=iris) autoplot(test_fit1, which=5, ncol=1) test_fit2 <- lm(Sepal.Length ~ ., data=iris[-1,]) autoplot(test_fit2, which=5, ncol=1)

We may not be expecting a huge different behavior with just the first data point removed (see attached plot). After the change, the second test plot will behave more similarly to the first plot. And in fact, the leverage of the smaller dataset is not constant, if you would have time to take a look at it. test

I am embarrassed but I am not sure about how I should update the PR title. Do you have any rules on that? You might also change the title yourself if you find it more convenient.

ZexiCAI commented 2 years ago

Thank you!