# NOT RUN {
data(FF4_qc) # load demo dataset
# QC as training samples; QC1, QC2 and QC3 as test samples:
train_samples <- FF4_qc[FF4_qc$sampleType == "QC",]
test_samples <- FF4_qc[FF4_qc$sampleType != "QC",]
# Only numeric data of metabolite variables are allowed:
train_num = train_samples[-c(1:5)]
test_num = test_samples[-c(1:5)]
# If the selection is performed on the whole dataset:
# based on training samples only:
selected_var_1 <- select_variable(train_num = train_num,
test_num = NULL,
selectVar_batchWise = FALSE)
# also consider test samples:
selected_var_2 <- select_variable(train_num = train_num,
test_num = test_num,
selectVar_batchWise = FALSE)
# If the selection is based on different batches:
# (In selectVar_batchWise, batch ID is required.)
selected_var_3 <- select_variable(train_num = train_num,
test_num = NULL,
train_batchID = train_samples$plateID,
test_batchID = NULL,
selectVar_batchWise = TRUE)
# If coerce_numeric = TRUE,
# columns cannot be coerced to numeric will be removed (with warnings):
# (In this example, columns of injection order and well position are excluded.
# Because we don't want to calculate the correlations between metabolites and
# injection order/well position.)
selected_var_4 <- select_variable(train_num = train_samples[-c(4,5)],
train_batchID = train_samples$plateID,
selectVar_batchWise = TRUE,
coerce_numeric = TRUE)
identical(selected_var_3, selected_var_4) # identical to selected_var_3
# }
# NOT RUN {
# will throw errors if input data have non-numeric columns
# and coerce_numeric = FALSE:
selected_var_5 <- select_variable(train_num = train_samples[-c(4,5)],
coerce_numeric = FALSE)
# }
Run the code above in your browser using DataLab