From b90d0886dcfe64ba560c86629d9be6b4f29b3527 Mon Sep 17 00:00:00 2001 From: Marlena Bannick Date: Mon, 8 Apr 2024 11:49:23 -0700 Subject: [PATCH 1/2] Fixed printing error for formula used with glm.nb --- R/description-glm.R | 6 +++++- tests/testthat/test-glm.R | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/R/description-glm.R b/R/description-glm.R index 3c157ea..08e2d72 100644 --- a/R/description-glm.R +++ b/R/description-glm.R @@ -20,7 +20,11 @@ descript.GLMModelResult <- function(x, ...){ if(!is.null(x$data$formula)){ - form <- x$mod$formula + if(x$settings$g_family == "nb"){ + form <- x$data$formula + } else { + form <- x$mod$formula + } output <- c( output, sprintf("Treatment group mean estimates from a GLM working model of family %s and link %s using formula: \n", diff --git a/tests/testthat/test-glm.R b/tests/testthat/test-glm.R index af67183..19f14cc 100644 --- a/tests/testthat/test-glm.R +++ b/tests/testthat/test-glm.R @@ -241,6 +241,21 @@ test_that("GLM full function -- NEGATIVE binomial, permuted block", { covariate_to_include_strata=TRUE) expect_equal(class(non), "GLMModelResult") + non + + # Test with formula + non <- robincar_glm2( + df=DATA2, + response_col="y", + treat_col="A", + car_strata_cols=c("z1"), + formula="y ~ A + z1", + car_scheme="permuted-block", + g_family="nb", + g_accuracy=7) + + non + }) test_that("GLM Settings", { From 99f5a95e17e61622c01bc1ee9006a0d7471336cf Mon Sep 17 00:00:00 2001 From: Marlena Bannick Date: Mon, 8 Apr 2024 12:18:31 -0700 Subject: [PATCH 2/2] Updated description for formula to avoid warnings that cause R CMD check to fail. --- R/description-glm.R | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/R/description-glm.R b/R/description-glm.R index 08e2d72..91eb0cf 100644 --- a/R/description-glm.R +++ b/R/description-glm.R @@ -6,6 +6,7 @@ descript.GLMModelResult <- function(x, ...){ } else { etype <- "g-computation-type" } + if(is.character(x$settings$g_family)){ if(x$settings$g_family == "nb"){ family <- "negative binomial with unknown dispersion" @@ -20,11 +21,16 @@ descript.GLMModelResult <- function(x, ...){ if(!is.null(x$data$formula)){ - if(x$settings$g_family == "nb"){ - form <- x$data$formula + if(is.character(x$settings$g_family)){ + if(x$settings$g_family == "nb"){ + form <- x$data$formula + } else { + form <- x$mod$formula + } } else { form <- x$mod$formula } + output <- c( output, sprintf("Treatment group mean estimates from a GLM working model of family %s and link %s using formula: \n",