Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
149 commits
Select commit Hold shift + click to select a range
1194641
Updating run_mod to monitor pop_params
sschildhauer Dec 9, 2025
216de96
Updating News
sschildhauer Dec 9, 2025
3b44be0
Updating run_mod for pop_params
sschildhauer Dec 9, 2025
d167acf
Increment version number to 0.0.0.9044
sschildhauer Dec 9, 2025
806389c
Updating run_mod tests to include population parameters
sschildhauer Dec 9, 2025
12fd909
Adding visisble binding
sschildhauer Dec 9, 2025
9e5b61f
Updating lint for run_mod
sschildhauer Dec 9, 2025
c1956ce
Comitting unpack_jags for unpacking an MCMC object with all of the di…
sschildhauer Dec 10, 2025
c1ccc63
jags_unpack documentation
sschildhauer Dec 10, 2025
23cb959
Updating run_mod and documentation to include prec.logy
sschildhauer Dec 10, 2025
ab0876b
Adding unpack_jags to yaml
sschildhauer Dec 10, 2025
9c6255d
documentation and lint
sschildhauer Dec 10, 2025
e819741
Merge branch 'main' into mon_popparams
d-morrison Dec 16, 2025
808eb60
Merge branch 'main' into mon_popparams
d-morrison Dec 16, 2025
6f7b224
Increment version number to 0.0.0.9045
sschildhauer Dec 18, 2025
1ea38a0
Updating tests for monitor popupation parameters
sschildhauer Dec 18, 2025
920ae66
Merge branch 'mon_popparams' of https://github.com/UCD-SERG/serodynam…
sschildhauer Dec 18, 2025
b78a454
Taking unpack_jags out of pkgdown
sschildhauer Dec 20, 2025
2d5a841
Updating news
sschildhauer Dec 20, 2025
6b63587
Updating the documentation.
sschildhauer Dec 20, 2025
2edf8ef
Adding pak_prefer_binary to the env. of CMD_Check
sschildhauer Dec 22, 2025
a9fea4c
Changing documentation for unpack_kags
sschildhauer Dec 29, 2025
4691b50
Siting dplyr for filter arguments
sschildhauer Dec 29, 2025
80072bc
Renaming variable as recommended by copilot
sschildhauer Dec 29, 2025
29f2431
Taking prec.logy out of final output
sschildhauer Dec 29, 2025
b79ed5f
Changing label of population parameter attribute
sschildhauer Dec 29, 2025
b510d60
Fixing renaming
sschildhauer Dec 29, 2025
25eb682
Cleaning documentation and renaming population parameters to be more …
sschildhauer Dec 29, 2025
0b1d83a
Renaming to Population_Parameter
sschildhauer Dec 29, 2025
f3f19ec
Updating lint
sschildhauer Dec 30, 2025
d6186c8
Updating snaps with change in attribute name
sschildhauer Dec 30, 2025
7978f45
Updating more snaps
sschildhauer Dec 30, 2025
d63030c
Calling dplyr:: for filter
sschildhauer Jan 6, 2026
af36115
Omitting , after param = NA
sschildhauer Jan 6, 2026
554866f
Taking quotes away from structure function calls
sschildhauer Jan 6, 2026
7a7b66b
Update R/Run_Mod.R
sschildhauer Jan 6, 2026
0652a2c
Update man/run_mod.Rd
sschildhauer Jan 6, 2026
be6eb67
Update R/Run_Mod.R
sschildhauer Jan 6, 2026
167e335
Update R/Run_Mod.R
sschildhauer Jan 6, 2026
5dc667c
Update R/Run_Mod.R
sschildhauer Jan 6, 2026
492e274
Update R/Run_Mod.R
sschildhauer Jan 6, 2026
1b4214c
Merging with main
sschildhauer Jan 6, 2026
047e8bc
Increment version number to 0.0.0.9047
sschildhauer Jan 6, 2026
a19acf9
Adding space after hashtag copilot
sschildhauer Jan 6, 2026
f318682
Calling dplyr for mutate copilot
sschildhauer Jan 6, 2026
aba2dd4
dplyr before mutate copilot
sschildhauer Jan 6, 2026
9ce51ac
changing jags_out shell to a tibble
sschildhauer Jan 6, 2026
4476ace
Taking out the piece where we have to exclude NAs
sschildhauer Jan 6, 2026
9fd81e8
Changing jags_unpack to jags_packed for clatify
sschildhauer Jan 6, 2026
02ce138
renaming jags_unpacked_bind to jags_unpacked for clarity
sschildhauer Jan 6, 2026
256e8fa
No need to reclassify as tibble as shell is now tibble
sschildhauer Jan 6, 2026
9ba9c86
Changing order of jags_out shell
sschildhauer Jan 6, 2026
cf8e861
taking out PAK_PREFER_BINARY: "false"
sschildhauer Jan 6, 2026
5322f08
Creating a seperate R file for param_recode
sschildhauer Jan 6, 2026
4aafc38
Taking out param_recode as it is now in its own function
sschildhauer Jan 6, 2026
40a2e53
Updating documentation
sschildhauer Jan 6, 2026
41d541d
Updating run_mod snaps
sschildhauer Jan 6, 2026
d37106f
Creating prep_popparams function
sschildhauer Jan 7, 2026
ebf52f2
Finalizing population parameter functions
sschildhauer Jan 7, 2026
ad73d41
Implementing population parameter functions into run_mod
sschildhauer Jan 7, 2026
750c490
Creating documentation for new population parameter functions
sschildhauer Jan 7, 2026
4b0a542
Updating popparam function call
sschildhauer Jan 7, 2026
63a89e5
Updating run_mod lint
sschildhauer Jan 7, 2026
a5b3aac
Fixing lint in new pop param functions
sschildhauer Jan 7, 2026
e18802b
Redoing snaps
sschildhauer Jan 7, 2026
26d3f67
Updating run_mod test snaps
sschildhauer Jan 7, 2026
f2a6b12
Fixing lint in param_recode
sschildhauer Jan 7, 2026
8093b58
Referencing tibble package
sschildhauer Jan 7, 2026
c343ab5
Merge branch 'main' into mon_popparams
d-morrison Jan 9, 2026
84efc38
Increment version number to 0.0.0.9048
sschildhauer Jan 12, 2026
bf3e7f4
Update R/unpack_jags.R
sschildhauer Jan 19, 2026
35503de
Update R/prep_popparams.R
sschildhauer Jan 19, 2026
9986651
Update R/unpack_jags.R
sschildhauer Jan 19, 2026
080f384
Update R/param_recode.R
sschildhauer Jan 19, 2026
ccb8b37
Update R/Run_Mod.R
sschildhauer Jan 19, 2026
7102fda
Update man/prep_popparams.Rd
sschildhauer Jan 19, 2026
98a0aeb
Update R/Run_Mod.R
sschildhauer Jan 19, 2026
20d31c6
Update R/prep_popparams.R
sschildhauer Jan 19, 2026
a845269
Comitting changes recommended from copilot
sschildhauer Jan 24, 2026
0ec3ca6
comitting copilot changes for run_mod
sschildhauer Jan 24, 2026
12158b6
debugging jags_unpack
sschildhauer Jan 24, 2026
4f55f09
Fixing unpack_jags lint
sschildhauer Jan 24, 2026
82a397f
Updating run_mod snapshots
sschildhauer Jan 24, 2026
08aa4ec
Update R/param_recode.R
sschildhauer Jan 24, 2026
3f1cf90
Update R/unpack_jags.R
sschildhauer Jan 24, 2026
5568f37
Update R/Run_Mod.R
sschildhauer Jan 24, 2026
5f62438
Update R/Run_Mod.R
sschildhauer Jan 24, 2026
92e54f0
Update man/run_mod.Rd
sschildhauer Jan 24, 2026
3ea9aca
Changing final data frame to tibble
sschildhauer Jan 24, 2026
516c3e7
Fixing param recode
sschildhauer Jan 24, 2026
05bf272
Initial plan
Copilot Jan 24, 2026
04ed39d
Fix unpack_jags and implement review suggestions
Copilot Jan 24, 2026
d8fa544
Add comprehensive unit tests for internal population parameter functions
Copilot Jan 24, 2026
5974909
Fix deprecated tidyselect syntax in prep_popparams
Copilot Jan 24, 2026
c3ea272
Add 'precisions' to spelling wordlist
Copilot Jan 24, 2026
132c8d9
Remove defensive programming code per maintainer feedback
Copilot Jan 28, 2026
42cf453
Merge pull request #183 from ucdavis/copilot/sub-pr-141-again
sschildhauer Jan 28, 2026
bd6981a
Update R/Run_Mod.R
sschildhauer Jan 28, 2026
55228c8
Initial plan
Copilot Jan 28, 2026
6c9ea64
Merge pull request #185 from ucdavis/copilot/sub-pr-141-again
sschildhauer Mar 4, 2026
bb19344
Update R/unpack_jags.R
sschildhauer Mar 9, 2026
834602b
Updating run_mod tests
sschildhauer Mar 9, 2026
f195188
Updating tests
sschildhauer Mar 9, 2026
b119c6a
Update R/unpack_jags.R
sschildhauer Mar 10, 2026
59c08b9
Accepting new snaps after changing prec logy
sschildhauer Mar 10, 2026
d0b42fb
Updating documentation
sschildhauer Mar 10, 2026
8fece48
Update R/unpack_jags.R
sschildhauer Mar 10, 2026
d1ed607
Updating documentation
sschildhauer Mar 10, 2026
f9bea33
Taking parentheses away from run_mod in documentation because roxygen…
sschildhauer Mar 10, 2026
cb57cc9
autoplot
sschildhauer Mar 10, 2026
aff25bc
Update NAMESPACE
sschildhauer Mar 10, 2026
49e42c5
Comitting namespace
sschildhauer Mar 10, 2026
0248a4e
Initial plan
Copilot Mar 10, 2026
9d3efc6
Fix documentation: replace dplyr::tbl_df (defunct) with tibble::tbl_d…
Copilot Mar 10, 2026
361e681
Merge pull request #189 from ucdavis/copilot/sub-pr-141-another-one
sschildhauer Mar 10, 2026
f27abb7
Fixing lint
sschildhauer Mar 11, 2026
e906a8d
Updating param_recode with recode_values instead of case_when
sschildhauer Mar 11, 2026
560da05
Changing doc for expect snapshot dat
sschildhauer Mar 11, 2026
72082ff
Changing param_recode function to dplyr::recode
sschildhauer Mar 11, 2026
431975c
taking away RDataTmp
sschildhauer Mar 29, 2026
46b991d
Updating run_mod test snaps
sschildhauer Mar 30, 2026
79956b9
Changes before error encountered
Copilot Mar 31, 2026
5048e36
Comitting changes to expect_snapshot
sschildhauer Mar 31, 2026
860a894
Updating tests for run_mod
sschildhauer Mar 31, 2026
640c5c2
Updating expectsnapshot data!
sschildhauer Mar 31, 2026
9b67516
Make population parameters optional
sschildhauer Apr 1, 2026
c6268c7
Fixing population param call
sschildhauer Apr 1, 2026
1179b9d
Updating run_mod tests with optional pop params
sschildhauer Apr 1, 2026
548483c
Updating run_mod documentation
sschildhauer Apr 1, 2026
3dadddc
Fixing lint
sschildhauer Apr 1, 2026
d761107
Changing test
sschildhauer Apr 2, 2026
858b47c
Updating tests
sschildhauer Apr 2, 2026
5e25983
Updating and streamlining run_mod snaps to accomodate population para…
sschildhauer Apr 2, 2026
4163a8c
Updating snaps again
sschildhauer Apr 2, 2026
64e068e
Update R/Run_Mod.R
sschildhauer Apr 3, 2026
6038fb7
Update R/Run_Mod.R
sschildhauer Apr 3, 2026
2b03cbe
Update R/as_case_data.R
sschildhauer Apr 3, 2026
14d9eac
Update R/Run_Mod.R
sschildhauer Apr 3, 2026
232855d
Making default option FALSE for pop_params
sschildhauer Apr 3, 2026
c14bba8
fix: switch popparam test to snapshot_data with darwin_variant, add L…
Copilot Apr 3, 2026
9c611b9
Updating tests to take a snapshot based on copilots recommendation
sschildhauer Apr 3, 2026
c7f6779
Integrating copilot edited files
sschildhauer Apr 3, 2026
3be11bd
Updating tests for run_mod
sschildhauer Apr 3, 2026
936ff74
Updating lint for tests
sschildhauer Apr 3, 2026
d282ba5
Adding a snap for fitted because it was declared
sschildhauer Apr 3, 2026
34ebde3
Fixing run_mod snaps
sschildhauer Apr 4, 2026
9b93578
Error in commas for snaps. Running again
sschildhauer Apr 4, 2026
36891b9
Redoing snaps
sschildhauer Apr 4, 2026
43129e0
fix: use current_atts$class in as_case_data, add attr ordering test, …
Copilot Apr 4, 2026
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.9047
Version: 0.0.0.9048
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 @@ -15,6 +15,7 @@

