Skip to content
Snippets Groups Projects
Commit 475b26ec authored by Arnaud Duvermy's avatar Arnaud Duvermy
Browse files

Rd modifications

Former-commit-id: 386607160b2e87fada9c19a6f656f3a655716041
Former-commit-id: da0304e2fa91100465d8296c021f440e3ae1bb1f
Former-commit-id: 5f47cb2441719006771c95b31b7a079c2094971a
parent b1d48967
No related branches found
No related tags found
No related merge requests found
......@@ -599,17 +599,17 @@ test_that("isValidMock_obj checks if the provided object is a valid mock object"
#'
#' @param list_var Either c() or output of init_variable
#' @param name Variable name
#' @param mu Either a numeric value or a numeric vector (of length = level)
#' @param sd Either numeric value or NA
#' @param sd Either numeric value or NA. Use to specify range of effect sizes.
#' @param level Numeric value to specify the number of levels to simulate
#' @param mu Either a numeric value or a numeric vector (of length = level). Default : 0. Not recommended to modify.
#'
#' @return
#' A list with initialized variables
#' @export
#'
#' @examples
#' init_variable(name = "my_varA", mu = 2, sd = 9, level = 200)
init_variable <- function(list_var = c(), name = "myVariable", mu = c(2,3), sd = NA, level = NA) {
#' init_variable(name = "my_varA", sd = 9, level = 200)
init_variable <- function(list_var = c(), name = "myVariable", sd = NA, level = NA, mu = 0) {
name <- clean_variable_name(name)
......@@ -795,18 +795,19 @@ build_sub_obj_return_to_user <- function(level, metaData, effectsGivenByUser, co
#'
#' @param list_var A list of variables (already initialized)
#' @param between_var A vector of variable names to include in the interaction
#' @param mu Either a numeric value or a numeric vector (of length = level)
#' @param sd Either numeric value or NA
#' @param sd Either numeric value or NA. Use to specify range of effect sizes.
#' @param mu Either a numeric value or a numeric vector (of length = level). Default : 0. Not recommended to modify.
#'
#' @return
#' A list with initialized interaction
#' @export
#'
#' @examples
#' init_variable(name = "myvarA", mu = 2, sd = 3, level = 200) %>%
#' init_variable(name = "myvarB", mu = 1, sd = 0.2, level = 2 ) %>%
#' add_interaction(between_var = c("myvarA", "myvarB"), mu = 3, sd = 2)
add_interaction <- function(list_var, between_var, mu, sd = NA) {
#' init_variable(name = "myvarA", sd = 3, level = 200) %>%
#' init_variable(name = "myvarB", sd = 0.2, level = 2 ) %>%
#' add_interaction(between_var = c("myvarA", "myvarB"), sd = 2)
add_interaction <- function(list_var, between_var, sd = NA, mu = 0) {
name_interaction <- paste(between_var, collapse = ":")
check_input2interaction(name_interaction, list_var, between_var, mu, sd)
......@@ -7819,12 +7820,9 @@ evaluation_report <- function(mock_obj, list_gene = NULL,
list_tmb <- list_tmb[list_gene]
}
## -- eval data
eval_data <- get_eval_data(list_tmb, dds, mock_obj, coeff_threshold, alt_hypothesis)
## -- identity plot
#identity_data <- rbind_model_params_and_dispersion(eval_data)
params_identity_eval <- eval_identityTerm( eval_data$modelparams, palette_color, palette_shape )
dispersion_identity_eval <- eval_identityTerm(eval_data$modeldispersion, palette_color, palette_shape)
......@@ -7834,6 +7832,12 @@ evaluation_report <- function(mock_obj, list_gene = NULL,
eval_data2metrics <- eval_data$modelparams
}
## aggregate RMSE + R2
rmse_modelparams <- compute_rmse(eval_data2metrics, grouping_by = "from")
rsquare_modelparams <- compute_rsquare(eval_data2metrics, grouping_by = "from")
rsquare_modelparams$from <- NULL
aggregate_metrics <- cbind(rmse_modelparams, rsquare_modelparams)
## -- counts plot
counts_violinplot <- counts_plot(mock_obj)
......@@ -7848,9 +7852,11 @@ evaluation_report <- function(mock_obj, list_gene = NULL,
return(
list(
data = eval_data,
identity = list( params = params_identity_eval$p,
identity = list(params = params_identity_eval$p,
dispersion = dispersion_identity_eval$p ),
counts = counts_violinplot
counts = counts_violinplot,
performances = list(byparams = rbind(dispersion_identity_eval$R2, params_identity_eval$R2),
aggregate = aggregate_metrics )
))
......@@ -7870,7 +7876,8 @@ evaluation_report <- function(mock_obj, list_gene = NULL,
## -- acc, recall, sensib, speci, ...
metrics_obj <- get_ml_metrics_obj(eval_data2metrics, alpha_risk )
## -- merge all metrics in one obj
model_perf_obj <- get_performances_metrics_obj( r2_params = params_identity_eval$R2,
model_perf_obj <- get_performances_metrics_obj( r2_params = params_identity_eval$R2,
r2_agg = aggregate_metrics,
dispersion_identity_eval$R2,
pr_curve_obj,
roc_curve_obj,
......@@ -7910,15 +7917,16 @@ evaluation_report <- function(mock_obj, list_gene = NULL,
#' The function generates separate data frames for metric values by parameter value and for the
#' aggregated metric values.
#'
#' @param r2_params R-squared values from model parameters evaluation object.
#' @param r2_dispersion R-squared values from dispersion evaluation object.
#' @param r2_params R-squared and RMSE values from model parameters evaluation object.
#' @param r2_agg R-squared and RMSE values aggregated.
#' @param r2_dispersion R-squared and RMSE values from dispersion evaluation object.
#' @param pr_obj PR object generated from evaluation report.
#' @param roc_obj ROC object generated from evaluation report.
#' @param ml_metrics_obj Machine learning performance metrics object.
#'
#' @return A list containing separate data frames for by-parameter and aggregated metric values.
#' @export
get_performances_metrics_obj <- function(r2_params , r2_dispersion,
get_performances_metrics_obj <- function(r2_params , r2_agg ,r2_dispersion,
pr_obj, roc_obj, ml_metrics_obj ){
## -- by params
auc_mtrics_params <- join_dtf(pr_obj$byparams$pr_auc , roc_obj$byparams$roc_auc,
......@@ -7933,6 +7941,8 @@ get_performances_metrics_obj <- function(r2_params , r2_dispersion,
k1 = c("from"), k2 = c("from"))
metrics_agg <- join_dtf(auc_mtrics_agg , ml_metrics_obj$aggregate,
k1 = c("from"), k2 = c("from"))
metrics_agg <- join_dtf(metrics_agg, r2_agg,
k1 = c("from"), k2 = c("from"))
return(list(byparams = metrics_params, aggregate = metrics_agg ))
}
......@@ -8064,8 +8074,6 @@ test_that("isValidEvalInput with valid input", {
test_that("evaluation_report returns correct output", {
N_GENES <- 100
MAX_REPLICATES <- 5
MIN_REPLICATES <- 5
......@@ -8127,8 +8135,12 @@ test_that("get_performances_metrics_obj returns correct output", {
recall = c(0.09, 0.88)),
aggregate = data.frame(from = c("Glm", "Hglm"),
accuracy = c(0.7, 0.6), recall = c(0.1, 0.8)))
r2_agg <- data.frame(from = c("Glm", "Hglm"),
RMSE = c(0.22, 0.55),
R2 = c(0.9, 0.7))
# Call the function
result <- get_performances_metrics_obj(r2_params, r2_dispersion,
result <- get_performances_metrics_obj(r2_params, r2_agg, r2_dispersion,
pr_obj, roc_obj, ml_metrics_obj)
# Test the output
......@@ -8138,7 +8150,7 @@ test_that("get_performances_metrics_obj returns correct output", {
expect_equal(nrow(result$byparams), 6)
expect_equal(ncol(result$byparams), 7)
expect_equal(nrow(result$aggregate), 2)
expect_equal(ncol(result$aggregate), 5)
expect_equal(ncol(result$aggregate), 7)
})
......@@ -8193,7 +8205,6 @@ test_that("get_ml_metrics_obj returns correct output", {
```
......@@ -8565,8 +8576,8 @@ test_that("get_eval_data returns correct output", {
#' MAX_REPLICATES = 5
#' MIN_REPLICATES = 5
#' ## --init variable
#' input_var_list <- init_variable( name = "genotype", mu = 12, sd = 0.1, level = 3) %>%
#' init_variable(name = "environment", mu = c(0,1), NA , level = 2)
#' input_var_list <- init_variable( name = "genotype", sd = 0.1, level = 3) %>%
#' init_variable(name = "environment", NA , level = 2)
#'
#' mock_data <- mock_rnaseq(input_var_list, N_GENES, MIN_REPLICATES, MAX_REPLICATES)
#' dds <- DESeq2::DESeqDataSetFromMatrix(mock_data$counts ,
......@@ -9136,7 +9147,7 @@ test_that("RMSE function calculates correct RMSE values", {
#' N_GENES = 100
#' MAX_REPLICATES = 5
#' MIN_REPLICATES = 5
#' input_var_list <- init_variable(name = "varA", mu = 10, sd = 0.1, level = 3)
#' input_var_list <- init_variable(name = "varA", sd = 0.1, level = 3)
#' mock_data <- mock_rnaseq(input_var_list, N_GENES,
#' min_replicates = MIN_REPLICATES,
#' max_replicates = MAX_REPLICATES)
......@@ -9711,7 +9722,8 @@ isValidEval_report <- function(obj){
stop("All elements in 'obj' are NULL")
}
## level 1
expected_names <- c("data", "identity", "precision_recall", "roc", "counts", "performances")
expected_names <- c("data", "identity", "counts", "performances")
## N.B : "precision_recall", "roc" names are not mandatory
if (!all(expected_names %in% names(obj))) {
stop(message_err)
}
......@@ -9782,15 +9794,21 @@ export_evaluation_report <- function(eval_report_obj, outfolder, plot_format = "
#' @importFrom ggplot2 ggsave
#' @export
export_eval_plots <- function(eval_report_obj, extension, ...){
dir.create("plots", showWarnings = FALSE)
setwd("./plots")
ggplot2::ggsave(filename = paste("identity_modelparams" , extension, sep = "."), eval_report_obj$identity$params, ...)
ggplot2::ggsave(filename = paste("identity_modeldispersion" , extension, sep = "."), eval_report_obj$identity$dispersion )
ggplot2::ggsave(filename = paste("precision_recall_byparams" , extension, sep = "."), eval_report_obj$precision_recall$params )
ggplot2::ggsave(filename = paste("precision_recall_aggregated" , extension, sep = "."), eval_report_obj$precision_recall$aggregate)
ggplot2::ggsave(filename = paste("roc_byparams" , extension, sep = "."), eval_report_obj$roc$params )
ggplot2::ggsave(filename = paste("roc_aggregated" , extension, sep = "."), eval_report_obj$roc$aggregate )
ggplot2::ggsave(filename = paste("genes_expression" , extension, sep = "."), eval_report_obj$counts)
if (all(c("roc", "precision_recall") %in% names(eval_report_obj))){
ggplot2::ggsave(filename = paste("precision_recall_byparams" , extension, sep = "."), eval_report_obj$precision_recall$params )
ggplot2::ggsave(filename = paste("precision_recall_aggregated" , extension, sep = "."), eval_report_obj$precision_recall$aggregate)
ggplot2::ggsave(filename = paste("roc_byparams" , extension, sep = "."), eval_report_obj$roc$params )
ggplot2::ggsave(filename = paste("roc_aggregated" , extension, sep = "."), eval_report_obj$roc$aggregate )
}
}
......
......@@ -4,16 +4,16 @@
\alias{add_interaction}
\title{Add interaction}
\usage{
add_interaction(list_var, between_var, mu, sd = NA)
add_interaction(list_var, between_var, sd = NA, mu = 0)
}
\arguments{
\item{list_var}{A list of variables (already initialized)}
\item{between_var}{A vector of variable names to include in the interaction}
\item{mu}{Either a numeric value or a numeric vector (of length = level)}
\item{sd}{Either numeric value or NA. Use to specify range of effect sizes.}
\item{sd}{Either numeric value or NA}
\item{mu}{Either a numeric value or a numeric vector (of length = level). Default : 0. Not recommended to modify.}
}
\value{
A list with initialized interaction
......@@ -22,7 +22,7 @@ A list with initialized interaction
Add interaction
}
\examples{
init_variable(name = "myvarA", mu = 2, sd = 3, level = 200) \%>\%
init_variable(name = "myvarB", mu = 1, sd = 0.2, level = 2 ) \%>\%
add_interaction(between_var = c("myvarA", "myvarB"), mu = 3, sd = 2)
init_variable(name = "myvarA", sd = 3, level = 200) \%>\%
init_variable(name = "myvarB", sd = 0.2, level = 2 ) \%>\%
add_interaction(between_var = c("myvarA", "myvarB"), sd = 2)
}
......@@ -6,6 +6,7 @@
\usage{
get_performances_metrics_obj(
r2_params,
r2_agg,
r2_dispersion,
pr_obj,
roc_obj,
......@@ -13,9 +14,11 @@ get_performances_metrics_obj(
)
}
\arguments{
\item{r2_params}{R-squared values from model parameters evaluation object.}
\item{r2_params}{R-squared and RMSE values from model parameters evaluation object.}
\item{r2_dispersion}{R-squared values from dispersion evaluation object.}
\item{r2_agg}{R-squared and RMSE values aggregated.}
\item{r2_dispersion}{R-squared and RMSE values from dispersion evaluation object.}
\item{pr_obj}{PR object generated from evaluation report.}
......
......@@ -4,24 +4,18 @@
\alias{init_variable}
\title{Initialize variable}
\usage{
init_variable(
list_var = c(),
name = "myVariable",
mu = c(2, 3),
sd = NA,
level = NA
)
init_variable(list_var = c(), name = "myVariable", sd = NA, level = NA, mu = 0)
}
\arguments{
\item{list_var}{Either c() or output of init_variable}
\item{name}{Variable name}
\item{mu}{Either a numeric value or a numeric vector (of length = level)}
\item{sd}{Either numeric value or NA}
\item{sd}{Either numeric value or NA. Use to specify range of effect sizes.}
\item{level}{Numeric value to specify the number of levels to simulate}
\item{mu}{Either a numeric value or a numeric vector (of length = level). Default : 0. Not recommended to modify.}
}
\value{
A list with initialized variables
......@@ -30,5 +24,5 @@ A list with initialized variables
Initialize variable
}
\examples{
init_variable(name = "my_varA", mu = 2, sd = 9, level = 200)
init_variable(name = "my_varA", sd = 9, level = 200)
}
......@@ -24,7 +24,7 @@ This function filters and adjusts genomic data within the Roxygeb project, based
N_GENES = 100
MAX_REPLICATES = 5
MIN_REPLICATES = 5
input_var_list <- init_variable(name = "varA", mu = 10, sd = 0.1, level = 3)
input_var_list <- init_variable(name = "varA", sd = 0.1, level = 3)
mock_data <- mock_rnaseq(input_var_list, N_GENES,
min_replicates = MIN_REPLICATES,
max_replicates = MAX_REPLICATES)
......
......@@ -31,8 +31,8 @@ N_GENES = 100
MAX_REPLICATES = 5
MIN_REPLICATES = 5
## --init variable
input_var_list <- init_variable( name = "genotype", mu = 12, sd = 0.1, level = 3) \%>\%
init_variable(name = "environment", mu = c(0,1), NA , level = 2)
input_var_list <- init_variable( name = "genotype", sd = 0.1, level = 3) \%>\%
init_variable(name = "environment", NA , level = 2)
mock_data <- mock_rnaseq(input_var_list, N_GENES, MIN_REPLICATES, MAX_REPLICATES)
dds <- DESeq2::DESeqDataSetFromMatrix(mock_data$counts ,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment