From cca3cedf7930380023e09a03f55afc17726be79c Mon Sep 17 00:00:00 2001 From: Josh Sumner <51797700+joshqsumner@users.noreply.github.com> Date: Wed, 11 Feb 2026 08:23:04 -0600 Subject: [PATCH 1/8] docs update --- R/stat_growthSS.R | 6 +++--- man/stat_growthss.Rd | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/R/stat_growthSS.R b/R/stat_growthSS.R index 8d1e0244..c9a15074 100644 --- a/R/stat_growthSS.R +++ b/R/stat_growthSS.R @@ -12,7 +12,7 @@ #' This behaves per normal ggplot2 expectations except #' that if data is missing (ie, not inherited or specified) then the data from \code{ss} is used. #' @param fit A model object returned from \code{fitGrowth}. -#' @param ss A \code{pcvrss} object. Only the "pcvrForm" and "df" elements are used. +#' @param ss A \code{\link{pcvrss-class}} object. Only the "pcvrForm" and "df" elements are used. #' @param inherit.aes Logical, should aesthetics be inherited from top level? Defaults to TRUE. #' @param CI A vector of credible intervals to plot, defaults to 0.95. #' @param ... Additional arguments passed to the ggplot layer. @@ -25,8 +25,8 @@ #' \item{\strong{brms}: \code{geom_ribbon} for longitudinal plots, \code{geom_rect} for others.} #' \item{\strong{nlrq}: \code{geom_line}, replicated per each quantile.} #' \item{\strong{nlme}: \code{geom_smooth}, with ribbon based on the heteroskedastic term.} -#' \item{\strong{nls}: \code{geom_line}, replicated per each quantile.} -#' \item{\strong{nlrq}: \code{geom_line}, replicated per each quantile.} +#' \item{\strong{nls}: \code{geom_line}.} +#' \item{\strong{nlrq}: \code{geom_smooth}.} #' } #' #' @examples diff --git a/man/stat_growthss.Rd b/man/stat_growthss.Rd index 528ca468..3f359fd8 100644 --- a/man/stat_growthss.Rd +++ b/man/stat_growthss.Rd @@ -77,7 +77,7 @@ that if data is missing (ie, not inherited or specified) then the data from \cod \item{fit}{A model object returned from \code{fitGrowth}.} -\item{ss}{A \code{pcvrss} object. Only the "pcvrForm" and "df" elements are used.} +\item{ss}{A \code{\link{pcvrss-class}} object. Only the "pcvrForm" and "df" elements are used.} \item{CI}{A vector of credible intervals to plot, defaults to 0.95.} @@ -97,8 +97,8 @@ The geometries used for each type of model are: \item{\strong{brms}: \code{geom_ribbon} for longitudinal plots, \code{geom_rect} for others.} \item{\strong{nlrq}: \code{geom_line}, replicated per each quantile.} \item{\strong{nlme}: \code{geom_smooth}, with ribbon based on the heteroskedastic term.} - \item{\strong{nls}: \code{geom_line}, replicated per each quantile.} - \item{\strong{nlrq}: \code{geom_line}, replicated per each quantile.} + \item{\strong{nls}: \code{geom_line}.} + \item{\strong{nlrq}: \code{geom_smooth}.} } } \examples{ From 9771a06831e9985315b15586ddd2b53eb50fd7f2 Mon Sep 17 00:00:00 2001 From: Josh Sumner <51797700+joshqsumner@users.noreply.github.com> Date: Wed, 11 Feb 2026 08:27:00 -0600 Subject: [PATCH 2/8] adding hierarchical_value argument and updating docs for it --- R/brmPlot.R | 7 ++++--- R/stat_brms_model.R | 1 + R/stat_growthSS.R | 5 +++++ man/brmPlot.Rd | 7 ++++--- man/stat_growthss.Rd | 7 +++++++ 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/R/brmPlot.R b/R/brmPlot.R index c0e1ef43..377d5d40 100644 --- a/R/brmPlot.R +++ b/R/brmPlot.R @@ -14,9 +14,10 @@ #' future data if the available data has not reached some point (such as asymptotic size), #' although prediction using splines outside of the observed range is not necessarily reliable. #' @param facetGroups logical, should groups be separated in facets? Defaults to TRUE. -#' @param hierarchy_value If a hierarchical model is being plotted, what value should the -#' hierarchical predictor be? If left NULL (the default) the mean value is used. If this is >1L -#' then the x axis will use the hierarchical variable from the model at the mean of the timeRange +#' @param hierarchy_value Value(s) for the hierarchical variable(s), if applicable. Only used +#' for hierarchical brms models. If left NULL (the default) the mean value is used. If this is >1L +#' then the x axis will use the hierarchical variable from the model instead of the "time" variable +#' and plot data across the values of the hierarchical variable at the mean of the timeRange #' (mean of x values in the model if timeRange is not specified). #' @param vir_option Viridis color scale to use for plotting credible intervals. Defaults to "plasma". #' @keywords growth-curve brms diff --git a/R/stat_brms_model.R b/R/stat_brms_model.R index d36113d8..a0879d6c 100644 --- a/R/stat_brms_model.R +++ b/R/stat_brms_model.R @@ -5,6 +5,7 @@ stat_brms_model <- function(mapping = NULL, data = NULL, fit = NULL, ss = NULL, CI = 0.95, + hierarchy_value = NULL, inherit.aes = TRUE, ...) { # These would normally be arguments to a stat layer but they should not be changed geom <- "ribbon" diff --git a/R/stat_growthSS.R b/R/stat_growthSS.R index c9a15074..3e85306e 100644 --- a/R/stat_growthSS.R +++ b/R/stat_growthSS.R @@ -15,6 +15,11 @@ #' @param ss A \code{\link{pcvrss-class}} object. Only the "pcvrForm" and "df" elements are used. #' @param inherit.aes Logical, should aesthetics be inherited from top level? Defaults to TRUE. #' @param CI A vector of credible intervals to plot, defaults to 0.95. +#' @param hierarchy_value Value(s) for the hierarchical variable(s), if applicable. Only used +#' for hierarchical brms models. If left NULL (the default) the mean value is used. If this is >1L +#' then the x axis will use the hierarchical variable from the model instead of the "time" variable +#' and plot data across the values of the hierarchical variable at the mean of the timeRange +#' (mean of x values in the model if timeRange is not specified). #' @param ... Additional arguments passed to the ggplot layer. #' #' @details diff --git a/man/brmPlot.Rd b/man/brmPlot.Rd index a3c00cbf..918083c2 100644 --- a/man/brmPlot.Rd +++ b/man/brmPlot.Rd @@ -32,9 +32,10 @@ although prediction using splines outside of the observed range is not necessari \item{facetGroups}{logical, should groups be separated in facets? Defaults to TRUE.} -\item{hierarchy_value}{If a hierarchical model is being plotted, what value should the -hierarchical predictor be? If left NULL (the default) the mean value is used. If this is >1L -then the x axis will use the hierarchical variable from the model at the mean of the timeRange +\item{hierarchy_value}{Value(s) for the hierarchical variable(s), if applicable. Only used +for hierarchical brms models. If left NULL (the default) the mean value is used. If this is >1L +then the x axis will use the hierarchical variable from the model instead of the "time" variable +and plot data across the values of the hierarchical variable at the mean of the timeRange (mean of x values in the model if timeRange is not specified).} \item{vir_option}{Viridis color scale to use for plotting credible intervals. Defaults to "plasma".} diff --git a/man/stat_growthss.Rd b/man/stat_growthss.Rd index 3f359fd8..23547f03 100644 --- a/man/stat_growthss.Rd +++ b/man/stat_growthss.Rd @@ -16,6 +16,7 @@ stat_brms_model( fit = NULL, ss = NULL, CI = 0.95, + hierarchy_value = NULL, inherit.aes = TRUE, ... ) @@ -81,6 +82,12 @@ that if data is missing (ie, not inherited or specified) then the data from \cod \item{CI}{A vector of credible intervals to plot, defaults to 0.95.} +\item{hierarchy_value}{Value(s) for the hierarchical variable(s), if applicable. Only used +for hierarchical brms models. If left NULL (the default) the mean value is used. If this is >1L +then the x axis will use the hierarchical variable from the model instead of the "time" variable +and plot data across the values of the hierarchical variable at the mean of the timeRange +(mean of x values in the model if timeRange is not specified).} + \item{inherit.aes}{Logical, should aesthetics be inherited from top level? Defaults to TRUE.} \item{...}{Additional arguments passed to the ggplot layer.} From 2845cf6aa95c0e2440be6ae61f352e665aa66769 Mon Sep 17 00:00:00 2001 From: Josh Sumner <51797700+joshqsumner@users.noreply.github.com> Date: Wed, 11 Feb 2026 10:12:46 -0600 Subject: [PATCH 3/8] add hierarchy value statBrmsMod --- R/stat_brms_model.R | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/R/stat_brms_model.R b/R/stat_brms_model.R index a0879d6c..7a9b6122 100644 --- a/R/stat_brms_model.R +++ b/R/stat_brms_model.R @@ -30,12 +30,19 @@ stat_brms_model <- function(mapping = NULL, data = NULL, c(((1 - i) / 2), (i + (1 - i) / 2)) ) }) + # get hierarchy value if NULL + if (is.null(hierarchy_value) && !is.null(parsed_form$hierarchical_predictor)) { + hierarchy_value <- mean(fit$data[[parsed_form$hierarchical_predictor]]) + } # make layer for each of the intervals layers <- lapply(formatted_prob_list, function(prob_pair) { lyr <- ggplot2::layer( stat = stat, data = data, mapping = mapping, geom = geom, position = position, show.legend = show.legend, inherit.aes = inherit.aes, - params = list(na.rm = na.rm, fit = fit, parsed_form = parsed_form, probs = prob_pair, ...) + params = list( + na.rm = na.rm, fit = fit, parsed_form = parsed_form, + probs = prob_pair, hierarchy_value = hierarchy_value, ... + ) ) return(lyr) }) @@ -53,7 +60,7 @@ stat_brms_model <- function(mapping = NULL, data = NULL, statBrmsMod <- ggplot2::ggproto("StatBrm", Stat, # `specify that there will be extra params` - extra_params = c("na.rm", "fit", "parsed_form", "probs"), + extra_params = c("na.rm", "fit", "parsed_form", "probs", "hierarchy_value"), # `data setup function` setup_data = function(data, params) { #' possible that ss is not a pcvrss object for compatibility with other brms models @@ -123,14 +130,17 @@ statBrmsMod <- ggplot2::ggproto("StatBrm", Stat, #' the model and ss objects. compute_group = function(data, scales, fit = NULL, parsed_form = NULL, probs = NULL, + hierarchy_value = NULL, ...) { yvar <- parsed_form$y xvar <- parsed_form$x group <- parsed_form$group + hierarchy <- parsed_form$hierarchical_predictor # make data to use drawing posterior predictions nd <- data[, c("x", "MOD_GROUP", "PANEL")] nd <- nd[!duplicated(nd), ] colnames(nd) <- c(xvar, group, "PANEL") + nd[[hierarchy %||% "none"]] <- hierarchy_value # make predictions mod_data <- cbind(nd, predict(fit, newdata = nd, probs = probs)) # lengthen predictions as in brmPlot From fa533965251ccebcf57d0756feb5d093ea5341ea Mon Sep 17 00:00:00 2001 From: Josh Sumner <51797700+joshqsumner@users.noreply.github.com> Date: Wed, 11 Feb 2026 10:12:54 -0600 Subject: [PATCH 4/8] docs update --- R/stat_growthSS.R | 9 +++------ man/stat_growthss.Rd | 9 +++------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/R/stat_growthSS.R b/R/stat_growthSS.R index 3e85306e..673855cc 100644 --- a/R/stat_growthSS.R +++ b/R/stat_growthSS.R @@ -14,12 +14,9 @@ #' @param fit A model object returned from \code{fitGrowth}. #' @param ss A \code{\link{pcvrss-class}} object. Only the "pcvrForm" and "df" elements are used. #' @param inherit.aes Logical, should aesthetics be inherited from top level? Defaults to TRUE. -#' @param CI A vector of credible intervals to plot, defaults to 0.95. -#' @param hierarchy_value Value(s) for the hierarchical variable(s), if applicable. Only used -#' for hierarchical brms models. If left NULL (the default) the mean value is used. If this is >1L -#' then the x axis will use the hierarchical variable from the model instead of the "time" variable -#' and plot data across the values of the hierarchical variable at the mean of the timeRange -#' (mean of x values in the model if timeRange is not specified). +#' @param CI A vector of credible intervals to plot, defaults to 0.95. Only used with brms models. +#' @param hierarchy_value Value for the hierarchical variable, if applicable. Only used +#' for hierarchical brms models. If left NULL (the default) the mean value is used. #' @param ... Additional arguments passed to the ggplot layer. #' #' @details diff --git a/man/stat_growthss.Rd b/man/stat_growthss.Rd index 23547f03..83fb70ec 100644 --- a/man/stat_growthss.Rd +++ b/man/stat_growthss.Rd @@ -80,13 +80,10 @@ that if data is missing (ie, not inherited or specified) then the data from \cod \item{ss}{A \code{\link{pcvrss-class}} object. Only the "pcvrForm" and "df" elements are used.} -\item{CI}{A vector of credible intervals to plot, defaults to 0.95.} +\item{CI}{A vector of credible intervals to plot, defaults to 0.95. Only used with brms models.} -\item{hierarchy_value}{Value(s) for the hierarchical variable(s), if applicable. Only used -for hierarchical brms models. If left NULL (the default) the mean value is used. If this is >1L -then the x axis will use the hierarchical variable from the model instead of the "time" variable -and plot data across the values of the hierarchical variable at the mean of the timeRange -(mean of x values in the model if timeRange is not specified).} +\item{hierarchy_value}{Value for the hierarchical variable, if applicable. Only used +for hierarchical brms models. If left NULL (the default) the mean value is used.} \item{inherit.aes}{Logical, should aesthetics be inherited from top level? Defaults to TRUE.} From 7244533c9590bafe9838eda43a63104d68feea6b Mon Sep 17 00:00:00 2001 From: Josh Sumner <51797700+joshqsumner@users.noreply.github.com> Date: Wed, 11 Feb 2026 10:13:17 -0600 Subject: [PATCH 5/8] testing hierarchical geom --- tests/testthat/test-brmsModels.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/testthat/test-brmsModels.R b/tests/testthat/test-brmsModels.R index 11ce1ba0..277dfffc 100644 --- a/tests/testthat/test-brmsModels.R +++ b/tests/testthat/test-brmsModels.R @@ -212,6 +212,8 @@ test_that("Hierarchical Model Works", { expect_s3_class(p, "ggplot") p <- growthPlot(fit, ss$pcvrForm, df = ss$df, hierarchy_value = seq(8, 12, 1)) expect_s3_class(p, "ggplot") + p <- ggplot() + stat_growthss(fit = fit, ss = ss, hierarchy_value = 5) + expect_s3_class(p, "ggplot") }) test_that("Changepoint model can be specified", { From f364837fc2384092d2a9a6d2aec54aface0d1ff3 Mon Sep 17 00:00:00 2001 From: Josh Sumner <51797700+joshqsumner@users.noreply.github.com> Date: Wed, 11 Feb 2026 11:01:48 -0600 Subject: [PATCH 6/8] testing missed line --- tests/testthat/test-brmsModels.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/testthat/test-brmsModels.R b/tests/testthat/test-brmsModels.R index 277dfffc..62632e94 100644 --- a/tests/testthat/test-brmsModels.R +++ b/tests/testthat/test-brmsModels.R @@ -214,6 +214,8 @@ test_that("Hierarchical Model Works", { expect_s3_class(p, "ggplot") p <- ggplot() + stat_growthss(fit = fit, ss = ss, hierarchy_value = 5) expect_s3_class(p, "ggplot") + p <- ggplot() + stat_growthss(fit = fit, ss = ss) + expect_s3_class(p, "ggplot") }) test_that("Changepoint model can be specified", { From c21e5a05eb41e9c171a4921b78cf7cf1caeaa038 Mon Sep 17 00:00:00 2001 From: Josh Sumner <51797700+joshqsumner@users.noreply.github.com> Date: Wed, 11 Feb 2026 13:11:53 -0600 Subject: [PATCH 7/8] moving error condition --- R/pcvsubread.R | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/R/pcvsubread.R b/R/pcvsubread.R index 8d951a64..ff30a9de 100644 --- a/R/pcvsubread.R +++ b/R/pcvsubread.R @@ -25,5 +25,11 @@ pcv.sub.read <- function(inputFile, filters, reader = "read.csv", awk = NULL, .. x <- suppressMessages(as.data.frame(readingFunction(pipe(awkCommand), ...))) colnames(x) <- COLS } + if (nrow(x) < 1) { + stop(paste0( + "0 Rows returned using awk statement:\n", awkHelper(filepath, filters), + "\nMost common issues are misspellings or not including a column name and affector." + )) + } return(x) } From 6af3384d95887e61840820239b1938244bc42388 Mon Sep 17 00:00:00 2001 From: Josh Sumner <51797700+joshqsumner@users.noreply.github.com> Date: Wed, 11 Feb 2026 13:24:02 -0600 Subject: [PATCH 8/8] typo --- R/pcvsubread.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/pcvsubread.R b/R/pcvsubread.R index ff30a9de..fc3ce52d 100644 --- a/R/pcvsubread.R +++ b/R/pcvsubread.R @@ -27,7 +27,7 @@ pcv.sub.read <- function(inputFile, filters, reader = "read.csv", awk = NULL, .. } if (nrow(x) < 1) { stop(paste0( - "0 Rows returned using awk statement:\n", awkHelper(filepath, filters), + "0 Rows returned using awk statement:\n", awkCommand, "\nMost common issues are misspellings or not including a column name and affector." )) }