Function `audit`

create modelAudit object for further validation of a model.
Models may have very different structures. This function creates a unified representation of a model and calculates residuals,
which can be further processed by various error analysis functions.

audit(object, data = NULL, y = NULL, predict.function = yhat,
residual.function = NULL, label = NULL)

## Arguments

object |
An object containing a model or object of class explainer (see `explain` ). |

data |
Data.frame or matrix - data that will be used by further validation functions. If not provided, will be extracted from the model. |

y |
Response vector that will be used by further validation functions. Some functions may require an integer vector containing binary labels with values 0,1. If not provided, will be extracted from the model. |

predict.function |
Function that takes two arguments: model and data. It should return a numeric vector with predictions. |

residual.function |
Function that takes three arguments: model, data and response vector. It should return a numeric vector with model residuals for given data. If not provided, response residuals (\(y-\hat{y}\)) are calculated. |

label |
Character - the name of the model. By default it's extracted from the 'class' attribute of the model. |

## Value

An object of class ModelAudit, which contains:
#'

`model.class`

class of the audited model,

`label`

the name of the model,

`model`

the audited model,

`fitted.values`

fitted values from model,

`data`

data used for fitting the model,

`y`

vector with values of predicted variable used for fitting the model,

`predict.function`

function that were used for model predictions,

`residual.function`

function that were used for calculating model residuals,

`residuals`

`std.residuals`

standardized residuals - the residuals divided by theirs standard deviation.

## Examples

library(MASS)
model.glm <- glm(Postwt ~ Prewt + Treat + offset(Prewt), family = gaussian, data = anorexia)
audit.glm <- audit(model.glm)
p.fun <- function(model, data){predict(model, data, response = "link")}
audit.glm.newpred <- audit(model.glm, predict.function = p.fun)
library(randomForest)

#> randomForest 4.6-14

#> Type rfNews() to see new features/changes/bug fixes.