Cook’s distance are used for estimate of the influence of an single observation.

score_cooksdistance(object, verbose = TRUE, ...)

scoreCooksDistance(object, verbose = TRUE)

Arguments

object

An object of class explainer created with function explain from the DALEX package.

verbose

If TRUE progress is printed.

...

Other arguments dependent on the type of score.

Value

A vector of Cook's distances for each observation.

numeric vector

Details

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.

Models of classes other than lm and glm the distances are computed directly from the definition, so this may take a while.

See also

Examples

dragons <- DALEX::dragons[1:100, ] # fit a model model_lm <- lm(life_length ~ ., data = dragons) # create an explainer lm_audit <- audit(model_lm, data = dragons, y = dragons$life_length)
#> Preparation of a new explainer is initiated #> -> model label : lm ( default ) #> -> data : 100 rows 8 cols #> -> target variable : 100 values #> -> predict function : yhat.lm will be used ( default ) #> -> predicted values : No value for predict function target column. ( default ) #> -> model_info : package stats , ver. 4.1.1 , task regression ( default ) #> -> predicted values : numerical, min = 585.8311 , mean = 1347.787 , max = 2942.307 #> -> residual function : difference between y and yhat ( default ) #> -> residuals : numerical, min = -88.41755 , mean = -1.489291e-13 , max = 77.92805 #> A new explainer has been created!
# calculate score score_cooksdistance(lm_audit)
#> 1 2 3 4 5 6 #> 1.002101e-04 3.242611e-02 1.890841e-02 5.501554e-03 6.016306e-04 2.355311e-02 #> 7 8 9 10 11 12 #> 2.544244e-01 2.244365e-02 9.949426e-03 1.355185e-04 4.031547e-02 1.108980e-03 #> 13 14 15 16 17 18 #> 3.980142e-05 1.072810e-03 2.072410e-02 7.774523e-03 1.499741e-02 1.079816e-02 #> 19 20 21 22 23 24 #> 3.721060e-04 9.496610e-03 2.568844e-03 8.295470e-03 3.258827e-04 8.065736e-03 #> 25 26 27 28 29 30 #> 3.595406e-02 1.368116e-02 2.308784e-03 1.540685e-02 2.544244e-01 1.235508e-02 #> 31 32 33 34 35 36 #> 7.682785e-03 7.881792e-03 3.943694e-03 2.008135e-02 2.207892e-03 4.927128e-03 #> 37 38 39 40 41 42 #> 5.281046e-04 8.068385e-04 5.720329e-05 2.629196e-05 1.681928e-03 3.542272e-02 #> 43 44 45 46 47 48 #> 2.176019e-03 1.554140e-03 1.760357e-02 4.797761e-03 1.212860e-03 1.888598e-02 #> 49 50 51 52 53 54 #> 3.822542e-03 1.853168e-03 5.748063e-03 2.091746e-03 1.863908e-03 6.694238e-03 #> 55 56 57 58 59 60 #> 3.503988e-02 1.055101e-03 2.668863e-03 1.496564e-03 4.308740e-04 3.997185e-03 #> 61 62 63 64 65 66 #> 1.011832e-02 1.433621e-04 3.410505e-02 2.952540e-03 1.936214e-03 5.560783e-03 #> 67 68 69 70 71 72 #> 2.522497e-02 1.145939e-03 9.089199e-04 1.669481e-04 5.150935e-03 4.677569e-03 #> 73 74 75 76 77 78 #> 1.291100e-03 1.336545e-02 8.068197e-03 1.066489e-04 4.562679e-03 3.224655e-02 #> 79 80 81 82 83 84 #> 9.624479e-03 2.080309e-03 2.207012e-02 2.222930e-02 2.143174e-03 1.402131e-06 #> 85 86 87 88 89 90 #> 4.699707e-05 7.158544e-04 1.064152e-03 3.228444e-03 2.406698e-02 5.931045e-02 #> 91 92 93 94 95 96 #> 3.000449e-04 1.630513e-02 6.890545e-03 1.010056e-02 8.270442e-03 6.660468e-02 #> 97 98 99 100 #> 9.628741e-03 3.302315e-04 1.046263e-03 3.460410e-03