calculate_AUC_base: calculate_AUC_base

Description Usage Arguments Value Examples

View source: R/calculate_AUC_base.R

Description

the base function of calculate_AUCs: build the model and calculate the AUCs

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
calculate_AUC_base(
  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),
  seed = 1,
  method = "pca2_mvnorm",
  model = c("svm", "randomforest"),
  func = 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.

seed

the seed you want to use to run simulations.

method

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

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,

library(e1071)

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)
}

AUC = calculate_AUC_base(n01_all= c(800,800), n01_p=c(15,15), n01_test=c(300,300), n_train_sets = c(c(15,15),c(30,30),c(60,60),c(120,120),c(150,150)), seed=1, model=c("self","randomforest"),func=predict_model)

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

data = list(x_data=x_data, y_data=y_data)

AUC = calculate_AUC_base(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), seed=1, 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
AUC = calculate_AUC_base(n01_all = c(800, 800), n01_p = c(15, 15), n01_test = c(300,
    300), n_train_sets = c(c(15, 15), c(30, 30), c(60, 60), c(120, 120), c(150, 150)),
    seed = 1, model = c("svm", "randomforest"))

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