From f79047db94d1cf9589dadc55f5354e4800b9d058 Mon Sep 17 00:00:00 2001 From: Flavio Lozano Isla Date: Sat, 6 Jul 2024 16:17:22 -0500 Subject: [PATCH] fix plot diag --- DESCRIPTION | 2 +- NAMESPACE | 1 + NEWS.md | 3 ++- R/gdoc2qmd.R | 6 +++--- R/plot_diag.R | 10 ++++++---- R/remove_outliers.R | 13 ++++++------- man/plot_diag.Rd | 6 +++--- man/remove_outliers.Rd | 13 ++++++------- 8 files changed, 28 insertions(+), 26 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3733422f..69e4e505 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -44,4 +44,4 @@ VignetteBuilder: knitr License: GPL-3 | file LICENSE LazyData: true Encoding: UTF-8 -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 diff --git a/NAMESPACE b/NAMESPACE index 5d61f2f9..70380290 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -77,6 +77,7 @@ importFrom(shiny,runGadget) importFrom(stats,anova) importFrom(stats,aov) importFrom(stats,as.formula) +importFrom(stats,density) importFrom(stats,fitted) importFrom(stats,lm) importFrom(stats,median) diff --git a/NEWS.md b/NEWS.md index 0ca20880..267e9aaa 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,7 +9,8 @@ # inti 0.6.6 - Package - - Update function to remove outliers => "`remove_outliers`" + - Update function to outliers_remove => "`remove_outliers`" + - Update function `plot_diag()` - Rticles - Fix Tables and Figures order in final document diff --git a/R/gdoc2qmd.R b/R/gdoc2qmd.R index c7215af9..e39a0f32 100644 --- a/R/gdoc2qmd.R +++ b/R/gdoc2qmd.R @@ -114,11 +114,11 @@ gdoc2qmd <- function(file tab <- txt %>% dplyr::filter(grepl("^\\|", .data$value) | grepl("#tbl", .data$value)) %>% - ungroup() %>% - mutate(group = case_when( + dplyr::ungroup() %>% + dplyr::mutate(group = case_when( grepl("#tbl", .data$value) ~ .data$name )) %>% - tidyr::fill(., group, .direction = "up") %>% + tidyr::fill(., .data$group, .direction = "up") %>% split(.$group) %>% purrr::map_dfr(~ slice(.data = ., c(n(), 1:(n()-1)))) %>% split(.$group) %>% diff --git a/R/plot_diag.R b/R/plot_diag.R index 1e2b3fb0..8bad7f15 100644 --- a/R/plot_diag.R +++ b/R/plot_diag.R @@ -7,17 +7,19 @@ #' #' @return plots #' +#' @importFrom stats density +#' #' @export #' #' @examples #' #' \dontrun{ #' -#' dt <- potato +#' library(inti) #' -#' lm <- aov(stemdw ~ bloque + geno*treat, dt) +#' lm <- aov(stemdw ~ bloque + geno*treat, data = potato) #' -#' #lm <- lme4::lmer(stemdw ~ bloque + (1|geno:treat), dt) +#' #lm <- lme4::lmer(stemdw ~ bloque + (1|geno:treat), data = potato) #' #' plot(lm, which = 1) #' plot_diag(lm)[3] @@ -52,7 +54,7 @@ plot_diag <- function( model, title = NA) { # Histogram p1 <- ggplot(dt , aes(.data$.resid)) + - geom_histogram(aes(y = after_stat(density)), + geom_histogram(aes(y = ggplot2::after_stat(density)), color = "black", fill = "grey82", bins = 30) + stat_function(fun = stats::dnorm, color = "blue", args = list(mean = 0, sd = sd(dt$.resid))) + theme_bw() + diff --git a/R/remove_outliers.R b/R/remove_outliers.R index e6ad7fe0..52b192c8 100644 --- a/R/remove_outliers.R +++ b/R/remove_outliers.R @@ -3,9 +3,9 @@ #' Function to remove outliers in MET experiments #' #' @param data Experimental design data frame with the factors and traits. -#' @param trait Name of the trait. -#' @param model The fixed or random effects in the model. +#' @param formula mixed model formula. #' @param drop_na drop NA values from the data.frame +#' @param plot_diag Diagnostic plot based in the raw and clean data #' #' @description #' @@ -30,11 +30,10 @@ #' #' library(inti) #' -#' rmout <- remove_outliers( -#' data = potato -#' , formula = stemdw ~ 0 + (1|bloque) + treat*geno + geno +#' rmout <- remove_outliers(data = potato +#' , formula = stemdw ~ 0 + (1|bloque) + treat*geno #' , drop_na = FALSE -#' , plot_diag = TRUE +#' , plot_diag = FALSE #' ) #' #' rmout @@ -47,7 +46,7 @@ remove_outliers <- function(data ) { # data = potato; drop_na = TRUE; plot_diag = TRUE - # formula = stemdw ~ 0 + (1|bloque) + treat*geno+ geno + # formula = stemdw ~ 0 + (1|bloque) + treat*geno out_flag <- bholm <- NULL diff --git a/man/plot_diag.Rd b/man/plot_diag.Rd index 80923a2b..8bc6cb3d 100644 --- a/man/plot_diag.Rd +++ b/man/plot_diag.Rd @@ -21,11 +21,11 @@ Function to plot the diagnostic of models \dontrun{ -dt <- potato +library(inti) -lm <- aov(stemdw ~ bloque + geno*treat, dt) +lm <- aov(stemdw ~ bloque + geno*treat, data = potato) -#lm <- lme4::lmer(stemdw ~ bloque + (1|geno:treat), dt) +#lm <- lme4::lmer(stemdw ~ bloque + (1|geno:treat), data = potato) plot(lm, which = 1) plot_diag(lm)[3] diff --git a/man/remove_outliers.Rd b/man/remove_outliers.Rd index 8be156ba..4de38b20 100644 --- a/man/remove_outliers.Rd +++ b/man/remove_outliers.Rd @@ -9,11 +9,11 @@ remove_outliers(data, formula, drop_na = TRUE, plot_diag = FALSE) \arguments{ \item{data}{Experimental design data frame with the factors and traits.} -\item{drop_na}{drop NA values from the data.frame} +\item{formula}{mixed model formula.} -\item{trait}{Name of the trait.} +\item{drop_na}{drop NA values from the data.frame} -\item{model}{The fixed or random effects in the model.} +\item{plot_diag}{Diagnostic plot based in the raw and clean data} } \value{ list. 1. Table with date without outliers. 2. The outliers in the @@ -30,11 +30,10 @@ Function to remove outliers in MET experiments library(inti) -rmout <- remove_outliers( - data = potato - , formula = stemdw ~ 0 + (1|bloque) + treat*geno + geno +rmout <- remove_outliers(data = potato + , formula = stemdw ~ 0 + (1|bloque) + treat*geno , drop_na = FALSE - , plot_diag = TRUE + , plot_diag = FALSE ) rmout