Skip to content

Commit

Permalink
some logic to allow handling of factors
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhendricks committed Jul 9, 2017
1 parent 4a2a80c commit c9c9184
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion R/R/core.R
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,23 @@ easy_analysis <- function(.data, dependent_variable, algorithm,
.data <- remove_variables(.data, exclude_variables)
object[["data"]] <- .data

# Set and capture dependent variable
# Set dependent variable
y <- set_dependent_variable(.data, dependent_variable)

# Process dependent variable
if (family == "binomial") {
# Check that dependent variable has two classes
if (length(unique(y)) != 2) {
stop("Error! Dependent variable must have two classes!")
}

# Check if dependent variable is a factor
if (is.factor(y)) {
y <- as.numeric(y) - 1
}
}

# Capture dependent variable
object[["y"]] <- y

# Set and capture independent variables
Expand Down
2 changes: 1 addition & 1 deletion R/R/setters.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ set_categorical_variables <- function(column_names, categorical_variables = NULL
#' @family setters
#' @export
set_dependent_variable <- function(.data, dependent_variable) {
y <- as.vector(.data[, dependent_variable, drop = TRUE])
y <- .data[, dependent_variable, drop = TRUE]
y
}

Expand Down

0 comments on commit c9c9184

Please sign in to comment.