|
a |
|
b/R/J48DT.R |
|
|
1 |
#' @title J48 Decision Tree |
|
|
2 |
#' @description The decision tree analysis is implemented over a training |
|
|
3 |
#' dataset, which consisted of the DEGs obtained by either SAMseq or the |
|
|
4 |
#' binomial differential expression. |
|
|
5 |
#' @export |
|
|
6 |
#' @param data A data frame resulted from running the function ClassVectoringDT. |
|
|
7 |
#' @param quiet If `TRUE`, suppresses intermediary output |
|
|
8 |
#' @param plot If `FALSE`, suppresses plot output |
|
|
9 |
#' @importFrom RWeka J48 |
|
|
10 |
#' @importFrom graphics plot |
|
|
11 |
#' @return Information about the J48 model and, by default, a plot of the |
|
|
12 |
#' decision tree. |
|
|
13 |
J48DT <- function(data, quiet = FALSE, plot = TRUE) { |
|
|
14 |
msg <- NULL |
|
|
15 |
if (!is.data.frame(data)) { |
|
|
16 |
msg <- c(msg, "input data must be data.frame") |
|
|
17 |
} else if (nrow(data) < 2) { |
|
|
18 |
msg <- c(msg, "input data must have more than one row") |
|
|
19 |
} else if (ncol(data) < 2) { |
|
|
20 |
msg <- c(msg, "input data must have more than one column") |
|
|
21 |
} else if (sum(apply(is.na(data), 1, sum)) > 0) { |
|
|
22 |
msg <- c(msg, "NAs are not allowed in input data") |
|
|
23 |
} else if (sum(apply(data, 1, min)) < 0) { |
|
|
24 |
msg <- c(msg, "negative values are not allowed in input data") |
|
|
25 |
} |
|
|
26 |
if (is.null(msg)) TRUE else msg |
|
|
27 |
|
|
|
28 |
exp.df <- as.data.frame(t(data)) |
|
|
29 |
exp.df$classVector <- factor(colnames(data)) |
|
|
30 |
j48.model <- J48(classVector ~ ., exp.df) |
|
|
31 |
if (!quiet) print(j48.model) |
|
|
32 |
if (plot) plot(j48.model) |
|
|
33 |
return(j48.model) |
|
|
34 |
} |