Skip to content

Commit

Permalink
remove dependent variable name (not needed in R version)
Browse files Browse the repository at this point in the history
  • Loading branch information
mnwright committed Aug 28, 2019
1 parent 0951785 commit 0ce3cac
Show file tree
Hide file tree
Showing 17 changed files with 147 additions and 232 deletions.
4 changes: 2 additions & 2 deletions R/RcppExports.R
@@ -1,8 +1,8 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

rangerCpp <- function(treetype, dependent_variable_name, input_x, input_y, variable_names, mtry, num_trees, verbose, seed, num_threads, write_forest, importance_mode_r, min_node_size, split_select_weights, use_split_select_weights, always_split_variable_names, use_always_split_variable_names, status_variable_name, prediction_mode, loaded_forest, snp_data, sample_with_replacement, probability, unordered_variable_names, use_unordered_variable_names, save_memory, splitrule_r, case_weights, use_case_weights, class_weights, predict_all, keep_inbag, sample_fraction, alpha, minprop, holdout, prediction_type_r, num_random_splits, sparse_x, use_sparse_data, order_snps, oob_error, max_depth, inbag, use_inbag) {
.Call(`_ranger_rangerCpp`, treetype, dependent_variable_name, input_x, input_y, variable_names, mtry, num_trees, verbose, seed, num_threads, write_forest, importance_mode_r, min_node_size, split_select_weights, use_split_select_weights, always_split_variable_names, use_always_split_variable_names, status_variable_name, prediction_mode, loaded_forest, snp_data, sample_with_replacement, probability, unordered_variable_names, use_unordered_variable_names, save_memory, splitrule_r, case_weights, use_case_weights, class_weights, predict_all, keep_inbag, sample_fraction, alpha, minprop, holdout, prediction_type_r, num_random_splits, sparse_x, use_sparse_data, order_snps, oob_error, max_depth, inbag, use_inbag)
rangerCpp <- function(treetype, input_x, input_y, variable_names, mtry, num_trees, verbose, seed, num_threads, write_forest, importance_mode_r, min_node_size, split_select_weights, use_split_select_weights, always_split_variable_names, use_always_split_variable_names, prediction_mode, loaded_forest, snp_data, sample_with_replacement, probability, unordered_variable_names, use_unordered_variable_names, save_memory, splitrule_r, case_weights, use_case_weights, class_weights, predict_all, keep_inbag, sample_fraction, alpha, minprop, holdout, prediction_type_r, num_random_splits, sparse_x, use_sparse_data, order_snps, oob_error, max_depth, inbag, use_inbag) {
.Call(`_ranger_rangerCpp`, treetype, input_x, input_y, variable_names, mtry, num_trees, verbose, seed, num_threads, write_forest, importance_mode_r, min_node_size, split_select_weights, use_split_select_weights, always_split_variable_names, use_always_split_variable_names, prediction_mode, loaded_forest, snp_data, sample_with_replacement, probability, unordered_variable_names, use_unordered_variable_names, save_memory, splitrule_r, case_weights, use_case_weights, class_weights, predict_all, keep_inbag, sample_fraction, alpha, minprop, holdout, prediction_type_r, num_random_splits, sparse_x, use_sparse_data, order_snps, oob_error, max_depth, inbag, use_inbag)
}

numSmaller <- function(values, reference) {
Expand Down
9 changes: 3 additions & 6 deletions R/predict.R
Expand Up @@ -98,8 +98,7 @@ predict.ranger.forest <- function(object, data, predict.all = FALSE,
is.null(forest$treetype)) {
stop("Error: Invalid forest object.")
}
if (forest$treetype == "Survival" && (is.null(forest$status.variable.name) ||
is.null(forest$chf) || is.null(forest$unique.death.times))) {
if (forest$treetype == "Survival" && (is.null(forest$chf) || is.null(forest$unique.death.times))) {
stop("Error: Invalid forest object.")
}

Expand Down Expand Up @@ -213,15 +212,13 @@ predict.ranger.forest <- function(object, data, predict.all = FALSE,
}

## Defaults for variables not needed
dependent.variable.name <- ""
mtry <- 0
importance <- 0
min.node.size <- 0
split.select.weights <- list(c(0, 0))
use.split.select.weights <- FALSE
always.split.variables <- c("0", "0")
use.always.split.variables <- FALSE
status.variable.name <- "status"
prediction.mode <- TRUE
write.forest <- FALSE
replace <- TRUE
Expand Down Expand Up @@ -258,11 +255,11 @@ predict.ranger.forest <- function(object, data, predict.all = FALSE,
}

## Call Ranger
result <- rangerCpp(treetype, dependent.variable.name, x, y, forest$independent.variable.names, mtry,
result <- rangerCpp(treetype, x, y, forest$independent.variable.names, mtry,
num.trees, verbose, seed, num.threads, write.forest, importance,
min.node.size, split.select.weights, use.split.select.weights,
always.split.variables, use.always.split.variables,
status.variable.name, prediction.mode, forest, snp.data, replace, probability,
prediction.mode, forest, snp.data, replace, probability,
unordered.factor.variables, use.unordered.factor.variables, save.memory, splitrule,
case.weights, use.case.weights, class.weights,
predict.all, keep.inbag, sample.fraction, alpha, minprop, holdout,
Expand Down
18 changes: 3 additions & 15 deletions R/ranger.R
Expand Up @@ -226,8 +226,6 @@ ranger <- function(formula = NULL, data = NULL, num.trees = 500, mtry = NULL,
if (is.null(x) | is.null(y)) {
stop("Error: Either data or x and y is required.")
}
dependent.variable.name <- ""
status.variable.name <- ""
} else {
## GenABEL GWA data
if ("gwaa.data" %in% class(data)) {
Expand All @@ -246,12 +244,9 @@ ranger <- function(formula = NULL, data = NULL, num.trees = 500, mtry = NULL,
if (is.null(dependent.variable.name)) {
if (is.null(y) | is.null(x)) {
stop("Error: Please give formula, dependent variable name or x/y.")
} else {
dependent.variable.name <- colnames(y)[1]
}
}
} else {
if (is.null(status.variable.name)) {
status.variable.name <- ""
y <- data[, dependent.variable.name, drop = TRUE]
x <- data[, !(colnames(data) %in% dependent.variable.name), drop = FALSE]
} else {
Expand All @@ -267,13 +262,6 @@ ranger <- function(formula = NULL, data = NULL, num.trees = 500, mtry = NULL,
data.selected <- parse.formula(formula, data, env = parent.frame())
y <- data.selected[, 1]
x <- data.selected[, -1, drop = FALSE]
if (survival::is.Surv(y)) {
dependent.variable.name <- colnames(y)[1]
status.variable.name <- colnames(y)[2]
} else {
dependent.variable.name <- colnames(data.selected)[1]
status.variable.name <- ""
}
}
}

Expand Down Expand Up @@ -789,11 +777,11 @@ ranger <- function(formula = NULL, data = NULL, num.trees = 500, mtry = NULL,
}

## Call Ranger
result <- rangerCpp(treetype, dependent.variable.name, x, y.mat, independent.variable.names, mtry,
result <- rangerCpp(treetype, x, y.mat, independent.variable.names, mtry,
num.trees, verbose, seed, num.threads, write.forest, importance.mode,
min.node.size, split.select.weights, use.split.select.weights,
always.split.variables, use.always.split.variables,
status.variable.name, prediction.mode, loaded.forest, snp.data,
prediction.mode, loaded.forest, snp.data,
replace, probability, unordered.factor.variables, use.unordered.factor.variables,
save.memory, splitrule.num, case.weights, use.case.weights, class.weights,
predict.all, keep.inbag, sample.fraction, alpha, minprop, holdout, prediction.type,
Expand Down
5 changes: 2 additions & 3 deletions R/treeInfo.R
Expand Up @@ -68,14 +68,13 @@ treeInfo <- function(object, tree = 1) {
if (is.null(forest)) {
stop("Error: No saved forest in ranger object. Please set write.forest to TRUE when calling ranger.")
}
if (is.null(forest$dependent.variable.name) || is.null(forest$num.trees) ||
if (is.null(forest$num.trees) ||
is.null(forest$child.nodeIDs) || is.null(forest$split.varIDs) ||
is.null(forest$split.values) || is.null(forest$independent.variable.names) ||
is.null(forest$treetype)) {
stop("Error: Invalid forest object.")
}
if (forest$treetype == "Survival" && (is.null(forest$status.variable.name) ||
is.null(forest$chf) || is.null(forest$unique.death.times))) {
if (forest$treetype == "Survival" && (is.null(forest$chf) || is.null(forest$unique.death.times))) {
stop("Error: Invalid forest object.")
}
if (length(forest$child.nodeIDs) != forest$num.trees || length(forest$child.nodeIDs[[1]]) != 2) {
Expand Down

0 comments on commit 0ce3cac

Please sign in to comment.