Skip to content

Commit c9c9184

Browse files
committed
some logic to allow handling of factors
1 parent 4a2a80c commit c9c9184

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

R/R/core.R

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,23 @@ easy_analysis <- function(.data, dependent_variable, algorithm,
238238
.data <- remove_variables(.data, exclude_variables)
239239
object[["data"]] <- .data
240240

241-
# Set and capture dependent variable
241+
# Set dependent variable
242242
y <- set_dependent_variable(.data, dependent_variable)
243+
244+
# Process dependent variable
245+
if (family == "binomial") {
246+
# Check that dependent variable has two classes
247+
if (length(unique(y)) != 2) {
248+
stop("Error! Dependent variable must have two classes!")
249+
}
250+
251+
# Check if dependent variable is a factor
252+
if (is.factor(y)) {
253+
y <- as.numeric(y) - 1
254+
}
255+
}
256+
257+
# Capture dependent variable
243258
object[["y"]] <- y
244259

245260
# Set and capture independent variables

R/R/setters.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ set_categorical_variables <- function(column_names, categorical_variables = NULL
152152
#' @family setters
153153
#' @export
154154
set_dependent_variable <- function(.data, dependent_variable) {
155-
y <- as.vector(.data[, dependent_variable, drop = TRUE])
155+
y <- .data[, dependent_variable, drop = TRUE]
156156
y
157157
}
158158

0 commit comments

Comments
 (0)