## New features

* Including optional population parameters as attributes in run_mod output. (#141)
* Made "newperson" optional in `prep_data()` (#73)
* 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)
Expand Down
169 changes: 116 additions & 53 deletions R/Run_Mod.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
#' should be included as an element of the [list] object returned by `run_mod()`
#' (see `Value` section below for details).
#' Note: These objects can be large.
#' @returns An `sr_model` class object: a subclass of [dplyr::tbl_df] that
#' @param with_pop_params A [logical] value specifying whether population
#' level parameters should be included as an attribute entitled
#' `population_params`. Excluded as default.
#' Note: These objects can be large.
#' @returns An `sr_model` class object: a subclass of [tibble::tbl_df] that
#' contains MCMC samples from the joint posterior distribution of the model
#' parameters, conditional on the provided input `data`,
#' including the following:
Expand All @@ -49,6 +53,17 @@
#' - `nIterations`: Number of iteration specified.
#' - `nBurnin`: Number of burn ins.
#' - `nThin`: Thinning number (niter/nmc).
#' - `population_params`: Optionally included modeled population parameters
#' indexed by
#' `Iteration`,
#' `Chain`, `Parameter`, `Iso_type`, and `Stratification`. Excluded as
#' default. Includes the following modeled population parameters:
#' - `mu.par` = The population means of the host-specific model parameters
#' (on logarithmic scales).
#' - `prec.par` = The population precision matrix of the hyperparameters
#' (with diagonal elements equal to inverse variances).
#' - `prec.logy` = A vector of population precisions (inverse variances),
#' one per antigen/isotype combination.
#' - `priors`: A [list] that summarizes the input priors, including:
#' - `mu_hyp_param`
#' - `prec_hyp_param`
Expand All @@ -71,6 +86,7 @@ run_mod <- function(data,
niter = 100,
strat = NA,
with_post = FALSE,
with_pop_params = FALSE,
...) {
## Conditionally creating a stratification list to loop through
if (is.na(strat)) {
Expand All @@ -80,15 +96,14 @@ run_mod <- function(data,
}

## Creating a shell to output results
jags_out <- data.frame(
"Iteration" = NA,
"Chain" = NA,
"Parameter" = NA,
"value" = NA,
"Parameter_sub" = NA,
"Subject" = NA,
"Iso_type" = NA,
"Stratification" = NA
jags_out <- tibble::tibble(
"Iteration" = integer(),
"Chain" = integer(),
"value" = numeric(),
"Subject" = character(),
"Parameter" = character(),
"Iso_type" = character(),
"Stratification" = character()
)

## Creating output list for jags.post
Expand Down Expand Up @@ -118,6 +133,11 @@ run_mod <- function(data,
nthin <- round(niter / nmc) # thinning needed to produce nmc from niter

tomonitor <- c("y0", "y1", "t1", "alpha", "shape")
# Conditional statement for including population parameters
if (with_pop_params) {
tomonitor <- c(tomonitor, "mu.par", "prec.par",
"prec.logy")
}

jags_post <- runjags::run.jags(
model = file_mod,
Expand All @@ -138,61 +158,106 @@ run_mod <- function(data,
jags_post_final[[i]] <- jags_post

# Unpacking and cleaning MCMC output.
jags_unpack <- ggmcmc::ggs(jags_post[["mcmc"]])
jags_packed <- ggmcmc::ggs(jags_post[["mcmc"]])

# Adding attributes
mod_atts <- attributes(jags_unpack)
# Only keeping necessary attributes
mod_atts <- mod_atts[4:8]

mod_atts <- attributes(jags_packed)
# Select necessary attributes by name for robustness across platforms
mod_atts <- mod_atts[c("nChains", "nParameters", "nIterations",
"nBurnin", "nThin", "description")]

# extracting antigen-iso combinations to correctly number
# then by the order they are estimated by the program.
# them by the order they are estimated by the program.
iso_dat <- data.frame(attributes(longdata)$antigens)
iso_dat <- iso_dat |> dplyr::mutate(Subnum = as.numeric(row.names(iso_dat)))
# Working with jags unpacked ggs outputs to clarify parameter and subject
jags_unpack <- jags_unpack |>
dplyr::mutate(
Subnum = sub(".*,", "", .data$Parameter),
Parameter_sub = sub("\\[.*", "", .data$Parameter),
Subject = sub("\\,.*", "", .data$Parameter)
) |>
dplyr::mutate(
Subnum = as.numeric(sub("\\].*", "", .data$Subnum)),
Subject = sub(".*\\[", "", .data$Subject)
)
# Merging isodat in to ensure we are classifying antigen_iso
jags_unpack <- dplyr::left_join(jags_unpack, iso_dat, by = "Subnum")
iso_dat <- iso_dat |> dplyr::mutate(Subnum = row.names(iso_dat))

# Unpacking the mcmc object
jags_unpacked <- unpack_jags(jags_packed)

# Merging isodat in to ensure we are classifying antigen_iso.
jags_unpacked <- dplyr::left_join(jags_unpacked, iso_dat,
by = "Subnum")

# Adding in ID name
ids <- data.frame(attr(longdata, "ids")) |>
mutate(Subject = as.character(dplyr::row_number()))
jags_unpack <- dplyr::left_join(jags_unpack, ids, by = "Subject")
jags_final <- jags_unpack |>
dplyr::select(!c("Subnum", "Subject")) |>
dplyr::mutate(Subject = as.character(dplyr::row_number()))
jags_final <- dplyr::left_join(jags_unpacked, ids,
by = "Subject") |>
dplyr::rename(c("Iso_type" = "attributes.longdata..antigens",
"Subject" = "attr.longdata...ids.."))
"Subject_mcmc" = "attr.longdata...ids..")) |>
# Subject handling:
# * For individual-level parameters, the left join above finds a row in
# attr(longdata, "ids"), so Subject_mcmc contains the subject ID.
# * For population-level parameters (e.g., mu.par, prec.par, prec.logy),
# there is no matching ID, so Subject_mcmc is NA. In that case we
# intentionally keep the original Subject value from unpack_jags,
# which holds the parameter name and serves as the identifier.
dplyr::mutate(Subject_mcmc = ifelse(is.na(.data$Subject_mcmc),
.data$Subject,
.data$Subject_mcmc)) |>
# At this point, jags_unpacked contains:
# * Parameter: original JAGS parameter names (e.g., "y0[1,2]")
# * Param: cleaned parameter names used elsewhere in the package.
# We drop the original JAGS-style Parameter column and keep the
# cleaned names, then rename Param back to Parameter so that all
# downstream code consistently uses a single "Parameter" column
# containing cleaned parameter names.
# Drop the temporary Subject (now only used as a fallback for population
# parameters) and rename Subject_mcmc back to Subject for downstream use.
dplyr::select(!c("Subnum", "Subject", "Parameter")) |>
dplyr::rename(c("Subject" = "Subject_mcmc",
"Parameter" = "Param"))

# Creating a label for the stratification, if there is one.
# If not, will add in "None".
jags_final$Stratification <- i
## Creating output
jags_out <- data.frame(rbind(jags_out, jags_final))
# Creating output as a data frame with the
# jags output results for each stratification rbinded.
jags_out <- dplyr::bind_rows(jags_out, jags_final)
}
# Ensuring output does not have any NAs
jags_out <- jags_out[complete.cases(jags_out), ]
# Outputting the finalized jags output as a data frame with the
# jags output results for each stratification rbinded.

# Making output a tibble and restructing.
jags_out <- dplyr::as_tibble(jags_out) |>
select(!c("Parameter")) |>
rename("Parameter" = "Parameter_sub")

if (with_pop_params) {
# Preparing population parameters
population_params <- prep_popparams(jags_out)
population_params <- population_params[, c(
"Iteration", "Chain", "Parameter", "Iso_type",
"Stratification", "Population_Parameter", "value"
)]

# Taking out population parameters
jags_out <- ex_popparams(jags_out)
}

# Making output a tibble and restructuring.
jags_out <- jags_out[, c("Iteration", "Chain", "Parameter", "Iso_type",
"Stratification", "Subject", "value")]
Comment on lines 232 to 233
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order of columns in the final output is hardcoded on lines 198-199. If any of these columns are missing from jags_final due to changes in the data structure, this will fail silently or produce an error.

Consider adding a check to verify all expected columns exist before reordering, or use dplyr::select() with any_of() to handle missing columns gracefully.

Copilot uses AI. Check for mistakes.
current_atts <- attributes(jags_out)
current_atts <- c(current_atts, mod_atts)
attributes(jags_out) <- current_atts
current_atts <- attributes(jags_out)
# Explicitly build the attribute list in the correct order to ensure that
# `class` appears immediately after `names` and `row.names`.
# The dplyr operations above can carry ggmcmc attributes (nChains, etc.)
# from jags_packed into jags_out, placing `class` at the end. We use
# mod_atts (named selection from jags_packed) as the authoritative source
# for the ggmcmc-style metadata attributes.
new_atts <- list(
names = current_atts$names,
row.names = current_atts$row.names,
class = union("sr_model", current_atts$class),
nChains = mod_atts$nChains,
nParameters = mod_atts$nParameters,
nIterations = mod_atts$nIterations,
nBurnin = mod_atts$nBurnin,
nThin = mod_atts$nThin,
description = mod_atts$description
)
attributes(jags_out) <- new_atts

# Adding priors
# Adding population parameters optionally and priors in as attributes
if (with_pop_params) {
jags_out <- jags_out |>
structure(population_params = population_params)
}
jags_out <- jags_out |>
structure("priors" = attributes(priorspec)$used_priors)
structure(priors = attributes(priorspec)$used_priors)

# Calculating fitted and residuals
# Renaming columns using attributes from as_case_data
Expand All @@ -206,7 +271,5 @@ run_mod <- function(data,
jags_out <- jags_out |>
structure(jags.post = jags_post_final)
}
jags_out <- jags_out |>
structure(class = union("sr_model", class(jags_out)))
jags_out
}
26 changes: 20 additions & 6 deletions R/as_case_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,24 @@ as_case_data <- function(
visit_num = dplyr::row_number()
) |>
serocalculator::set_id_var(id_var) |>
structure(
class = union("case_data", class(data)),
biomarker_var = biomarker_var,
timeindays = time_in_days,
value_var = value_var
)
(\(x) {
current_atts <- attributes(x)
# Explicitly order attributes so that class comes immediately after
# names and row.names, which is the expected position for tibble
# subclasses. tibble::as_tibble() on a subclass can reorder
# standard attributes, so we rebuild them in the correct order.
# Use current_atts$id_var to preserve any standardization done by
# serocalculator::set_id_var (e.g., renaming the ID column to "id").
new_atts <- list(
names = current_atts$names,
row.names = current_atts$row.names,
class = union("case_data", current_atts$class),
id_var = current_atts$id_var,
biomarker_var = biomarker_var,
timeindays = time_in_days,
value_var = value_var
)
attributes(x) <- new_atts
x
})()
}
13 changes: 13 additions & 0 deletions R/ex_popparams.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#' @title Excluding population parameters
#' @author Sam Schildhauer
#' @description
#' `ex_popparams` excludes estimated population parameters from final output
#' [data.frame].
#' @param x A [data.frame] with a `Subject` variable.
#' @returns A filtered [data.frame] excluding population parameters.
#' @keywords internal
ex_popparams <- function(x) {
x <- x |>
dplyr::filter(!(.data$Subject %in% c("mu.par", "prec.par", "prec.logy")))
return(x)
}
3 changes: 2 additions & 1 deletion R/nepal_sees_jags_output.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#' which is the diagnosis type (typhoid or
#' paratyphoid). Keeping only IDs `"newperson"`, `"sees_npl_1"`, `"sees_npl_2"`.
#'
#' @format An S3 object of class `sr_model`: A [dplyr::tbl_df] that contains the
#' @format An S3 object of class `sr_model`: A [tibble::tbl_df] that contains
#' the
#' posterior predictive distribution of the person-specific parameters for a
#' "new person" with no observed data (`Subject = "newperson"`) and posterior
#' distributions of the person-specific parameters for two arbitrarily-chosen
Expand Down
17 changes: 17 additions & 0 deletions R/param_recode.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#' @title Parameter recode
#' @author Sam Schildhauer
#' @description
#' `param_recode` recodes character numbers as their corresponding parameter.
#' @param x A [vector] of character numbers that represent parameters.
#' @returns A [vector] with recoded values.
#' @keywords internal
param_recode <- function(x) {
dplyr::recode(
x,
"1" = "y0",
"2" = "y1",
"3" = "t1",
"4" = "alpha",
"5" = "shape"
)
}
4 changes: 2 additions & 2 deletions R/plot_predicted_curve.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
#' and shows all individual
#' sampled curves.
#'
#' @param model An `sr_model` object (returned by [run_mod()]) containing
#' @param model An `sr_model` object (returned by [run_mod]) containing
#' samples from the posterior distribution of the model parameters.
#' @param ids The participant IDs to plot; for example, `"sees_npl_128"`.
#' @param antigen_iso The antigen isotype to plot; for example, "HlyE_IgA" or
#' "HlyE_IgG".
#' @param dataset (Optional) A [dplyr::tbl_df] with observed antibody response
#' @param dataset (Optional) A [tibble::tbl_df] with observed antibody response
#' data.
#' Must contain:
#' - `timeindays`
Expand Down
4 changes: 2 additions & 2 deletions R/post_summ.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#' @title Summary Table of Jags Posterior Estimates
#' @author Sam Schildhauer
#' @description
#' `post_summ()` takes a [list] output from [serodynamics::run_mod()]
#' `post_summ()` takes a [list] output from [run_mod]
#' to summary table for parameter, antigen/antibody, and stratification
#' combination.
#' Defaults will produce every combination of antigen/antibody, parameters,
Expand All @@ -14,7 +14,7 @@
#' - t1 = time to peak
#' - r = shape parameter
#' - alpha = decay rate
#' @param data A [list] outputted from [run_mod()].
#' @param data A [list] outputted from [run_mod].
#' @param iso Specify [character] string to produce tables of only a
#' specific antigen/antibody combination, entered with quotes. Default outputs
#' all antigen/antibody combinations.
Expand Down
15 changes: 15 additions & 0 deletions R/prep_popparams.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#' @title Preparing population parameters
#' @author Sam Schildhauer
#' @description
#' `prep_popparams` filters a [data.frame] to only include population
#' parameters and renames the `Subject` variable as `Population_Parameter`.
#' @param x A [data.frame] with a `Subject` variable.
#' @returns A filtered [data.frame] with the `Subject` variable renamed to
#' `Population_Parameter`.
#' @keywords internal
prep_popparams <- function(x) {
x <- x |>
dplyr::filter(.data$Subject %in% c("mu.par", "prec.par", "prec.logy")) |>
dplyr::rename(Population_Parameter = "Subject")
return(x)
}
Loading