Learn R Programming

auditor (version 0.3.0)

audit: Create modelAudit object

Description

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.

Usage

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

Run this code
# NOT RUN {
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)
model.rf <- randomForest(Species ~ ., data=iris)
audit.rf <- audit(model.rf)

# }

Run the code above in your browser using DataLab