Skip to content

Commit

Permalink
change from depends to import
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-columbiau committed Mar 20, 2024
1 parent d3121ca commit a3cb534
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 24 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ URL: https://github.com/jonathan-columbiau/lionmap,
https://jonathan-columbiau.github.io/lionmap/
BugReports: https://github.com/jonathan-columbiau/lionmap/issues
Depends:
Imports:
dplyr,
tidyr,
tidytree,
caret,
data.tree,
e1071,
Expand All @@ -24,10 +28,6 @@ Depends:
stats,
stringr,
testthat
Imports:
dplyr,
tidyr,
tidytree
Suggests:
kableExtra,
ggplot2,
Expand Down
6 changes: 4 additions & 2 deletions R/binomial_elastic_net.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#' @param celltype_labels Celltype labels in vector
#'
#' @return Binomial Elastic Net model trained on evenly split dataset (upsamples if classes aren't evenly split)
#' @importFrom caret upSample
#' @importFrom glmet cv.glmnet
#' @keywords internal
#'
#' @examples
Expand All @@ -14,9 +16,9 @@
#' dataset = dataset[,1:4]
#' ex_model = binomial_elastic_net(dataset, labels)
binomial_elastic_net <- function(reference_dataset, celltype_labels) {
upsampled_dataset <- caret::upSample(x = reference_dataset, y = celltype_labels, yname = "celltype_labels", list = T)
upsampled_dataset <- upSample(x = reference_dataset, y = celltype_labels, yname = "celltype_labels", list = T)
celltype_labels <- upsampled_dataset[["y"]]
reference_dataset <- upsampled_dataset[["x"]] %>% as.matrix()
pairwise_model <- glmnet::cv.glmnet(x = reference_dataset, y = celltype_labels, family = "binomial", alpha = .5)
pairwise_model <- cv.glmnet(x = reference_dataset, y = celltype_labels, family = "binomial", alpha = .5)
pairwise_model
}
6 changes: 4 additions & 2 deletions R/binomial_lasso.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#' @param celltype_labels Celltype labels in vector
#'
#' @return Binomial lasso model trained on evenly split dataset (upsamples if classes aren't evenly split)
#' @importFrom caret upSample
#' @importFrom glmet cv.glmnet
#' @keywords internal
#'
#' @examples
Expand All @@ -14,9 +16,9 @@
#' dataset = dataset[,1:4]
#' ex_model = binomial_lasso(dataset, labels)
binomial_lasso <- function(reference_dataset, celltype_labels) {
upsampled_dataset <- caret::upSample(x = reference_dataset, y = celltype_labels, yname = "celltype_labels", list = T)
upsampled_dataset <- upSample(x = reference_dataset, y = celltype_labels, yname = "celltype_labels", list = T)
celltype_labels <- upsampled_dataset[["y"]]
reference_dataset <- upsampled_dataset[["x"]] %>% as.matrix()
pairwise_model <- glmnet::cv.glmnet(x = reference_dataset, y = celltype_labels, family = "binomial", alpha = 1)
pairwise_model <- cv.glmnet(x = reference_dataset, y = celltype_labels, family = "binomial", alpha = 1)
pairwise_model
}
6 changes: 4 additions & 2 deletions R/binomial_ridge.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#' @param celltype_labels Celltype labels in vector
#'
#' @return Binomial ridge model trained on evenly split dataset (upsamples if classes aren't evenly split)
#' @importFrom caret upSample
#' @importFrom glmet cv.glmnet
#' @keywords internal
#'
#' @examples
Expand All @@ -14,9 +16,9 @@
#' dataset = dataset[,1:4]
#' ex_model = binomial_ridge(dataset, labels)
binomial_ridge <- function(reference_dataset, celltype_labels) {
upsampled_dataset <- caret::upSample(x = reference_dataset, y = celltype_labels, yname = "celltype_labels", list = T)
upsampled_dataset <- upSample(x = reference_dataset, y = celltype_labels, yname = "celltype_labels", list = T)
celltype_labels <- upsampled_dataset[["y"]]
reference_dataset <- upsampled_dataset[["x"]] %>% as.matrix()
pairwise_model <- glmnet::cv.glmnet(x = reference_dataset, y = celltype_labels, family = "binomial", alpha = 0)
pairwise_model <- cv.glmnet(x = reference_dataset, y = celltype_labels, family = "binomial", alpha = 0)
pairwise_model
}
6 changes: 4 additions & 2 deletions R/knn.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#' @param celltype_labels Celltype labels in vector
#'
#' @return knn model trained on evenly split dataset (upsamples if classes aren't evenly split)
#' @importFrom caret upSample
#' @importFrom caret knn3
#' @keywords internal
#'
#' @examples
Expand All @@ -15,7 +17,7 @@
#' ex_model = knn(dataset, labels)
knn <- function(reference_dataset, celltype_labels) {
#upsample minority class to make class frequencies equal
reference_dataset <- caret::upSample(x = reference_dataset, y = celltype_labels, yname = "celltype_labels")
pairwise_model <- caret::knn3(celltype_labels ~ ., data = reference_dataset, k = 5)
reference_dataset <- upSample(x = reference_dataset, y = celltype_labels, yname = "celltype_labels")
pairwise_model <- knn3(celltype_labels ~ ., data = reference_dataset, k = 5)
pairwise_model
}
6 changes: 4 additions & 2 deletions R/linear_da.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#' @param celltype_labels Celltype labels in vector
#'
#' @return linear_da model trained on evenly split dataset (upsamples if classes aren't evenly split)
#' @importFrom caret upSample
#' @importFrom MASS lda
#' @keywords internal
#'
#' @examples
Expand All @@ -15,7 +17,7 @@
#' ex_model = linear_da(dataset, labels)
linear_da <- function(reference_dataset, celltype_labels) {
#upsample minority class to make class frequencies equal
reference_dataset <- caret::upSample(x = reference_dataset, y = celltype_labels, yname = "celltype_labels")
pairwise_model <- MASS::lda(celltype_labels ~ ., data = reference_dataset)
reference_dataset <- upSample(x = reference_dataset, y = celltype_labels, yname = "celltype_labels")
pairwise_model <- lda(celltype_labels ~ ., data = reference_dataset)
pairwise_model
}
6 changes: 4 additions & 2 deletions R/linear_svm.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#' @param celltype_labels Celltype labels in vector
#'
#' @return linear_svm model trained on evenly split dataset (upsamples if classes aren't evenly split)
#' @importFrom caret upSample
#' @importFrom e1071 svm
#' @keywords internal
#'
#' @examples
Expand All @@ -14,7 +16,7 @@
#' dataset = dataset[,1:4]
#' ex_model = linear_svm(dataset, labels)
linear_svm <- function(reference_dataset, celltype_labels) {
reference_dataset <- caret::upSample(x = reference_dataset, y = celltype_labels, yname = "celltype_labels")
pairwise_model <- e1071::svm(celltype_labels ~ ., data = reference_dataset, kernel = "linear", scale = F)
reference_dataset <- upSample(x = reference_dataset, y = celltype_labels, yname = "celltype_labels")
pairwise_model <- svm(celltype_labels ~ ., data = reference_dataset, kernel = "linear", scale = F)
pairwise_model
}
6 changes: 4 additions & 2 deletions R/naive_bayes.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#' @param celltype_labels Celltype labels in vector
#'
#' @return naive_bayes model trained on evenly split dataset (upsamples if classes aren't evenly split)
#' @importFrom caret upSample
#' @importFrom e1071 naiveBayes
#' @keywords internal
#'
#' @examples
Expand All @@ -15,7 +17,7 @@
#' ex_model = naive_bayes(dataset, labels)
naive_bayes <- function(reference_dataset, celltype_labels) {
#upsample minority class to make class frequencies equal
reference_dataset <- caret::upSample(x = reference_dataset, y = celltype_labels, yname = "celltype_labels")
pairwise_model <- e1071::naiveBayes(celltype_labels ~ ., data = reference_dataset)
reference_dataset <- upSample(x = reference_dataset, y = celltype_labels, yname = "celltype_labels")
pairwise_model <- naiveBayes(celltype_labels ~ ., data = reference_dataset)
pairwise_model
}
6 changes: 4 additions & 2 deletions R/polynomial_svm.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#' @param celltype_labels Celltype labels in vector
#'
#' @return polynomial_svm model trained on evenly split dataset (upsamples if classes aren't evenly split)
#' @importFrom caret upSample
#' @importFrom e1071 svm
#' @keywords internal
#'
#' @examples
Expand All @@ -14,7 +16,7 @@
#' dataset = dataset[,1:4]
#' ex_model = polynomial_svm(dataset, labels)
polynomial_svm <- function(reference_dataset, celltype_labels) {
reference_dataset <- caret::upSample(x = reference_dataset, y = celltype_labels, yname = "celltype_labels")
pairwise_model <- e1071::svm(celltype_labels ~ ., data = reference_dataset, kernel = "polynomial", scale = F)
reference_dataset <- upSample(x = reference_dataset, y = celltype_labels, yname = "celltype_labels")
pairwise_model <- svm(celltype_labels ~ ., data = reference_dataset, kernel = "polynomial", scale = F)
pairwise_model
}
6 changes: 4 additions & 2 deletions R/quadratic_da.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#' @param celltype_labels Celltype labels in vector
#'
#' @return quadratic_da model trained on evenly split dataset (upsamples if classes aren't evenly split)
#' @importFrom caret upSample
#' @importFrom MASS qda
#' @keywords internal
#'
#' @examples
Expand All @@ -15,7 +17,7 @@
#' ex_model = quadratic_da(dataset, labels)
quadratic_da <- function(reference_dataset, celltype_labels) {
#upsample minority class to make class frequencies equal
reference_dataset <- caret::upSample(x = reference_dataset, y = celltype_labels, yname = "celltype_labels")
pairwise_model <- MASS::qda(celltype_labels ~ ., data = reference_dataset)
reference_dataset <- upSample(x = reference_dataset, y = celltype_labels, yname = "celltype_labels")
pairwise_model <- qda(celltype_labels ~ ., data = reference_dataset)
pairwise_model
}
6 changes: 4 additions & 2 deletions R/random_forest.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#' @param celltype_labels Celltype labels in vector
#'
#' @return rf model trained on evenly split dataset (upsamples if classes aren't evenly split)
#' @importFrom caret upSample
#' @importFrom ranger ranger
#' @keywords internal
#'
#' @examples
Expand All @@ -15,7 +17,7 @@
#' ex_model = random_forest(dataset, labels)
random_forest <- function(reference_dataset, celltype_labels) {
#upsample minority class to make class frequencies equal
reference_dataset <- caret::upSample(x = reference_dataset, y = celltype_labels, yname = "celltype_labels")
pairwise_model <- ranger::ranger(celltype_labels ~ ., data = reference_dataset, num.trees = 500, classification = T, replace = T)
reference_dataset <- upSample(x = reference_dataset, y = celltype_labels, yname = "celltype_labels")
pairwise_model <- ranger(celltype_labels ~ ., data = reference_dataset, num.trees = 500, classification = T, replace = T)
pairwise_model
}

0 comments on commit a3cb534

Please sign in to comment.