calculate_AUCs: Calculate the AUCs

Description Usage Arguments Value Examples

View source: R/calculate_AUCs.R

Description

The main function of SSD package: build the model and calculate the AUCs with parallel, you can also get the resulting plot via this function.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
calculate_AUCs(
  n01_all = c(800, 800),
  n01_p = c(15, 15),
  n_train_sets = c(c(15, 15), c(30, 30), c(60, 60), c(120, 120), c(150, 150)),
  n01_test = c(300, 300),
  num_of_seeds = 20,
  random_seeds = TRUE,
  seeds = NULL,
  calculate_std_of_AUC_and_produce_plot = FALSE,
  method = "pca2_mvnorm",
  ncores = NULL,
  model = c("svm", "randomforest"),
  func = NULL,
  package_imported = NULL,
  data_generation = list(dist = "t-distribution", sigma = list(class_0 = diag(5),
    class_1 = diag(5)), df = c(10, 10), delta = c(rep(0, 5), rep(2, 5))),
  data_input = NULL,
  true_data_to_compare = 1
)

Arguments

n01_all

size of all data labeled as class 0/1. For example, n01_all=c(800,800) represents that the size of all data labeled as class 0 is 800 and the size of all data labeled as class 1 is also 800.

n01_p

size of pilot data labeled as class 0/1. For example, n01_p=c(15,15) represents that the size of pilot data labeled as class 0 is 15 and the size of pilot data labeled as class 1 is also 15.

n_train_sets

size sets of training data labeled as class 0/1. For example, n_train_sets=c(c(30,30),c(90,90),c(150,150)) represents that we try 3 different sets of training data and the training size of the first set is c(30,30).

n01_test

number of test data labeled as class 0/1. size of all data labeled as class 0/1. For example, n01_test=c(300,300) represents that the size of test data labeled as class 0 is 300 and the size of test data labeled as class 1 is also 300.

num_of_seeds

number of seeds you want to use to run simulations.(If you want to make the plots, "num_of_seeds" must be not smaller than 2)

random_seeds

If TRUE, it will produce "num_of_seeds" seeds randomly. If FASLE, it will use seeds "1:num_of_seeds", which is used to make it reproducible.

seeds

You can choose the seeds set as you wish. It's default value is NULL. If it's not NULL, the function will use your seeds and ignore parameters "num_of_seeds" and "random_seeds".

calculate_std_of_AUC_and_produce_plot

You can calculate the standard deviation of AUC and produce the plot directly if you set this parameter to TRUE. It will create a new folder named "result" in your current directory and save the plots into it.

method

Choose the method you want to use: "pca2_mvnorm" , "gaussian_copula" or "smote"(SMOTE). The default value is "pca2_mvnorm".

ncores

number of cores used for parallel computing. Default = detectCores() - 1.

model

base classification model.

  • logistic: Logistic regression. glm function with family = 'binomial'

  • penlog: Penalized logistic regression with LASSO penalty. glmnet in glmnet package

  • svm: Support Vector Machines. svm in e1071 package

  • randomforest: Random Forest. randomForest in randomForest package

  • lda: Linear Discriminant Analysis. lda in MASS package

  • slda: Sparse Linear Discriminant Analysis with LASSO penalty.

  • nb: Naive Bayes. naiveBayes in e1071 package

  • nnb: Nonparametric Naive Bayes. naive_bayes in naivebayes package

  • ada: Ada-Boost. ada in ada package

  • xgboost: XGBboost. xgboost in xgboost package

  • tree: Classificatin Tree. tree in tree package

  • self: You can use your self-defined function. You need to pass your self-defined function via the "func" parameter.

func

If you set "model" to "self", you have to pass your self-defined model function. This function should be able to take "x_train" and "y_train" as the first two inputs to train the model and then take "x_test" as the third input and return the predicted scores of x_test data. For example,


predict_model <- function(x_train, y_train, x_test){
data_trainxy<-data.frame(x_train,y_train=as.factor(y_train))
fit_svm<-svm(y_train~.,data=data_trainxy,probability=TRUE)
pred_svm <- predict(fit_svm, x_test, probability=TRUE,decision.values = TRUE)
p_svm=as.data.frame(attr(pred_svm, "probabilities"))$"1"
return(p_svm)
}

calculate_AUCs(n01_all= c(800,800), n01_p=c(15,15), n_train_sets = c(c(15,15),c(30,30),c(60,60),c(120,120),c(150,150)), n01_test=c(300,300), num_of_seeds=20, random_seeds=FALSE, model=c("self","randomforest"), func=predict_model, package_imported=c("e1071"), calculate_std_of_AUC_and_produce_plot=TRUE)

package_imported

If you set "model" to "self",state the names of the packages you used in your "func", which have to be specified when using parallel computing.

data_generation

a parameter list that you can tell the function about the distribution and parameters you want to use to generate the data.

  • "gaussian" represent multivariate gaussian distribution. see mvrnorm in MASS package. For example, data_generation=list(dist="gaussian",sigma=list(class_0=diag(5),class_1=diag(5)),mu=c(rep(0,5),rep(2,5)))

  • "t-distribution" represent multivariate t distribution. see rmvt in mvtnorm package. For example, data_generation=list(dist="t-distribution",sigma=list(class_0=diag(5),class_1=diag(5)),df=c(10,10),delta=c(rep(0,5),rep(2,5))).

data_input

Its default value is NULL and the function will use the "data_generation" parameter to generate the data. If "data_input" is not NULL, the function will ignore the "data_generation" parameter and "n01_all" parameter, and use the "data_input" as the data. Your "data_input" should be a list with "x_data" matrix and "y_data" matrix. For example,

yeast_data <- read.table("./yeast.data")
###https://archive.ics.uci.edu/ml/datasets/Diabetic+Retinopathy+Debrecen+Data+Set

x_data = yeast_data[,c(2:5,8:9)]
y_label = yeast_data[,10]
id0 = which(y_label=="CYT" | y_label=="MIT")
y_data = rep(1,length(y_label))
y_data[id0] = 0
table(y_data)
data = list(x_data=x_data, y_data=y_data)

res = calculate_AUCs(n01_p=c(15,15), n_train_sets = c(c(15,15),c(30,30),c(60,60),c(120,120),c(150,150)), n01_test=c(300,300), num_of_seeds=20, random_seeds=FALSE, calculate_std_of_AUC_and_produce_plot=TRUE, method="pca2_mvnorm", model=c("svm","randomforest"), data_input=data)

true_data_to_compare

0/1 variable, whether to have the true data to compare with generated data (which could make the output matrix double): if input_data==NULL(run the simulations), we will generate the true data automatically and calculate the AUCs; if you give us the input_data, please make sure that you give us sufficient input data.

Value

Return the AUCs you want to calculate

Examples

1
2
3
4
5
6
7
res = calculate_AUCs(n01_all = c(800, 800), n01_p = c(15, 15),
    n_train_sets = c(c(15, 15), c(30, 30), c(60, 60), c(120, 120),
        c(150, 150)), n01_test = c(300, 300), num_of_seeds = 20,
    random_seeds = FALSE, calculate_std_of_AUC_and_produce_plot = TRUE,
    data_generation = list(dist = "t-distribution", sigma = list(class_0 = diag(5),
        class_1 = diag(5)), df = c(10, 10), delta = c(rep(0, 5),
        rep(2, 5))), true_data_to_compare = 1)

ShudongSun/Sample-Size-Determination documentation built on Feb. 10, 2022, 1:33 a.m.