splendid_convert: Convert covariate data

Description Usage Arguments Details Value Author(s) Examples

View source: R/splendid_convert.R

Description

Converts all categorical predictors to dummy variables in the dataset. Classification algorithms LDA and the MLR family have such a limitation.

Usage

1
splendid_convert(data, algorithms, convert = FALSE)

Arguments

data

data frame with rows as samples, columns as features

algorithms

character vector of algorithms to use for supervised learning. See Algorithms section for possible options. By default, this argument is NULL, in which case all algorithms are used.

convert

logical; if TRUE, converts all categorical variables in data to dummy variables. Certain algorithms only work with such limitations (e.g. LDA).

Details

If all the variables in the original data are already continuous, nothing is done. Otherwise, conversion is performed if convert = TRUE. An error message is thrown if there are categorical variables and convert = FALSE, indicating exactly which algorithms specified require data conversion.

Value

A (potentially) transformed data frame.

Author(s)

Derek Chiu

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
data(hgsc)

# Nothing happens if data is all continuous
data_same <- splendid_convert(hgsc, algorithms = "lda", convert = TRUE)
identical(hgsc, data_same)

# Dummy variables created if there are categorical variables
data_dummy <- splendid_convert(iris, algorithms = "lda", convert = TRUE)
head(data_dummy)

# Some algorithms are robust to the covariate data structure
data_robust <- splendid_convert(iris, algorithms = "rf", convert = FALSE)
identical(iris, data_robust)

# Other algorithms require conversion
## Not run: 
splendid_convert(iris, algorithms = "lda", convert = FALSE)

## End(Not run)

AlineTalhouk/splendid documentation built on Aug. 30, 2018, 7:54 a.m.