diff --git a/DESCRIPTION b/DESCRIPTION index 44d2af08..65983bda 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: serodynamics Title: What the Package Does (One Line, Title Case) -Version: 0.0.0.9037 +Version: 0.0.0.9038 Authors@R: c( person("Peter", "Teunis", , "p.teunis@emory.edu", role = c("aut", "cph"), comment = "Author of the method and original code."), diff --git a/NAMESPACE b/NAMESPACE index 3c1d9867..7d7a7d66 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,7 @@ # Generated by roxygen2: do not edit by hand S3method(autoplot,case_data) +S3method(print,sr_model) export(as_case_data) export(autoplot) export(get_biomarker_levels) diff --git a/NEWS.md b/NEWS.md index ba03f7d2..efa649eb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,10 @@ # serodynamics (development version) +* Initial CRAN submission. + +## New features + +* Creating default print.sr_model function for sr_model class (#114) * Added support for faceting by multiple IDs in `plot_predicted_curve()`: - New `facet_by_id` argument allows faceted plots by participant ID. * Added `plot_predicted_curve()` (#68) diff --git a/R/Run_Mod.R b/R/Run_Mod.R index b91c8e91..3dee30ca 100644 --- a/R/Run_Mod.R +++ b/R/Run_Mod.R @@ -200,4 +200,5 @@ run_mod <- function(data, jags_out <- jags_out |> structure(class = union("sr_model", class(jags_out))) jags_out + } diff --git a/R/print.sr_model.R b/R/print.sr_model.R new file mode 100644 index 00000000..a10f930b --- /dev/null +++ b/R/print.sr_model.R @@ -0,0 +1,35 @@ +#' @title Default print for [serodynamics::run_mod()] output object of class +#' `sr_model` +#' @description +#' A default print method for class `sr_model` that includes the median +#' posterior distribution for antibody kinetic curve parameters by `Iso_type` +#' and `Stratification` (if specified). +#' @param x An `sr_model` output object from [run_mod()]. +#' @param ... Additional arguments affecting the summary produced. +#' [serodynamics::run_mod()] function. +#' @returns A data summary that +#' contains the mean posterior distribution for antibody kinetic curve +#' parameters by `Iso_type` and `Stratification` (if specified). +#' @export +#' @examples +#' print(nepal_sees_jags_output) +print.sr_model <- function(x, ...) { # nolint + + cat("An sr_model with the following median values:") + cat("\n") + cat("\n") + x <- x |> + dplyr::summarise(.by = c(.data$Stratification, .data$Iso_type, + .data$Parameter), + median_val = stats::median(.data$value)) |> + tidyr::pivot_wider(names_from = .data$Parameter, + values_from = .data$median_val) |> + dplyr::arrange(.data$Iso_type) |> + suppressWarnings() + # Taking out stratification column if not specified + if (unique(x$Stratification == "None")) { + x <- x |> select(-c(.data$Stratification)) + } + print(as.data.frame(x)) + invisible(x) +} diff --git a/inst/WORDLIST b/inst/WORDLIST index b6f7538f..a964b9f1 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -1,6 +1,8 @@ +Biomarker CMD CodeFactor Codecov +Hyperpriors JAGs Lifecycle Postprocess @@ -9,6 +11,8 @@ Traceplots behaviour biomarker biomarkers +bmatrix +cdot dobson dotplots geoms @@ -16,22 +20,28 @@ ggproto hyp hyperprior hyperpriors +ij iso isotype isotypes +mathcal mcmc nmc +overfit params prec +pred rhat sd seroconversion serocourse seroresponse seroresponses +sr strat stratifications tbl +tibble unstratified wishdf dayssincefeveronset diff --git a/man/print.sr_model.Rd b/man/print.sr_model.Rd new file mode 100644 index 00000000..67be9223 --- /dev/null +++ b/man/print.sr_model.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/print.sr_model.R +\name{print.sr_model} +\alias{print.sr_model} +\title{Default print for \code{\link[=run_mod]{run_mod()}} output object of class +\code{sr_model}} +\usage{ +\method{print}{sr_model}(x, ...) +} +\arguments{ +\item{x}{An \code{sr_model} output object from \code{\link[=run_mod]{run_mod()}}.} + +\item{...}{Additional arguments affecting the summary produced. +\code{\link[=run_mod]{run_mod()}} function.} +} +\value{ +A data summary that +contains the mean posterior distribution for antibody kinetic curve +parameters by \code{Iso_type} and \code{Stratification} (if specified). +} +\description{ +A default print method for class \code{sr_model} that includes the median +posterior distribution for antibody kinetic curve parameters by \code{Iso_type} +and \code{Stratification} (if specified). +} +\examples{ +print(nepal_sees_jags_output) +} diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml index f3d072cd..2dad076c 100644 --- a/pkgdown/_pkgdown.yml +++ b/pkgdown/_pkgdown.yml @@ -42,6 +42,7 @@ reference: - title: Summarize seroresponse model estimates contents: - post_summ + - print.sr_model - title: Example data sets contents: - serodynamics_example diff --git a/tests/testthat/_snaps/print.sr_model.md b/tests/testthat/_snaps/print.sr_model.md new file mode 100644 index 00000000..634ff26c --- /dev/null +++ b/tests/testthat/_snaps/print.sr_model.md @@ -0,0 +1,13 @@ +# results are consistent with printed output for sr_model class + + Code + nepal_sees_jags_output + Output + An sr_model with the following median values: + + Stratification Iso_type alpha shape t1 y0 y1 + 1 typhi HlyE_IgA 0.001788800 1.538820 6.235540 2.405515 342.565 + 2 paratyphi HlyE_IgA 0.001272495 1.614535 3.700500 2.406050 153.787 + 3 typhi HlyE_IgG 0.001140990 1.346445 7.025800 2.073250 252.156 + 4 paratyphi HlyE_IgG 0.001742340 1.321350 4.370495 1.537045 288.325 + diff --git a/tests/testthat/test-print.sr_model.R b/tests/testthat/test-print.sr_model.R new file mode 100644 index 00000000..c1715a0d --- /dev/null +++ b/tests/testthat/test-print.sr_model.R @@ -0,0 +1,6 @@ +test_that( + desc = "results are consistent with printed output for sr_model class", + code = { + testthat::expect_snapshot(nepal_sees_jags_output) + } +)