From 96c6bbb0f3c9bb8fe73054f7a04efc0fdfe25c1b Mon Sep 17 00:00:00 2001 From: ChVav Date: Tue, 9 Apr 2024 11:23:47 +0200 Subject: [PATCH 1/3] fix selbal() to take variables form logCounts (and not x), cmultRepl2() may remove variables --- .Rbuildignore | 2 ++ R/Selbal_Functions.R | 18 +++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) create mode 100644 .Rbuildignore diff --git a/.Rbuildignore b/.Rbuildignore new file mode 100644 index 0000000..91114bf --- /dev/null +++ b/.Rbuildignore @@ -0,0 +1,2 @@ +^.*\.Rproj$ +^\.Rproj\.user$ diff --git a/R/Selbal_Functions.R b/R/Selbal_Functions.R index 54c2b5a..7c656b3 100644 --- a/R/Selbal_Functions.R +++ b/R/Selbal_Functions.R @@ -202,8 +202,8 @@ # Define the first balance A1 <- first.bal(logCounts, Y = numy, covar=covar) # Variables taking parti into the first balance - POS <- colnames(x)[A1[1,1]] - NEG <- colnames(x)[A1[1,2]] + POS <- colnames(logCounts)[A1[1,1]] + NEG <- colnames(logCounts)[A1[1,2]] # Included variables in the model INC.VAR <- c(POS, NEG) @@ -395,13 +395,13 @@ #----------------------------------------------------------------------------# # FINAL GLM #----------------------------------------------------------------------------# - + # Auxiliar data.frame for graphical representation U <- data.frame(dat, FINAL.BAL) colnames(U)[ncol(U)] <- "V1" # Regression model - FIT.final <- glm(numy~., data=U, family = f.class) - + FIT.final <- glm(numy~., data=U, family = f.class) + # Draw the plot if draw == T if (draw){ #----------------------------------------------------------------------------# @@ -543,7 +543,7 @@ FINAL.P <- arrangeGrob(Imp.table, ROC.plot, BoxP, ydensity, ncol=2, nrow=2, widths=c(5,1.25), heights=c(2, 5), vp=viewport(width=0.8, height=0.8)) - + library(gtable) g1 <- ggplotGrob(Imp.table2) g2 <- ggplotGrob(BoxP2) @@ -552,7 +552,7 @@ g <- rbind(g, g3, size = "first") g$widths <- unit.pmax(g1$widths,g2$widths) FINAL.P2 <- g - + } else { # Fit the regression model @@ -1977,8 +1977,8 @@ g <- rbind(g, g3, size = "first") g$widths <- unit.pmax(g1$widths,g2$widths) FINAL.P2 <- g - - + + # Build a list with the elements of interest L <- list(Global.plot = FINAL.P,Global.plot2 = FINAL.P2, ROC.plot = ROC.plot) From da7cce7b98bd2f1bc13a4acd79d850c20583e847 Mon Sep 17 00:00:00 2001 From: ChVav Date: Tue, 9 Apr 2024 11:28:50 +0200 Subject: [PATCH 2/3] fix selbal() set rem.nam and var.nam using logCounts --- R/Selbal_Functions.R | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/R/Selbal_Functions.R b/R/Selbal_Functions.R index 7c656b3..5726c17 100644 --- a/R/Selbal_Functions.R +++ b/R/Selbal_Functions.R @@ -37,9 +37,6 @@ # Load library suppressMessages(library(zCompositions)) - # Variables name - var.nam <- rem.nam <- colnames(x) - # Build a table with the response variable and covariates for correction if (!is.null(covar)){ dat <- data.frame(cbind(numy, covar)) } else { dat <-data.frame(numy)} @@ -50,6 +47,10 @@ logCounts <- log(cmultRepl2(x, zero.rep = zero.rep)) } + # Variables name + var.nam <- rem.nam <- colnames(logCounts) + + #--------------------------------------------------------------------------# # 0.3: auxiliar functions From c2aa2fce1eb9742d82827a6151abd89625952bb4 Mon Sep 17 00:00:00 2001 From: ChVav Date: Tue, 9 Apr 2024 15:16:22 +0200 Subject: [PATCH 3/3] fix selbal.aux() set rem.nam and var.nam using logCounts --- R/Selbal_Functions.R | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/R/Selbal_Functions.R b/R/Selbal_Functions.R index 5726c17..4fbf6b1 100644 --- a/R/Selbal_Functions.R +++ b/R/Selbal_Functions.R @@ -1041,10 +1041,10 @@ }else{ df.boxplot <- data.frame(mean = ACC.mean, se = ACC.se, n =2:maxV) - ylabelName="Accuracy (AUC)"; - if (logit.acc=="Dev"){ - ylabelName="Explained Deviance"; - } + ylabelName="Accuracy (AUC)"; + if (logit.acc=="Dev"){ + ylabelName="Explained Deviance"; + } # Load library library(ggplot2) # The plot @@ -1343,21 +1343,19 @@ # Load library suppressMessages(library(zCompositions)) - # Variables name - var.nam <- rem.nam <- colnames(x) - # Build a table with the response variable and covariates for correction if (!is.null(covar)){ dat <- data.frame(cbind(numy, covar)) } else { dat <-data.frame(numy)} - - # The logCounts (with zero replacement) if (logt == F){ logCounts <- x } else{ logCounts <- log(cmultRepl2(x, zero.rep = zero.rep)) } + # Variables name + var.nam <- rem.nam <- colnames(logCounts) + #--------------------------------------------------------------------------# # 0.3: auxiliar functions