Skip to content

Commit

Permalink
adding imports and more s3classes
Browse files Browse the repository at this point in the history
  • Loading branch information
JackStat committed Sep 15, 2016
1 parent 10ebaee commit 9b4e3fe
Show file tree
Hide file tree
Showing 51 changed files with 178 additions and 150 deletions.
1 change: 1 addition & 0 deletions deprecated/normalize2Reference.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#' @importFrom stats approx
"normalize2Reference" <-
function (data, refData = NULL, ties = TRUE)
{
Expand Down
138 changes: 2 additions & 136 deletions pkg/caret/NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
useDynLib(caret)
importFrom(ModelMetrics, auc)
import(foreach, methods, plyr, reshape2, ggplot2, lattice, nlme)
importFrom(car, powerTransform, yjPower)
importFrom(grDevices, extendrange)
importFrom(stats, .checkMFClasses, .getXlevels, aggregate, anova,
approx, as.formula, binom.test, complete.cases, contrasts,

importFrom(stats,
cor, cov, delete.response, dist,
fitted.values, loess, mahalanobis,
mcnemar.test, median, model.frame, model.matrix,
Expand All @@ -18,132 +13,3 @@ importFrom(utils, capture.output, getFromNamespace, head,
install.packages, installed.packages, object.size, flush.console, menu, stack,
modifyList, combn
)


S3method(train, formula)
S3method(rfe, formula)


S3method(varImp, train)
S3method(varImp, rpart)
S3method(varImp, randomForest)
S3method(varImp, gbm)
S3method(varImp, classbagg)
S3method(varImp, regbagg)
S3method(varImp, pamrtrained)
S3method(varImp, lm)
S3method(varImp, glm)
S3method(varImp, mvr)
S3method(varImp, earth)
S3method(varImp, bagEarth)
S3method(varImp, bagFDA)
S3method(varImp, RandomForest)
S3method(varImp, dsa)
S3method(varImp, plsda)
S3method(varImp, fda)
S3method(varImp, multinom)
S3method(varImp, cubist)
S3method(varImp, RRF)
S3method(varImp, PART)
S3method(varImp, JRip)
S3method(varImp, C5.0)
S3method(varImp, nnet)
S3method(varImp, glmnet)
S3method(varImp, gam)
S3method(varImp, gafs)
S3method(varImp, safs)

S3method(densityplot, train)
S3method(histogram, train)
S3method(stripplot, train)
S3method(xyplot, train)


S3method(plot, train)
S3method(plot, gafs)
S3method(plot, safs)

S3method(confusionMatrix, train)
S3method(confusionMatrix, rfe)
S3method(confusionMatrix, sbf)

S3method(print, train)
S3method(print, varImp.train)
S3method(print, confusionMatrix)
S3method(print, confusionMatrix.train)
S3method(print, confusionMatrix.rfe)
S3method(print, confusionMatrix.sbf)
S3method(print, knn3)
S3method(print, plsda)
S3method(print, splsda)
S3method(print, bagEarth)
S3method(print, bagFDA)
S3method(print, summary.bagEarth)
S3method(print, summary.bagFDA)
S3method(print, preProcess)
S3method(print, pcaNNet)


S3method(print, gafs)
S3method(print, safs)

S3method(predict, plsda)
S3method(predict, splsda)
S3method(predict, knn3)
S3method(predict, bagEarth)
S3method(predict, bagFDA)
S3method(predict, preProcess)
S3method(predict, pcaNNet)
S3method(predict, list)
S3method(predict, train)

S3method(predict, gafs)
S3method(predict, safs)

S3method(summary, bagEarth)
S3method(summary, bagFDA)

S3method(format, bagEarth)

S3method(predictors, train)
S3method(predictors, terms)
S3method(predictors, formula)
S3method(predictors, list)
S3method(predictors, default)
S3method(predictors, gafs)
S3method(predictors, safs)

S3method(confusionMatrix, table)



S3method(as.table, confusionMatrix)
S3method(as.matrix, confusionMatrix)

S3method(update, gafs)
S3method(update, safs)


S3method(levels, train)

S3method(ggplot, train)
S3method(ggplot, rfe)


S3method(oob_pred, train)
S3method(oob_pred, rfe)
S3method(oob_pred, sbf)
S3method(oob_pred, list)

S3method(gafs, default)
S3method(safs, default)

S3method(trim, train)

S3method(spatialSign, matrix)
S3method(spatialSign, data.frame)

S3method(knn3, matrix)
S3method(knn3, data.frame)
S3method(knn3, formula)

7 changes: 7 additions & 0 deletions pkg/caret/R/aaa.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
##
## and other examples.


#' @useDynLib caret
#' @import methods plyr reshape2 ggplot2 lattice nlme

###################################################################
## Global Variables
###################################################################
Expand Down Expand Up @@ -223,6 +227,8 @@ defaultSummary <- function(data, lev = NULL, model = NULL)
postResample(data[,"pred"], data[,"obs"])
}


#' @importFrom ModelMetrics auc
#' @export
twoClassSummary <- function (data, lev = NULL, model = NULL)
{
Expand All @@ -242,6 +248,7 @@ twoClassSummary <- function (data, lev = NULL, model = NULL)
out
}

#' @importFrom stats complete.cases
#' @export
mnLogLoss <- function(data, lev = NULL, model = NULL){
if(is.null(lev)) stop("'lev' cannot be NULL")
Expand Down
3 changes: 2 additions & 1 deletion pkg/caret/R/adaptive.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
## add na.action to all eval functions
## change multiplier and alpha to confidence


#' @importFrom stats complete.cases
#' @import foreach
adaptiveWorkflow <- function(x, y, wts, info, method, ppOpts, ctrl, lev,
metric, maximize, testing = FALSE, ...) {
loadNamespace("caret")
Expand Down
3 changes: 3 additions & 0 deletions pkg/caret/R/avNNet.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ avNNet <- function (x, ...)


## this is a near copy of nnet.formula
#' @importFrom stats .getXlevels contrasts
#' @export
avNNet.formula <- function (formula, data, weights, ...,
repeats = 5,
Expand Down Expand Up @@ -48,6 +49,7 @@ avNNet.formula <- function (formula, data, weights, ...,
res
}

#' @import foreach
#' @export
avNNet.default <- function(x, y, repeats = 5,
bag = FALSE, allowParallel = TRUE,
Expand Down Expand Up @@ -106,6 +108,7 @@ print.avNNet <- function (x, ...)
invisible(x)
}

#' @importFrom stats .checkMFClasses
#' @export
predict.avNNet <- function(object, newdata, type = c("raw", "class", "prob"), ...)
{
Expand Down
2 changes: 1 addition & 1 deletion pkg/caret/R/bag.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ bagControl <- function(fit = NULL, predict = NULL, aggregate = NULL, downSample




#' @importFrom stats contrasts
#' @export
"bag.formula" <-
function (formula, data = NULL,..., subset, weights, na.action = na.omit)
Expand Down
4 changes: 3 additions & 1 deletion pkg/caret/R/bagEarth.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
class = "bagEarth")
}

#' @importFrom stats contrasts
#' @export
"bagEarth.formula" <-
function (formula, data = NULL, B = 50, summary = mean, keepX = TRUE, ..., subset, weights = NULL, na.action = na.omit)
Expand Down Expand Up @@ -157,7 +158,7 @@

}


#' @export
print.bagEarth <- function (x, ...)
{
cat("\nCall:\n", deparse(x$call), "\n\n", sep = "")
Expand Down Expand Up @@ -190,6 +191,7 @@ print.bagEarth <- function (x, ...)
out
}

#' @export
"print.summary.bagEarth" <-
function(x, digits = max(3, getOption("digits") - 3), ...)
{
Expand Down
4 changes: 3 additions & 1 deletion pkg/caret/R/bagFDA.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function(x, y, weights = NULL, B = 50, keepX = TRUE, ...)
weights = !is.null(weights), dots = list(...)), class = "bagFDA")
}

#' @importFrom stats contrasts
#' @export
"bagFDA.formula" <-
function (formula, data = NULL, B = 50, keepX = TRUE, ..., subset, weights = NULL, na.action = na.omit)
Expand Down Expand Up @@ -73,7 +74,7 @@ function (formula, data = NULL, B = 50, keepX = TRUE, ..., subset, weights = NUL
out
}


#' @export
"print.bagFDA" <-
function (x, ...)
{
Expand Down Expand Up @@ -162,6 +163,7 @@ function(object, ...)
out
}

#' @export
"print.summary.bagFDA" <-
function(x, digits = max(3, getOption("digits") - 3), ...)
{
Expand Down
4 changes: 3 additions & 1 deletion pkg/caret/R/calibration.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ print.calibration <- function(x, ...)
invisible(x)
}


#' @importFrom stats binom.test
calibCalc <- function(x, class = levels(obs)[1], cuts = 11) {
if(length(cuts) == 1) {
num_cuts <- cuts
Expand Down Expand Up @@ -94,6 +94,8 @@ calibCalc <- function(x, class = levels(obs)[1], cuts = 11) {
plot.calibration <- function(x, y = NULL, ...)
xyplot(x = x, data = NULL, ...)

#' @importFrom stats as.formula
#' @importFrom grDevices extendrange
#' @export
xyplot.calibration <- function(x, data = NULL, ...){
lFormula <- "Percent ~ midpoint"
Expand Down
1 change: 1 addition & 0 deletions pkg/caret/R/classLevels.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

#' @export
levels.train <- function(x, ...) {
if(any(names(x) == "levels")) {
out <- x$levels
Expand Down
2 changes: 2 additions & 0 deletions pkg/caret/R/common_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ change_text <- function(old, new, p, show_diff = TRUE) {
num_text
}

#' @export
predictors.gafs <- function(x, ...) {
x$best_vars
}

#' @export
predictors.safs <- function(x, ...) {
x$best_vars
}
Expand Down
12 changes: 11 additions & 1 deletion pkg/caret/R/confusionMatrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ confusionMatrix.default <- function(data, reference,
getFromNamespace("confusionMatrix.table", "caret")(classTable, positive, prevalence = prevalence, mode = mode)
}

#' @importFrom stats binom.test
#' @export
confusionMatrix.table <- function(data, positive = NULL,
prevalence = NULL, mode = "sens_spec", ...){
requireNamespaceQuietStop("e1071")
Expand Down Expand Up @@ -157,7 +159,7 @@ confusionMatrix.table <- function(data, positive = NULL,
class = "confusionMatrix")
}


#' @export
as.matrix.confusionMatrix <- function(x, what = "xtabs", ...){
if(!(what %in% c("xtabs", "overall", "classes")))
stop("what must be either xtabs, overall or classes")
Expand Down Expand Up @@ -231,6 +233,7 @@ train_resampledCM <- function(x) {
resampledCM
}

#' @export
as.table.confusionMatrix <- function(x, ...) x$table

#' @export
Expand Down Expand Up @@ -283,9 +286,13 @@ confusionMatrix.train <- function(data, norm = "overall", dnn = c("Prediction",
out
}

#' @export
confusionMatrix.rfe <- confusionMatrix.train

#' @export
confusionMatrix.sbf <- confusionMatrix.train

#' @export
print.confusionMatrix.train <- function(x, digits = 1, ...){
cat(x$text, "\n")
normText <- switch(x$norm,
Expand All @@ -308,7 +315,10 @@ print.confusionMatrix.train <- function(x, digits = 1, ...){
invisible(x)
}

#' @export
print.confusionMatrix.rfe <- print.confusionMatrix.train

#' @export
print.confusionMatrix.sbf <- print.confusionMatrix.train

resampName <- function(x, numbers = TRUE){
Expand Down
1 change: 1 addition & 0 deletions pkg/caret/R/dummyVar.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ contr.dummy <- function(n, ...)
UseMethod("dummyVars")
}

#' @importFrom stats as.formula
#' @export
dummyVars.default <- function (formula, data, sep = ".", levelsOnly = FALSE, fullRank = FALSE, ...)
{
Expand Down
3 changes: 3 additions & 0 deletions pkg/caret/R/filterVarImp.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@


#' @importFrom ModelMetrics auc

rocPerCol <- function(dat, cls){
auc(cls, dat)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/caret/R/findCorrelation.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

#' @importFrom stats complete.cases
findCorrelation_fast <- function(x, cutoff = .90, verbose = FALSE){
if(any(!complete.cases(x)))
stop("The correlation matrix has some missing values.")
Expand Down
2 changes: 2 additions & 0 deletions pkg/caret/R/format.bagEarth.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

#' @export
format.bagEarth <- function(x, file = "", cat = TRUE, ...)
{
requireNamespaceQuietStop("earth")
Expand Down
Loading

0 comments on commit 9b4e3fe

Please sign in to comment.