View source: R/plot_cooksdistance.R
plot_cooksdistance | R Documentation |
Plot of Cook’s distances used for estimate the influence of an single observation.
plot_cooksdistance(object, ..., nlabel = 3)
plotCooksDistance(object, ..., nlabel = 3)
object |
An object of class |
... |
Other objects of class |
nlabel |
Number of observations with the biggest Cook's distances to be labeled. |
Cook’s distance is a tool for identifying observations that may negatively affect the model. They may be also used for indicating regions of the design space where it would be good to obtain more observations. Data points indicated by Cook’s distances are worth checking for validity.
Cook’s Distances are calculated by removing the i-th observation from the data and recalculating the model. It shows how much all the values in the model change when the i-th observation is removed.
For model classes other than lm and glm the distances are computed directly from the definition.
A ggplot object.
Cook, R. Dennis (1977). "Detection of Influential Observations in Linear Regression". doi:10.2307/1268249.
dragons <- DALEX::dragons[1:100, ]
# fit a model
model_lm <- lm(life_length ~ ., data = dragons)
lm_audit <- audit(model_lm, data = dragons, y = dragons$life_length)
# validate a model with auditor
library(auditor)
cd_lm <- model_cooksdistance(lm_audit)
# plot results
plot_cooksdistance(cd_lm)
plot(cd_lm, type = "cooksdistance")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.