Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
0a1cc37
Updating traceplot diagnostic
sschildhauer Jul 18, 2025
b11d662
Updating traceplot documentation
sschildhauer Jul 18, 2025
fd24ed2
Updating Rhat dx with documentation
sschildhauer Jul 18, 2025
0aca561
Updating effective dx with documentation
sschildhauer Jul 18, 2025
1016830
Fixing traceplot snaps and tests
sschildhauer Jul 27, 2025
67f06e7
Updating and adding Rhat tests for new id functionality
sschildhauer Jul 27, 2025
1532ea1
Updating effective tests
sschildhauer Jul 27, 2025
afd8d60
Updating density tests
sschildhauer Jul 27, 2025
6577100
Fixing Lint
sschildhauer Jul 27, 2025
5668638
Updating documentation
sschildhauer Jul 27, 2025
e21f691
Updating news
sschildhauer Jul 27, 2025
eb491f6
Increment version number to 0.0.0.9035
sschildhauer Jul 27, 2025
65e30c8
Merging with main
sschildhauer Jul 28, 2025
36e0efb
Fixing snaps
sschildhauer Jul 28, 2025
82eb137
Increment version number to 0.0.0.9037
sschildhauer Jul 28, 2025
ad83bb2
updating density lint and test
sschildhauer Jul 28, 2025
19d0035
Updating lint in rhat test
sschildhauer Jul 28, 2025
6453c8d
Updating Rhat test snap
sschildhauer Jul 28, 2025
7090d27
Updating test snaps for effective and rhat
sschildhauer Jul 28, 2025
a0fbb74
Merge branch 'main' into individualdx_2
d-morrison Aug 7, 2025
674d580
Merging with main
sschildhauer Aug 8, 2025
0cb37c3
Increment version number to 0.0.0.9038
sschildhauer Aug 8, 2025
bdde2f9
Merging News with main
sschildhauer Aug 8, 2025
be62f9a
Merging with main
sschildhauer Aug 8, 2025
638eef4
Redoing trace snaps
sschildhauer Aug 8, 2025
efd738e
Changing trace snaps
sschildhauer Aug 8, 2025
14b52dc
Updating effective snaps
sschildhauer Aug 8, 2025
15ba2da
Merging with main
sschildhauer Sep 12, 2025
62d8878
Increment version number to 0.0.0.9042
sschildhauer Sep 12, 2025
c00fbe2
Update R/plot_jags_densitydx.R
sschildhauer Sep 27, 2025
24bc5e0
Merging with main
sschildhauer Sep 27, 2025
c4b5bfd
Merge branch 'individualdx_2' of https://github.com/UCD-SERG/serodyna…
sschildhauer Sep 27, 2025
a6bb585
Updating plot_jags_dens to provide clarity on sub vs strat in loop
sschildhauer Sep 27, 2025
d781757
Update R/plot_jags_densitydx.R
sschildhauer Sep 27, 2025
d9e56e6
Update R/plot_jags_densitydx.R
sschildhauer Sep 27, 2025
778ebe9
Update R/plot_jags_effectivedx.R
sschildhauer Sep 27, 2025
adf9967
Update R/plot_jags_effectivedx.R
sschildhauer Sep 27, 2025
827ae7e
Update R/plot_jags_rhatdx.R
sschildhauer Sep 27, 2025
eab46ac
Update R/plot_jags_rhatdx.R
sschildhauer Sep 27, 2025
8eb01ee
Update R/plot_jags_tracedx.R
sschildhauer Sep 27, 2025
452c31d
Adding new functions to add attributes to a data frame. Used repetiti…
sschildhauer Sep 28, 2025
7d943a6
Updating Rhat code based on recommendations
sschildhauer Sep 28, 2025
9711a44
Comitting changes to plot functions
sschildhauer Sep 28, 2025
fda2c24
Updating Rhat test
sschildhauer Sep 28, 2025
2869b37
Updating density and rhat snaps
sschildhauer Sep 28, 2025
14ee835
Updating trace and effective snaps
sschildhauer Sep 28, 2025
d3f0f77
Updating jags atts attributes name
sschildhauer Sep 29, 2025
c62cd33
Increment version number to 0.0.0.9043
sschildhauer Sep 29, 2025
5edb3f2
reverting run_mod test
sschildhauer Sep 29, 2025
3d52370
Documentation for add_jags_atts
sschildhauer Sep 29, 2025
14e86ad
Fixing lint in dx functions
sschildhauer Sep 29, 2025
ebb29fe
Changing plot titles back to paste0
sschildhauer Sep 29, 2025
e2cac6c
updating traceplot snaps
sschildhauer Sep 29, 2025
04a1dca
Fixing stratification issue in Rhat
sschildhauer Sep 29, 2025
769acf4
Updating dx plots to have dynamic stratification
sschildhauer Sep 29, 2025
fa7856d
replacing traceplot snaps
sschildhauer Sep 29, 2025
000632b
Updating traceplot snaps
sschildhauer Sep 29, 2025
7cbdba4
redoing autplot doc
sschildhauer Sep 29, 2025
54d2fa0
updating autoplot documentation
sschildhauer Sep 29, 2025
717e1bd
Updating test snaps
sschildhauer Sep 30, 2025
9841b88
Remaking plot predicted curve snaps
sschildhauer Oct 1, 2025
260dd1f
Remaking plot curve snaps
sschildhauer Oct 1, 2025
7bcf2ad
Fixing small issue with loops in trace
sschildhauer Oct 1, 2025
f807e19
Updating autoplot after ggplot update
sschildhauer Oct 2, 2025
f87a358
Updating trace snap
sschildhauer Oct 3, 2025
321a640
Merged origin/main into individualdx_2
sschildhauer Oct 8, 2025
3da69bd
Increment version number to 0.0.0.9044
sschildhauer Oct 8, 2025
d961139
Updating density snaps
sschildhauer Oct 8, 2025
523ecc4
Updating autoplot snap
sschildhauer Oct 8, 2025
eb7c83a
Updating documentation of add_jags_atts
sschildhauer Oct 9, 2025
d4ab703
Updating title of prior test for run_mod
sschildhauer Oct 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: serodynamics
Title: What the Package Does (One Line, Title Case)
Version: 0.0.0.9043
Version: 0.0.0.9044
Authors@R: c(
person("Peter", "Teunis", , "p.teunis@emory.edu", role = c("aut", "cph"),
comment = "Author of the method and original code."),
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

## New features

* Adding `id` parameter to diagnostic functions (#121)
* Including fitted and residual values as data frame in run_mod output. (#101)
* Added `plot_predicted_curve()` with support for faceting by multiple IDs (#68)
* Replacing old data object with new run_mod output (#102)
Expand Down
12 changes: 12 additions & 0 deletions R/add_jags_atts.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#' @title Adds attributes
#' @description
#' `add_jags_attrs` adds specified attributes to a [data.frame].
#' @param df A [data.frame].
#' @param attrs [attributes] to attach to the [data.frame].
#' @param df A [data.frame] of the original input dataset.
#' @returns A [data.frame] with specified [attributes] attached.
#' @keywords internal
add_jags_attrs <- function(df, attrs) {
attributes(df) <- c(attributes(df), attrs)
df
}
78 changes: 46 additions & 32 deletions R/plot_jags_densitydx.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#' - `y1` = posterior estimate of peak antibody concentration
#' @param strat Specify [character] string to produce plots of specific
#' stratification entered in quotes.
#' @param id Specify [character] id in a [vector] format to produce plots for
#' specific individuals. Default is the `newperson` referring to the predictive
#' distribution.
#' @return A [base::list()] of [ggplot2::ggplot()] objects producing density
#' plots for all the specified input.
#' @export
Expand All @@ -34,45 +37,56 @@
plot_jags_dens <- function(data,
iso = unique(data$Iso_type),
param = unique(data$Parameter),
strat = unique(data$Stratification)) {
strat = unique(data$Stratification),
id = c("newperson")) {

attributes_jags <- data[["attributes"]]

dens_strat_list <- list()
for (i in strat) {
dens_id_list <- list()
for (h in id) {

visualize_jags_sub <- data |>
Comment thread
sschildhauer marked this conversation as resolved.
dplyr::filter(.data$Stratification == i) |>
dplyr::filter(.data$Subject == "newperson")
dplyr::filter(.data$Subject == h)

stratify <- dplyr::intersect(unique(visualize_jags_sub$Stratification),
strat)

dens_strat_list <- list()
for (i in stratify) {

visualize_jags_strat <- visualize_jags_sub |>
dplyr::filter(.data$Stratification == i)

# Creating open list to store ggplots
density_out <- list()
# Looping through the isos
for (j in iso) {
visualize_jags_plot <- visualize_jags_strat |>
dplyr::filter(.data$Iso_type == j)

# Will not loop through parameters, as we may want each to show on the
# same plot by default.
visualize_jags_plot <- visualize_jags_plot |>
dplyr::filter(.data$Parameter %in% param)

# Creating open list to store ggplots
density_out <- list()
# Looping through the isos
for (j in iso) {
visualize_jags_plot <- visualize_jags_sub |>
dplyr::filter(.data$Iso_type == j)
visualize_jags_plot <- visualize_jags_plot |>
dplyr::mutate(Parameter = paste0("iso = ", j, ", parameter = ",
.data$Parameter, ", strat = ",
i),
value = log(.data$value))

# Will not loop through parameters, as we may want each to show on the
# same plot by default.
visualize_jags_plot <- visualize_jags_plot |>
dplyr::filter(.data$Parameter %in% param)
visualize_jags_plot <- add_jags_attrs(visualize_jags_plot,
attributes_jags)

visualize_jags_plot <- visualize_jags_plot |>
# Changing parameter name to reflect the input
dplyr::mutate(Parameter = paste0("iso = ", j, ", parameter = ",
.data$Parameter, ", strat = ",
i),
value = log(.data$value))
# Assigning attributes, which are needed to run ggs_density
attributes(visualize_jags_plot) <- c(attributes(visualize_jags_plot),
attributes_jags)
# Creating density plot
densplot <- ggmcmc::ggs_density(visualize_jags_plot) +
ggplot2::theme_bw() +
ggplot2::labs(x = "log(value)")
density_out[[j]] <- densplot
# Creating density plot
densplot <- ggmcmc::ggs_density(visualize_jags_plot) +
ggplot2::theme_bw() +
ggplot2::labs(x = "log(value)")
density_out[[j]] <- densplot
}
dens_strat_list[[i]] <- density_out
}
dens_strat_list[[i]] <- density_out
dens_id_list[[h]] <- dens_strat_list
}
dens_strat_list
dens_id_list
}
88 changes: 51 additions & 37 deletions R/plot_jags_effectivedx.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#' - `alpha` = posterior estimate of decay rate
#' @param strat Specify [character] string to produce plots of specific
#' stratification entered in quotes.
#' @param id Specify [character] id in a [vector] format to produce plots for
#' specific individuals. Default is the `newperson` referring to the predictive
#' distribution.
#' @return A [list] of [ggplot2::ggplot] objects showing the
#' proportion of effective samples taken/total samples taken for all parameter
#' iso combinations. The estimate with the highest proportion of effective
Expand All @@ -38,51 +41,62 @@
plot_jags_effect <- function(data,
iso = unique(data$Iso_type),
param = unique(data$Parameter),
strat = unique(data$Stratification)) {
strat = unique(data$Stratification),
id = c("newperson")) {

attributes_jags <- data[["attributes"]]

eff_id_list <- list()
for (h in id) {

visualize_jags_sub <- data |>
dplyr::filter(.data$Subject == h)

eff_strat_list <- list()
for (i in strat) {
stratify <- dplyr::intersect(unique(visualize_jags_sub$Stratification),
strat)

visualize_jags_sub <- data |>
dplyr::filter(.data$Stratification == i) |>
dplyr::filter(.data$Subject == "newperson")
eff_strat_list <- list()
for (i in stratify) {

visualize_jags_strat <- visualize_jags_sub |>
dplyr::filter(.data$Stratification == i)

# Creating open list to store ggplots
eff_out <- list()
# Looping through the isos
for (j in iso) {
visualize_jags_plot <- visualize_jags_sub |>
dplyr::filter(.data$Iso_type == j)
# Creating open list to store ggplots
eff_out <- list()
# Looping through the isos
for (j in iso) {
visualize_jags_plot <- visualize_jags_strat |>
dplyr::filter(.data$Iso_type == j)

# Will not loop through parameters, as we may want each to show on the
# same plot by default.
visualize_jags_plot <- visualize_jags_plot |>
dplyr::filter(.data$Parameter %in% param)
# Will not loop through parameters, as we may want each to show on the
# same plot by default.
visualize_jags_plot <- visualize_jags_plot |>
dplyr::filter(.data$Parameter %in% param)

visualize_jags_plot <- visualize_jags_plot |>
# Changing parameter name to reflect the input
dplyr::mutate(Parameter = .data$Parameter)
# Assigning attributes, which are needed to run ggs_density
attributes(visualize_jags_plot) <- c(attributes(visualize_jags_plot),
attributes_jags)
visualize_jags_plot <- visualize_jags_plot |>
# Changing parameter name to reflect the input
dplyr::mutate(Parameter = .data$Parameter)
# Assigning attributes, which are needed to run ggs_density
visualize_jags_plot <- add_jags_attrs(visualize_jags_plot,
attributes_jags)

# Creating density plot
eff <- ggmcmc::ggs_effective(visualize_jags_plot) +
ggplot2::theme_bw() +
ggplot2::labs(title = "Effective sample size",
subtitle = plot_title_fun(i, j),
x = "Proportion of effective samples") +
ggplot2::scale_y_discrete(limits = c("alpha", "shape", "t1", "y1",
"y0"))
eff_out[[j]] <- eff
# Creating density plot
eff <- ggmcmc::ggs_effective(visualize_jags_plot) +
ggplot2::theme_bw() +
ggplot2::labs(title = "Effective sample size",
subtitle = plot_title_fun(i, j),
x = "Proportion of effective samples") +
ggplot2::scale_y_discrete(limits =
unique(visualize_jags_plot$Parameter))
eff_out[[j]] <- eff
}
eff_strat_list[[i]] <- eff_out
}
eff_strat_list[[i]] <- eff_out
#Printing only one plot if only one exists.
if (sum(lengths(eff_strat_list)) == 1) {
eff_strat_list <- eff_strat_list[[1]][[iso]]
}
eff_id_list[[h]] <- eff_strat_list
}
#Printing only one plot if only one exists.
if (sum(lengths(eff_strat_list)) == 1) {
eff_strat_list <- eff_strat_list[[1]][[iso]]
}
eff_strat_list
eff_id_list
}
90 changes: 53 additions & 37 deletions R/plot_jags_rhatdx.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#' - `alpha` = posterior estimate of decay rate
#' @param strat Specify [character] string to produce plots of specific
#' stratification entered in quotes.
#' @param id Specify [character] id in a [vector] format to produce plots for
#' specific individuals. Default is the `newperson` referring to the predictive
#' distribution.
#' @return A [list] of [ggplot2::ggplot] objects producing dotplots with rhat
#' values for all the specified input.
#' @export
Expand All @@ -37,51 +40,64 @@
plot_jags_Rhat <- function(data, # nolint: object_name_linter
iso = unique(data$Iso_type),
param = unique(data$Parameter),
strat = unique(data$Stratification)) {
strat = unique(data$Stratification),
id = c("newperson")) {

attributes_jags <- data[["attributes"]]

rhat_strat_list <- list()
for (i in strat) {
rhat_id_list <- list()
for (h in id) {

visualize_jags_sub <- data |>
dplyr::filter(.data$Stratification == i) |>
dplyr::filter(.data$Subject == "newperson")
dplyr::filter(.data$Subject == h)

stratify <- dplyr::intersect(unique(visualize_jags_sub$Stratification),
strat)

rhat_strat_list <- list()
for (i in stratify) {

visualize_jags_strat <- visualize_jags_sub |>
dplyr::filter(.data$Stratification == i)

# Creating open list to store ggplots
rhat_out <- list()
# Looping through the isos
for (j in iso) {
visualize_jags_plot <- visualize_jags_sub |>
dplyr::filter(.data$Iso_type == j)
# Creating open list to store ggplots
rhat_out <- list()
# Looping through the isos
for (j in iso) {
visualize_jags_plot <- visualize_jags_strat |>
dplyr::filter(.data$Iso_type == j)

# Will not loop through parameters, as we may want each to show on the
# same plot by default.
visualize_jags_plot <- visualize_jags_plot |>
dplyr::filter(.data$Parameter %in% param)
# Will not loop through parameters, as we may want each to show on the
# same plot by default.
visualize_jags_plot <- visualize_jags_plot |>
dplyr::filter(.data$Parameter %in% param)

visualize_jags_plot <- visualize_jags_plot |>
# Changing parameter name to reflect the input
dplyr::mutate(Parameter = .data$Parameter,
value = log(.data$value))
# Assigning attributes, which are needed to run ggs_rhat
attributes(visualize_jags_plot) <- c(attributes(visualize_jags_plot),
attributes_jags)
# Creating rhat dotplots
rhatplot <- ggmcmc::ggs_Rhat(visualize_jags_plot) +
ggplot2::theme_bw() +
ggplot2::labs(title = "Rhat value",
subtitle = plot_title_fun(i, j),
x = "Rhat value") +
ggplot2::scale_y_discrete(limits = c("alpha", "shape", "t1", "y1",
"y0"))
rhat_out[[j]] <- rhatplot
visualize_jags_plot <- visualize_jags_plot |>
# Changing parameter name to reflect the input
dplyr::mutate(Parameter = .data$Parameter,
value = log(.data$value))
# Assigning attributes, which are needed to run ggs_rhat
visualize_jags_plot <- add_jags_attrs(visualize_jags_plot,
attributes_jags)
# Default order of main parameters
param_levels <- c("alpha", "shape", "t1", "y1", "y0")
# Creating rhat dotplots
rhatplot <- ggmcmc::ggs_Rhat(visualize_jags_plot) +
ggplot2::theme_bw() +
ggplot2::labs(title = "Rhat value",
subtitle = plot_title_fun(i, j),
x = "Rhat value") +
ggplot2::scale_y_discrete(limits = intersect(param_levels,
param))
rhat_out[[j]] <- rhatplot
}
rhat_strat_list[[i]] <- rhat_out
}
rhat_strat_list[[i]] <- rhat_out
#Printing only one plot if only one exists.
if (sum(lengths(rhat_strat_list)) == 1) {
rhat_strat_list <- rhat_strat_list[[1]][[iso]]
}
rhat_id_list[[h]] <- rhat_strat_list
}
#Printing only one plot if only one exists.
if (sum(lengths(rhat_strat_list)) == 1) {
rhat_strat_list <- rhat_strat_list[[1]][[iso]]
}
rhat_strat_list
rhat_id_list
}
Loading