diff --git a/DESCRIPTION b/DESCRIPTION index 6baa79c9..31f789bd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,14 +1,13 @@ Package: auditor -Title: Model audit - verification, validation, and error analysis +Title: Model Audit - Verification, Validation, and Error Analysis Version: 0.2.0 Authors@R: c( person("Alicja", "Gosiewska", , "alicjagosiewska@gmail.com", role = c("aut", "cre")), person("Przemyslaw", "Biecek", role = c("aut", "ths")) ) -Description: The 'auditor' package provides an easy to use unified interface for creating validation - plots for any model. This visualizations allow to asses and compare the goodness of fit, performance, - and similarity of models. The auditor help statisticians, data scientists, and researchers can avoid - repetitive work consisting of writing code needed to create residuals plots. +Description: Provides an easy to use unified interface for creating validation plots for any model. + The 'auditor' helps to avoid repetitive work consisting of writing code needed to create residual plots. + This visualizations allow to asses and compare the goodness of fit, performance, and similarity of models. Depends: R (>= 3.0.0) License: GPL Encoding: UTF-8 diff --git a/NEWS.md b/NEWS.md index 63284e8e..114016bd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# version 0.2.0 +# version 0.2.0 - released on CRAN ## 07/05.2019 - new plot functions: `plotLift()`, `plotCumulativeGain()`, `plotTwoSidedECDF()`, `plotModelCorrelation()`, `plotResidualDensity()`, `plotModelPCA()`, plotPrediction()`, plotModelRanking()` @@ -10,6 +10,7 @@ - `variable = NULL` parameter in `scoreDW()`, `scoreRuns()`, plotAutocorrelation()`, `plotACF()` causes the residuals to be not sorted by any variable - densities in `plotResidualDensity()` may be now separated by variable values - for function `score()` parameter `score` is renamed into `type` +- new examples # version 0.1.1.0000 ## 09/03/2018 diff --git a/R/audit.R b/R/audit.R index a9694e91..6a622eb3 100644 --- a/R/audit.R +++ b/R/audit.R @@ -18,7 +18,7 @@ #' \item \code{model} the audited model, #' \item \code{fitted.values} fitted values from model, #' \item \code{data} data used for fitting the model, -#' \item \code{y} vecor with values of predicted variable used for fittng the model, +#' \item \code{y} vector with values of predicted variable used for fitting the model, #' \item \code{predict.function} function that were used for model predictions, #' \item \code{residual.function} function that were used for calculating model residuals, #' \item \code{residuals} diff --git a/R/plotACF.R b/R/plotACF.R index 31f74f08..d4b380b3 100644 --- a/R/plotACF.R +++ b/R/plotACF.R @@ -8,6 +8,19 @@ #' @param variable Name of model variable to order residuals. If value is NULL data order is taken. If value is "Predicted response" or "Fitted values" then data is ordered by fitted values. If value is "Observed response" the data is ordered by a vector of actual response (\code{y} parameter passed to the \code{\link{audit}} function). #' @param alpha Confidence level of the interval. #' +#' +#' @examples +#' library(car) +#' lm_model <- lm(prestige~education + women + income, data = Prestige) +#' lm_au <- audit(lm_model, data = Prestige, y = Prestige$prestige) +#' plotACF(lm_au) +#' +#' library(randomForest) +#' rf_model <- randomForest(prestige~education + women + income, data = Prestige) +#' rf_au <- audit(rf_model, data = Prestige, y = Prestige$prestige) +#' plotACF(lm_au, rf_au) +#' +#' #' @import ggplot2 #' @importFrom stats qnorm acf #' diff --git a/R/plotAutocorrelation.R b/R/plotAutocorrelation.R index e8a2478a..91f628f1 100644 --- a/R/plotAutocorrelation.R +++ b/R/plotAutocorrelation.R @@ -7,6 +7,12 @@ #' @param variable Name of model variable to order residuals. If value is NULL data order is taken. If value is "Predicted response" or "Fitted values" then data is ordered by fitted values. If value is "Observed response" the data is ordered by a vector of actual response (\code{y} parameter passed to the \code{\link{audit}} function). #' @param score Logical, if TRUE values of \link{scoreDW} and \link{scoreRuns} will be added to plot. #' +#' @examples +#' library(car) +#' lm_model <- lm(prestige~education + women + income, data = Prestige) +#' lm_au <- audit(lm_model, data = Prestige, y = Prestige$prestige) +#' plotAutocorrelation(lm_au) +#' #' @import ggplot2 #' #' @export diff --git a/R/plotCooksDistance.R b/R/plotCooksDistance.R index a45ca7f9..04af998c 100644 --- a/R/plotCooksDistance.R +++ b/R/plotCooksDistance.R @@ -16,6 +16,14 @@ #' #' For model classes other than lm and glm the distances are computed directly from the definition. #' +#' +#' +#' @examples +#' library(car) +#' lm_model <- lm(prestige~education + women + income, data = Prestige) +#' lm_au <- audit(lm_model, data = Prestige, y = Prestige$prestige) +#' plotCooksDistance(lm_au) +#' #' @import ggplot2 #' #' @export diff --git a/R/plotCumulativeGain.R b/R/plotCumulativeGain.R index a62f8878..74e19d52 100644 --- a/R/plotCumulativeGain.R +++ b/R/plotCumulativeGain.R @@ -1,6 +1,6 @@ #' @title Cumulative Gain Chart #' -#' @description Cumulative Gain Chartis is a plot of the rate of positive prediction against true positive rate for the different thresholds. +#' @description Cumulative Gain Chart is is a plot of the rate of positive prediction against true positive rate for the different thresholds. #' It is useful for measuring and comparing the accuracy of the classificators. #' @param object An object of class ModelAudit. #' @param ... Other modelAudit objects to be plotted together. @@ -9,6 +9,15 @@ #' #' @seealso \code{\link{plot.modelAudit}} #' +#' @examples +#' library(mlbench) +#' data("PimaIndiansDiabetes") +#' Pima <- PimaIndiansDiabetes +#' Pima$diabetes <- ifelse(Pima$diabetes == "pos", 1, 0) +#' glm_model <- glm(diabetes~., family=binomial, data=Pima) +#' glm_au <- audit(glm_model, data = Pima, y = Pima$diabetes) +#' plotCumulativeGain(glm_au) +#' #' @import ggplot2 #' @importFrom ROCR performance prediction #' diff --git a/R/plotHalfNormal.R b/R/plotHalfNormal.R index 25baa993..1fc6be71 100644 --- a/R/plotHalfNormal.R +++ b/R/plotHalfNormal.R @@ -8,7 +8,7 @@ #' #' @param object ModelAudit object, fitted model object or numeric vector. #' @param score If TRUE score based on probability density function is displayed on the plot. -#' @param quant.scale if TRUE values on avis are on quantile scale. +#' @param quant.scale if TRUE values on axis are on quantile scale. #' @param main Title of plot. #' @param xlab The text for the x axis. #' @param ylab The text for the y axis. diff --git a/R/plotLift.R b/R/plotLift.R index a86823d9..0944fec9 100644 --- a/R/plotLift.R +++ b/R/plotLift.R @@ -11,6 +11,15 @@ #' #' @return ggplot object #' +#' @examples +#' library(mlbench) +#' data("PimaIndiansDiabetes") +#' Pima <- PimaIndiansDiabetes +#' Pima$diabetes <- ifelse(Pima$diabetes == "pos", 1, 0) +#' glm_model <- glm(diabetes~., family=binomial, data=Pima) +#' glm_au <- audit(glm_model, data = Pima, y = Pima$diabetes) +#' plotLIFT(glm_au) +#' #' @seealso \code{\link{plot.modelAudit}} #' #' @import ggplot2 diff --git a/R/plotModelCorrelation.R b/R/plotModelCorrelation.R index 0f00204a..d3ff473e 100644 --- a/R/plotModelCorrelation.R +++ b/R/plotModelCorrelation.R @@ -8,6 +8,15 @@ #' #' @return ggplot object #' +#' @examples +#' library(car) +#' lm_model <- lm(prestige~education + women + income, data = Prestige) +#' lm_au <- audit(lm_model, data = Prestige, y = Prestige$prestige) +#' library(randomForest) +#' rf_model <- randomForest(prestige~education + women + income, data = Prestige) +#' rf_au <- audit(rf_model, data = Prestige, y = Prestige$prestige) +#' plotModelCorrelation(lm_au, rf_au) +#' #' @seealso \code{\link{plot.modelAudit}} #' #' @import ggplot2 diff --git a/R/plotModelPCA.R b/R/plotModelPCA.R index a00d692f..7bcf2aa0 100644 --- a/R/plotModelPCA.R +++ b/R/plotModelPCA.R @@ -5,11 +5,20 @@ #' #' @param object An object of class ModelAudit, #' @param ... Other modelAudit objects to be plotted together. -#' @param scale A logical value indicating whether the models residuals should be scaled bfore the analysis. +#' @param scale A logical value indicating whether the models residuals should be scaled before the analysis. #' @param invisible A text specifying the elements to be hidden on the plot. Default value is "none". Allowed values are "model", "observ". #' #' @return ggplot object #' +#' @examples +#' library(car) +#' lm_model <- lm(prestige~education + women + income, data = Prestige) +#' lm_au <- audit(lm_model, data = Prestige, y = Prestige$prestige) +#' library(randomForest) +#' rf_model <- randomForest(prestige~education + women + income, data = Prestige) +#' rf_au <- audit(rf_model, data = Prestige, y = Prestige$prestige) +#' plotModelPCA(lm_au, rf_au) +#' #' @seealso \code{\link{plot.modelAudit}} #' #' @import ggplot2 diff --git a/R/plotModelRanking.R b/R/plotModelRanking.R index 3c492a0d..5c83aca2 100644 --- a/R/plotModelRanking.R +++ b/R/plotModelRanking.R @@ -9,6 +9,15 @@ #' #' @return ggplot object #' +#' @examples +#' library(car) +#' lm_model <- lm(prestige~education + women + income, data = Prestige) +#' lm_au <- audit(lm_model, data = Prestige, y = Prestige$prestige) +#' library(randomForest) +#' rf_model <- randomForest(prestige~education + women + income, data = Prestige) +#' rf_au <- audit(rf_model, data = Prestige, y = Prestige$prestige) +#' plotModelRanking(lm_au, rf_au) +#' #' @seealso \code{\link{plot.modelAudit}} #' #' @import ggplot2 diff --git a/R/plotPrediction.R b/R/plotPrediction.R index de04e17d..444c197b 100644 --- a/R/plotPrediction.R +++ b/R/plotPrediction.R @@ -7,6 +7,17 @@ #' @param ... Other modelAudit objects to be plotted together. #' @param variable Name of model variable to order residuals. If value is NULL data order is taken. If value is "Observed response" the data is ordered by a vector of actual response (\code{y} parameter passed to the \code{\link{audit}} function). #' +#' @examples +#' library(car) +#' lm_model <- lm(prestige~education + women + income, data = Prestige) +#' lm_au <- audit(lm_model, data = Prestige, y = Prestige$prestige) +#' plotPrediction(lm_au) +#' +#' library(randomForest) +#' rf_model <- randomForest(prestige~education + women + income, data = Prestige) +#' rf_au <- audit(rf_model, data = Prestige, y = Prestige$prestige) +#' plotPrediction(lm_au, rf_au) +#' #' @seealso \code{\link{plot.modelAudit}} #' #' @import ggplot2 diff --git a/R/plotREC.R b/R/plotREC.R index b3a49188..0f47eef3 100644 --- a/R/plotREC.R +++ b/R/plotREC.R @@ -19,17 +19,15 @@ #' @seealso \code{\link{plot.modelAudit}, \link{plotROC}, \link{plotRROC}} #' #' @examples -#' library(auditor) -#' library(randomForest) #' library(car) -#' model_lm <- lm(prestige ~ education + women + income, data = Prestige) -#' audit_lm <- audit(model_lm) -#' -#' plotREC(audit_lm) +#' lm_model <- lm(prestige~education + women + income, data = Prestige) +#' lm_au <- audit(lm_model, data = Prestige, y = Prestige$prestige) +#' plotREC(lm_au) #' -#' model_rf <- randomForest(prestige ~ education + women + income, data = Prestige) -#' audit_rf <- audit(model_rf) -#' plotREC(audit_lm, audit_rf) +#' library(randomForest) +#' rf_model <- randomForest(prestige~education + women + income, data = Prestige) +#' rf_au <- audit(rf_model, data = Prestige, y = Prestige$prestige) +#' plotREC(lm_au, rf_au) #' #' #' @export diff --git a/R/plotROC.R b/R/plotROC.R index d5f5d520..3c2a6948 100644 --- a/R/plotROC.R +++ b/R/plotROC.R @@ -14,17 +14,13 @@ #' @import plotROC #' #' @examples -#' library(auditor) #' library(mlbench) #' data("PimaIndiansDiabetes") -#' -#' model.glm <- glm(diabetes~., family=binomial, data=PimaIndiansDiabetes) -#' au.glm <- audit(model.glm, label="class glm") -#' plotROC(au.glm) -#' -#' model.glm.press <- glm(diabetes~pressure, family=binomial, data=PimaIndiansDiabetes) -#' au.glm.press <- audit(model.glm.press) -#' plotROC(au.glm, au.glm.press) +#' Pima <- PimaIndiansDiabetes +#' Pima$diabetes <- ifelse(Pima$diabetes == "pos", 1, 0) +#' glm_model <- glm(diabetes~., family=binomial, data=Pima) +#' glm_au <- audit(glm_model, data = Pima, y = Pima$diabetes) +#' plotROC(glm_au) #' #' @export diff --git a/R/plotRROC.R b/R/plotRROC.R index 7da0aaf6..fe1cabc8 100644 --- a/R/plotRROC.R +++ b/R/plotRROC.R @@ -9,11 +9,11 @@ #' #' @return ggplot object #' -#' @details For RROC curves we use a shift, which is an equvalent to the threshold for ROC curves. +#' @details For RROC curves we use a shift, which is an equivalent to the threshold for ROC curves. #' For each observation we calculate new prediction: \eqn{\hat{y}'=\hat{y}+s} where s is the shift. #' Therefore, there are different error values for each shift: \eqn{e_i = \hat{y_i}' - y_i} #' -#' Over-estimation is caluclates as: \eqn{OVER= \sum(e_i|e_i>0)}. +#' Over-estimation is calculated as: \eqn{OVER= \sum(e_i|e_i>0)}. #' #' Under-estimation is calculated as: \eqn{UNDER = \sum(e_i|e_i<0)}. #' @@ -27,17 +27,15 @@ #' #' #' @examples -#' library(auditor) -#' library(randomForest) #' library(car) -#' model_lm <- lm(prestige ~ education + women + income, data = Prestige) -#' audit_lm <- audit(model_lm) -#' -#' plotRROC(audit_lm) +#' lm_model <- lm(prestige~education + women + income, data = Prestige) +#' lm_au <- audit(lm_model, data = Prestige, y = Prestige$prestige) +#' plotRROC(lm_au) #' -#' model_rf <- randomForest(prestige ~ education + women + income, data = Prestige) -#' audit_rf <- audit(model_rf) -#' plotRROC(audit_lm, audit_rf) +#' library(randomForest) +#' rf_model <- randomForest(prestige~education + women + income, data = Prestige) +#' rf_au <- audit(rf_model, data = Prestige, y = Prestige$prestige) +#' plotRROC(lm_au, rf_au) #' #' @import ggplot2 #' diff --git a/R/plotResidual.R b/R/plotResidual.R index 534d0f04..1dfdec98 100644 --- a/R/plotResidual.R +++ b/R/plotResidual.R @@ -6,6 +6,17 @@ #' @param variable Name of model variable to order residuals. If value is NULL data order is taken. If value is "Predicted response" or "Fitted values" then data is ordered by fitted values. If value is "Observed response" the data is ordered by a vector of actual response (\code{y} parameter passed to the \code{\link{audit}} function). #' @param ... Other modelAudit objects to be plotted together. #' +#' @examples +#' library(car) +#' lm_model <- lm(prestige~education + women + income, data = Prestige) +#' lm_au <- audit(lm_model, data = Prestige, y = Prestige$prestige) +#' plotResidual(lm_au) +#' +#' library(randomForest) +#' rf_model <- randomForest(prestige~education + women + income, data = Prestige) +#' rf_au <- audit(rf_model, data = Prestige, y = Prestige$prestige) +#' plotResidual(lm_au, rf_au) +#' #' @seealso \code{\link{plot.modelAudit}} #' #' @import ggplot2 diff --git a/R/plotResidualDensity.R b/R/plotResidualDensity.R index 184ad226..55cc9a06 100644 --- a/R/plotResidualDensity.R +++ b/R/plotResidualDensity.R @@ -8,6 +8,17 @@ #' #' @return ggplot object #' +#' @examples +#' library(car) +#' lm_model <- lm(prestige~education + women + income, data = Prestige) +#' lm_au <- audit(lm_model, data = Prestige, y = Prestige$prestige) +#' plotResidualDensity(lm_au) +#' +#' library(randomForest) +#' rf_model <- randomForest(prestige~education + women + income, data = Prestige) +#' rf_au <- audit(rf_model, data = Prestige, y = Prestige$prestige) +#' plotResidualDensity(lm_au, rf_au) +#' #' @seealso \code{\link{plot.modelAudit}} #' #' @import ggplot2 diff --git a/R/plotScaleLocation.R b/R/plotScaleLocation.R index 7bc50536..b85c3d56 100644 --- a/R/plotScaleLocation.R +++ b/R/plotScaleLocation.R @@ -8,6 +8,13 @@ #' @param variable Name of model variable to order residuals. If value is NULL data order is taken. If value is "Predicted response" or "Fitted values" then data is ordered by fitted values. If value is "Observed response" the data is ordered by a vector of actual response (\code{y} parameter passed to the \code{\link{audit}} function). #' @param score A logical value. If TRUE value of \link{scoreGQ} will be added. #' +#' @examples +#' library(car) +#' lm_model <- lm(prestige~education + women + income, data = Prestige) +#' lm_au <- audit(lm_model, data = Prestige, y = Prestige$prestige) +#' plotScaleLocation(lm_au) +#' +#' #' @import ggplot2 #' @importFrom stats median #' diff --git a/R/plotTwoSidedECDF.R b/R/plotTwoSidedECDF.R index cda5cc3d..cc92acc8 100644 --- a/R/plotTwoSidedECDF.R +++ b/R/plotTwoSidedECDF.R @@ -11,6 +11,17 @@ #' #' @return ggplot object #' +#' @examples +#' library(car) +#' lm_model <- lm(prestige~education + women + income, data = Prestige) +#' lm_au <- audit(lm_model, data = Prestige, y = Prestige$prestige) +#' plotTwoSidedECDF(lm_au) +#' +#' library(randomForest) +#' rf_model <- randomForest(prestige~education + women + income, data = Prestige) +#' rf_au <- audit(rf_model, data = Prestige, y = Prestige$prestige) +#' plotTwoSidedECDF(lm_au, rf_au, y.reversed = TRUE) +#' #' @seealso \code{\link{plot.modelAudit}} #' #' @import ggplot2 diff --git a/R/plot_ModelAudit.R b/R/plot_ModelAudit.R index 1c5f4c8d..15a8491a 100644 --- a/R/plot_ModelAudit.R +++ b/R/plot_ModelAudit.R @@ -3,17 +3,29 @@ #' @description This function provides several diagnostic plots for regression and classification models. #' #' @param x object of class modelAudit -#' @param ... other arguments dependent on the type of plot or additionam objects of class modelAudit +#' @param ... other arguments dependent on the type of plot or additionl objects of class modelAudit #' @param type the type of plot. Possible values: 'ACF', 'Autocorrelation', 'CumulativeGain', 'CooksDistance', 'HalfNormal', 'Residuals', 'LIFT', -#' ModelPCA', 'ModelCorreltion', 'Prediction', 'REC', 'ResidualDensity', 'Residual', 'ROC', 'RROC', -#' ScaleLocation', 'TwoSidedECDF' (for detailed description see functions in seealso section). +#' ModelPCA', 'ModelRanking', ModelCorrelation', 'Prediction', 'REC', 'ResidualDensity', 'Residual', 'ROC', 'RROC', +#' ScaleLocation', 'TwoSidedECDF' (for detailed description see functions in see also section). #' @param ask logical; if TRUE, the user is asked before each plot, see \code{\link[graphics]{par}(ask=)}. #' #' @seealso \code{\link{plotACF}, \link{plotAutocorrelation}, \link{plotCumulativeGain}, \link{plotCooksDistance}, -#' \link{plotHalfNormal}, \link{plotResidual}, \link{plotLIFT}, \link{plotModelPCA}, \link{plotModelCorrelation}, +#' \link{plotHalfNormal}, \link{plotResidual}, \link{plotLIFT}, \link{plotModelPCA}, \link{plotModelRanking}, \link{plotModelCorrelation}, #' \link{plotPrediction}, \link{plotREC}, \link{plotResidualDensity}, \link{plotResidual}, \link{plotROC}, #' \link{plotRROC}, \link{plotScaleLocation}, \link{plotTwoSidedECDF}} #' +#' @examples +#' library(car) +#' lm_model <- lm(prestige~education + women + income, data = Prestige) +#' lm_au <- audit(lm_model, data = Prestige, y = Prestige$prestige) +#' plot(lm_au) +#' +#' library(randomForest) +#' rf_model <- randomForest(prestige~education + women + income, data = Prestige) +#' rf_au <- audit(rf_model, data = Prestige, y = Prestige$prestige) +#' plot(lm_au, rf_au, type = "ModelRanking") +#' +#' #' @importFrom grDevices devAskNewPage #' @importFrom graphics plot #' @@ -26,7 +38,7 @@ plot.modelAudit <- function(x, ..., type="Residual", ask = TRUE){ object <- x plotNames <- c('ACF', 'Autocorrelation', 'CumulativeGain', 'CooksDistance', 'HalfNormal', 'Residual', 'LIFT', - 'ModelPCA', 'ModelCorrelation', 'Prediction', 'REC', 'ResidualDensity', 'Residuals', 'ROC', 'RROC', + 'ModelPCA', 'ModelRanking', 'ModelCorrelation', 'Prediction', 'REC', 'ResidualDensity', 'Residuals', 'ROC', 'RROC', 'ScaleLocation', 'TwoSidedECDF') if(!all(type %in% plotNames)){ @@ -61,6 +73,7 @@ plotTypePlot <- function(x, ..., type){ HalfNormal = { return(plotHalfNormal(x, ...)) }, LIFT = {return(plotLIFT(x, ...))}, ModelPCA = {return(plotModelPCA(x, ...))}, + ModelRanking = {return(plotModelRanking(x, ...))}, ModelCorrelation = {return(plotModelCorrelation(x, ...))}, Prediction = {return(plotPrediction(x, ...))}, REC = { return(plotREC(x, ...)) }, diff --git a/R/score.R b/R/score.R index ba715d98..335d5773 100644 --- a/R/score.R +++ b/R/score.R @@ -5,13 +5,19 @@ #' #' @param object Object An object of class modelAudit. #' @param type The type of score to be calculated. Possible values: 'Cook', 'DW', 'GQ', 'HalfNormal', 'MAE', 'MSE', 'REC', 'RMSE', 'ROC', 'RROC', 'Runs' -#' (for detailed description see functions in seealso section). +#' (for detailed description see functions in see also section). #' @param ... Other arguments dependent on the type of score. #' #' @seealso \code{\link{scoreCooksDistance}, \link{scoreDW}, \link{scoreGQ}, \link{scoreHalfNormal}, \link{scoreMAE}, \link{scoreMSE}, \link{scoreREC}, \link{scoreROC}, \link{scoreRROC}, \link{scoreRuns}} #' #' @return an object of class scoreAudit, except Cooks distance, where numeric vector is returned #' +#' @examples +#' library(car) +#' lm_model <- lm(prestige~education + women + income, data = Prestige) +#' lm_au <- audit(lm_model, data = Prestige, y = Prestige$prestige) +#' score(lm_au, type = 'Runs') +#' #' @export score <- function(object, type = 'MSE', ...){ diff --git a/R/scoreCooksDistance.R b/R/scoreCooksDistance.R index 42872098..0111301a 100644 --- a/R/scoreCooksDistance.R +++ b/R/scoreCooksDistance.R @@ -15,6 +15,13 @@ #' Models of classes other than lm and glm the distances are computed directly from the definition, #' so this may take a while. #' +#' @examples +#' library(car) +#' lm_model <- lm(prestige~education + women + income, data = Prestige) +#' lm_au <- audit(lm_model, data = Prestige, y = Prestige$prestige) +#' scoreCooksDistance(lm_au) +#' +#' #' @importFrom stats cooks.distance update #' #' @seealso \code{\link{score}} diff --git a/R/scoreDW.R b/R/scoreDW.R index 144be8a0..2994aead 100644 --- a/R/scoreDW.R +++ b/R/scoreDW.R @@ -1,12 +1,19 @@ #' @title Durbin-Watson Score #' #' @description Score based on Durbin-Watson test statistic. -#' The score value is helpful in comparing models. It is worth ponting out that results of tests like p-value makes sense only +#' The score value is helpful in comparing models. It is worth pointing out that results of tests like p-value makes sense only #' when the test assumptions are satisfied. Otherwise test statistic may be considered as a score. #' #' @param object object An object of class ModelAudit #' @param variable Name of model variable to order residuals. If value is NULL data order is taken. If value is "Predicted response" or "Fitted values" then data is ordered by fitted values. If value is "Observed response" the data is ordered by a vector of actual response (\code{y} parameter passed to the \code{\link{audit}} function). #' +#' @examples +#' library(car) +#' lm_model <- lm(prestige~education + women + income, data = Prestige) +#' lm_au <- audit(lm_model, data = Prestige, y = Prestige$prestige) +#' scoreDW(lm_au) +#' +#' #' @importFrom car durbinWatsonTest #' #' @return an object of class scoreAudit diff --git a/R/scoreGQ.R b/R/scoreGQ.R index b6b94846..1b24a68f 100644 --- a/R/scoreGQ.R +++ b/R/scoreGQ.R @@ -11,13 +11,19 @@ #' where \eqn{MSE = (RSS)/(n-p)} #' where n is the number of observations and p is the number of variables . #' -#' The score value is helpful in comparing models. It is worth ponting out that results of tests like p-value makes sense only +#' The score value is helpful in comparing models. It is worth pointing out that results of tests like p-value makes sense only #' when the test assumptions are satisfied. Otherwise test statistic may be considered as a score. #' \code{scoreGQ} function uses a two-sided F-test. #' #' @param object Object An object of class ModelAudit. #' @param variable Name of model variable to order residuals. If value is NULL data order is taken. If value is "Predicted response" or "Fitted values" then data is ordered by fitted values. If value is "Observed response" the data is ordered by a vector of actual response (\code{y} parameter passed to the \code{\link{audit}} function). #' +#' @examples +#' library(car) +#' lm_model <- lm(prestige~education + women + income, data = Prestige) +#' lm_au <- audit(lm_model, data = Prestige, y = Prestige$prestige) +#' scoreGQ(lm_au) +#' #' @importFrom stats update rstandard predict pf sd #' #' @return an object of class scoreAudit diff --git a/R/scoreHalfNormal.R b/R/scoreHalfNormal.R index 894a4910..65d14ba2 100644 --- a/R/scoreHalfNormal.R +++ b/R/scoreHalfNormal.R @@ -10,6 +10,13 @@ #' @param object ModelAudit object or fitted model. #' @param ... Extra arguments passed to \link[hnp]{hnp}. #' +#' @examples +#' library(car) +#' lm_model <- lm(prestige~education + women + income, data = Prestige) +#' lm_au <- audit(lm_model, data = Prestige, y = Prestige$prestige) +#' plotHalfNormal(lm_au) +#' +#' #' @importFrom hnp hnp #' #' @export diff --git a/R/scoreMAE.R b/R/scoreMAE.R index 741e0777..0ddad656 100644 --- a/R/scoreMAE.R +++ b/R/scoreMAE.R @@ -6,6 +6,13 @@ #' #' @return an object of class scoreAudit #' +#' @examples +#' library(car) +#' lm_model <- lm(prestige~education + women + income, data = Prestige) +#' lm_au <- audit(lm_model, data = Prestige, y = Prestige$prestige) +#' scoreMAE(lm_au) +#' +#' #' @seealso \code{\link{score}} #' #' @export diff --git a/R/scoreMSE.R b/R/scoreMSE.R index 18b4dc4d..2b1b1569 100644 --- a/R/scoreMSE.R +++ b/R/scoreMSE.R @@ -6,6 +6,12 @@ #' #' @return an object of class scoreAudit #' +#' @examples +#' library(car) +#' lm_model <- lm(prestige~education + women + income, data = Prestige) +#' lm_au <- audit(lm_model, data = Prestige, y = Prestige$prestige) +#' scoreMSE(lm_au) +#' #' @seealso \code{\link{score}} #' #' @export diff --git a/R/scoreREC.R b/R/scoreREC.R index cd39fc25..1c8be5d4 100644 --- a/R/scoreREC.R +++ b/R/scoreREC.R @@ -7,6 +7,13 @@ #' #' @return an object of class scoreAudit #' +#' @examples +#' library(car) +#' lm_model <- lm(prestige~education + women + income, data = Prestige) +#' lm_au <- audit(lm_model, data = Prestige, y = Prestige$prestige) +#' scoreREC(lm_au) +#' +#' #' @seealso \code{\link{plotREC}} #' #' @references J. Bi, and K. P. Bennet, "Regression error characteristic curves," in Proc. 20th Int. Conf. Machine Learning, Washington DC, 2003, pp. 43-50 diff --git a/R/scoreRMSE.R b/R/scoreRMSE.R index fcd9a4c1..fb74c03a 100644 --- a/R/scoreRMSE.R +++ b/R/scoreRMSE.R @@ -6,6 +6,13 @@ #' #' @return an object of class scoreAudit #' +#' @examples +#' library(car) +#' lm_model <- lm(prestige~education + women + income, data = Prestige) +#' lm_au <- audit(lm_model, data = Prestige, y = Prestige$prestige) +#' scoreRMSE(lm_au) +#' +#' #' @seealso \code{\link{score}} #' #' @export diff --git a/R/scoreROC.R b/R/scoreROC.R index 9e871e5b..9b097282 100644 --- a/R/scoreROC.R +++ b/R/scoreROC.R @@ -5,6 +5,15 @@ #' #' @return an object of class scoreAudit #' +#' @examples +#' library(mlbench) +#' data("PimaIndiansDiabetes") +#' Pima <- PimaIndiansDiabetes +#' Pima$diabetes <- ifelse(Pima$diabetes == "pos", 1, 0) +#' glm_model <- glm(diabetes~., family=binomial, data=Pima) +#' glm_au <- audit(glm_model, data = Pima, y = Pima$diabetes) +#' scoreROC(glm_au) +#' #' @seealso \code{\link{plotROC}} #' #' @importFrom ROCR performance prediction diff --git a/R/scoreRROC.R b/R/scoreRROC.R index 7bff7241..1b988825 100644 --- a/R/scoreRROC.R +++ b/R/scoreRROC.R @@ -6,6 +6,13 @@ #' #' @return an object of class scoreAudit #' +#' @examples +#' library(car) +#' lm_model <- lm(prestige~education + women + income, data = Prestige) +#' lm_au <- audit(lm_model, data = Prestige, y = Prestige$prestige) +#' scoreRROC(lm_au) +#' +#' #' @seealso \code{\link{plotRROC}} #' #' @references Hernández-Orallo, José. 2013. ‘ROC Curves for Regression’. Pattern Recognition 46 (12): 3395–3411. diff --git a/R/scoreRuns.R b/R/scoreRuns.R index cca3a682..25506146 100644 --- a/R/scoreRuns.R +++ b/R/scoreRuns.R @@ -1,12 +1,18 @@ #' @title Runs Score #' #' @description Score based on Runs test statistic. Note that this test is not very strong. It utilizes only signs of the residuals. -#' The score value is helpful in comparing models. It is worth ponting out that results of tests like p-value makes sense only +#' The score value is helpful in comparing models. It is worth pointing out that results of tests like p-value makes sense only #' when the test assumptions are satisfied. Otherwise test statistic may be considered as a score. #' #' @param object object An object of class ModelAudit. #' @param variable name of model variable to order residuals. If value is NULL data order is taken. If value is "Predicted response" or "Fitted values" then data is ordered by fitted values. If value is "Observed response" the data is ordered by a vector of actual response (\code{y} parameter passed to the \code{\link{audit}} function). #' +#' @examples +#' library(car) +#' lm_model <- lm(prestige~education + women + income, data = Prestige) +#' lm_au <- audit(lm_model, data = Prestige, y = Prestige$prestige) +#' scoreRuns(lm_au) +#' #' @importFrom tseries runs.test #' #' @export diff --git a/docs/articles/HalfNormal.html b/docs/articles/HalfNormal.html index 091eab60..bb3baad1 100644 --- a/docs/articles/HalfNormal.html +++ b/docs/articles/HalfNormal.html @@ -73,7 +73,7 @@
HalfNormal.Rmd
Intorduction_into_model_audit.Rmd
plotResidualDensity()
may be now separated by variable valuesscore()
parameter score
is renamed into type