Skip to content

Conversation

@sschildhauer
Copy link
Collaborator

Creating a pull request for monitoring population parameters. This PR adds a dataframe of pop_params to the output of run_mod that includes mu.par and prec.par.

@codecov
Copy link

codecov bot commented Dec 9, 2025

❌ 5 Tests Failed:

Tests completed Failed Passed Skipped
29 5 24 0
View the top 3 failed test(s) by shortest run time
run_mod::results_are_consistent_with_unstratified_SEES_data_with_jags.post_included
Stack Traces | 0.022s run time
Error in `tibble(Iteration = NULL, Chain = NULL, value = NULL, Subject = NULL, Parameter = NULL, Iso_type = NULL, Stratification = NULL)`: could not find function "tibble"
Backtrace:
    x
 1. +-base::suppressWarnings(...) at test-run_mod.R:135:5
 2. | \-base::withCallingHandlers(...)
 3. \-serodynamics::run_mod(...)
run_mod::results_are_consistent_with_unstratified_SEES_data_with_modified_priors
Stack Traces | 0.023s run time
Error in `tibble(Iteration = NULL, Chain = NULL, value = NULL, Subject = NULL, Parameter = NULL, Iso_type = NULL, Stratification = NULL)`: could not find function "tibble"
Backtrace:
    x
 1. +-base::suppressWarnings(...) at test-run_mod.R:169:5
 2. | \-base::withCallingHandlers(...)
 3. \-serodynamics::run_mod(...)
run_mod::results_are_consistent_with_unstratified_SEES_data
Stack Traces | 0.035s run time
Error in `tibble(Iteration = NULL, Chain = NULL, value = NULL, Subject = NULL, Parameter = NULL, Iso_type = NULL, Stratification = NULL)`: could not find function "tibble"
Backtrace:
    x
 1. +-base::suppressWarnings(...) at test-run_mod.R:96:5
 2. | \-base::withCallingHandlers(...)
 3. \-serodynamics::run_mod(...)
run_mod::results_are_consistent_with_SEES_data
Stack Traces | 0.053s run time
Error in `tibble(Iteration = NULL, Chain = NULL, value = NULL, Subject = NULL, Parameter = NULL, Iso_type = NULL, Stratification = NULL)`: could not find function "tibble"
Backtrace:
    x
 1. +-base::suppressWarnings(...) at test-run_mod.R:57:5
 2. | \-base::withCallingHandlers(...)
 3. \-serodynamics::run_mod(...)
run_mod::results_are_consistent_with_simulated_data
Stack Traces | 0.286s run time
Error in `tibble(Iteration = NULL, Chain = NULL, value = NULL, Subject = NULL, Parameter = NULL, Iso_type = NULL, Stratification = NULL)`: could not find function "tibble"
Backtrace:
    x
 1. +-base::suppressWarnings(...) at test-run_mod.R:16:5
 2. | \-base::withCallingHandlers(...)
 3. \-serodynamics::run_mod(...)

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2025

📖 https://ucd-serg.github.io/serodynamics/preview/pr141
Preview documentation for this PR (at commit bd6981a)

@sschildhauer
Copy link
Collaborator Author

I am unsure why these final tests aren't passing. @Kwan-Jenny Any thoughts?

@Kwan-Jenny
Copy link
Collaborator

I am unsure why these final tests aren't passing. @Kwan-Jenny Any thoughts?

I am not sure what’s causing these final test failures. It may be helpful to ask @d-morrison for his thoughts.

@sschildhauer
Copy link
Collaborator Author

Hi @d-morrison , I have not seen this review fail message. I am a but confused how this came up as I made very few changes from the last review. It looks like it might have something to do with package dependencies, but unsure. Once this is done I can send up the posterior predictive check for review.

sschildhauer and others added 2 commits January 24, 2026 13:42
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 16 out of 22 changed files in this pull request and generated 1 comment.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings January 24, 2026 21:46
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 16 out of 22 changed files in this pull request and generated 6 comments.

Comments suppressed due to low confidence (1)

tests/testthat/_snaps/run_mod/strat-fitted_residuals.csv:1

  • The snapshot CSV files for fitted_residuals appear to have been completely deleted from the main snapshot directory (tests/testthat/_snaps/run_mod/) but they still exist in the darwin variant directory (tests/testthat/_snaps/darwin/run_mod/). This appears to be unintentional - the diff shows the entire file contents being removed with "-" prefixes for all lines.

The test file (test-run_mod.R) still references these snapshots in lines 40-44, 80-84, and 119-123, using expect_snapshot_data() calls. This will cause test failures because the snapshot files are missing.

Either the snapshots need to be restored to the main directory, or the test code needs to be updated to only use the darwin variant if that's the intended behavior. Given that the PR description doesn't mention intentionally removing these snapshots, this appears to be an accidental deletion.

@sschildhauer
Copy link
Collaborator Author

@copilot please implement your suggestions and troubleshoot areas where there are errors, specifically in the unpack_jags functions which does not seem to be working. Please keep all edits within this pull request.

Copy link
Contributor

Copilot AI commented Jan 24, 2026

@sschildhauer I've opened a new pull request, #183, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 6 commits January 24, 2026 22:33
- Add default case and error handling to param_recode()
- Fix unpack_jags() to handle factor Parameter column from ggmcmc::ggs()
- Improve pattern matching in unpack_jags using startsWith() for precision
- Add column validation before reordering in run_mod()
- Update documentation for prec.logy to clarify it's a vector of precisions
- Accept updated test snapshots with population_params now properly populated

Co-authored-by: sschildhauer <165851188+sschildhauer@users.noreply.github.com>
- Add 33 unit tests for param_recode(), unpack_jags(), prep_popparams(), and ex_popparams()
- Test valid and invalid parameter indices with error handling
- Test factor Parameter column handling from ggmcmc::ggs()
- Test mu.par, prec.par, and prec.logy parameter unpacking
- Test individual-level parameter unpacking
- Test population parameter filtering and exclusion
- Verify prep_popparams and ex_popparams are complementary

Co-authored-by: sschildhauer <165851188+sschildhauer@users.noreply.github.com>
- Replace .data$Subject with "Subject" in dplyr::rename()
- Resolves tidyselect 1.2.0 deprecation warning

Co-authored-by: sschildhauer <165851188+sschildhauer@users.noreply.github.com>
Co-authored-by: sschildhauer <165851188+sschildhauer@users.noreply.github.com>
- Remove error handling from param_recode() for invalid parameter indices
- Remove column validation from run_mod() before reordering
- Remove tests for invalid parameter handling
- Keep only essential functionality since JAGS outputs are always consistent

Co-authored-by: sschildhauer <165851188+sschildhauer@users.noreply.github.com>
Fix unpack_jags() factor handling and add test coverage for population parameters. Copilot made requested changes and will not merge into base branch for mon_popparams.
Copilot AI review requested due to automatic review settings January 28, 2026 03:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 14 out of 15 changed files in this pull request and generated 4 comments.

Comment on lines +1 to +173
test_that("param_recode correctly recodes parameter indices", {
# Test valid parameter indices
expect_equal(serodynamics:::param_recode("1"), "y0")
expect_equal(serodynamics:::param_recode("2"), "y1")
expect_equal(serodynamics:::param_recode("3"), "t1")
expect_equal(serodynamics:::param_recode("4"), "alpha")
expect_equal(serodynamics:::param_recode("5"), "shape")

# Test vector of valid indices
expect_equal(
serodynamics:::param_recode(c("1", "2", "3", "4", "5")),
c("y0", "y1", "t1", "alpha", "shape")
)
})

test_that("unpack_jags handles factor Parameter column", {
# Create a simple ggs-like object with factor Parameter column
test_data <- tibble::tibble(
Iteration = rep(1:5, 3),
Chain = rep(1, 15),
Parameter = factor(
rep(c("mu.par[1,1]", "prec.par[1,1,2]", "y0[1,1]"), each = 5)
),
value = rnorm(15)
)

# Should not error with factor column
result <- serodynamics:::unpack_jags(test_data)

expect_true(is.data.frame(result))
expect_true("Subject" %in% names(result))
expect_true("Param" %in% names(result))
})

test_that("unpack_jags correctly unpacks mu.par parameters", {
test_data <- tibble::tibble(
Iteration = rep(1:3, 2),
Chain = rep(1, 6),
Parameter = rep(c("mu.par[1,1]", "mu.par[1,2]"), each = 3),
value = rnorm(6)
)

result <- serodynamics:::unpack_jags(test_data)

# Check that mu.par rows are present
mu_rows <- result[result$Subject == "mu.par", ]
expect_gt(nrow(mu_rows), 0)

# Check Subject is correctly set
expect_true("mu.par" %in% result$Subject)

# Check Param is correctly decoded
expect_true(all(mu_rows$Param %in% c("y0", "y1", "t1", "alpha", "shape")))
})

test_that("unpack_jags correctly unpacks prec.par parameters", {
test_data <- tibble::tibble(
Iteration = rep(1:3, 2),
Chain = rep(1, 6),
Parameter = rep(c("prec.par[1,1,2]", "prec.par[1,2,3]"), each = 3),
value = rnorm(6)
)

result <- serodynamics:::unpack_jags(test_data)

# Check that prec.par rows are present
prec_rows <- result[result$Subject == "prec.par", ]
expect_gt(nrow(prec_rows), 0)

# Check Subject is correctly set
expect_true("prec.par" %in% result$Subject)

# Check Param contains pairs (e.g., "y0, y1")
expect_true(any(grepl(",", prec_rows$Param)))
})

test_that("unpack_jags correctly unpacks prec.logy parameters", {
test_data <- tibble::tibble(
Iteration = rep(1:3, 2),
Chain = rep(1, 6),
Parameter = rep(c("prec.logy[1]", "prec.logy[2]"), each = 3),
value = rnorm(6)
)

result <- serodynamics:::unpack_jags(test_data)

# Check that prec.logy rows are present
logy_rows <- result[result$Subject == "prec.logy", ]
expect_gt(nrow(logy_rows), 0)

# Check Subject is correctly set
expect_true("prec.logy" %in% result$Subject)
})

test_that("unpack_jags correctly unpacks individual-level parameters", {
test_data <- tibble::tibble(
Iteration = rep(1:3, 2),
Chain = rep(1, 6),
Parameter = rep(c("y0[1,1]", "alpha[2,1]"), each = 3),
value = rnorm(6)
)

result <- serodynamics:::unpack_jags(test_data)

# Check individual-level parameters are unpacked
expect_true("1" %in% result$Subject | "2" %in% result$Subject)
expect_true("y0" %in% result$Param | "alpha" %in% result$Param)
})

test_that("prep_popparams filters to population parameters only", {
test_data <- tibble::tibble(
Iteration = 1:10,
Chain = rep(1, 10),
Parameter = rep(c("y0", "mu.par"), each = 5),
Subject = rep(c("1", "mu.par"), each = 5),
value = rnorm(10)
)

result <- serodynamics:::prep_popparams(test_data)

# Should only have population parameters
expect_true(all(result$Population_Parameter %in%
c("mu.par", "prec.par", "prec.logy")))

# Should rename Subject to Population_Parameter
expect_true("Population_Parameter" %in% names(result))
expect_false("Subject" %in% names(result))

# Should have 5 rows (only mu.par rows)
expect_equal(nrow(result), 5)
})

test_that("ex_popparams excludes population parameters", {
test_data <- tibble::tibble(
Iteration = 1:10,
Chain = rep(1, 10),
Parameter = rep(c("y0", "mu.par"), each = 5),
Subject = rep(c("1", "mu.par"), each = 5),
value = rnorm(10)
)

result <- serodynamics:::ex_popparams(test_data)

# Should not have any population parameters
expect_false(any(result$Subject %in% c("mu.par", "prec.par", "prec.logy")))

# Should have 5 rows (only y0 rows)
expect_equal(nrow(result), 5)

# Should keep original structure
expect_equal(names(result), names(test_data))
})

test_that("prep_popparams and ex_popparams are complementary", {
test_data <- tibble::tibble(
Iteration = rep(1:5, 4),
Chain = rep(1, 20),
Parameter = rep(c("y0", "mu.par", "prec.par", "prec.logy"), each = 5),
Subject = rep(c("1", "mu.par", "prec.par", "prec.logy"), each = 5),
value = rnorm(20)
)

pop_params <- serodynamics:::prep_popparams(test_data)
individual_params <- serodynamics:::ex_popparams(test_data)

# Together they should account for all rows
expect_equal(nrow(pop_params) + nrow(individual_params), nrow(test_data))

# No overlap in subjects
# Note: pop_params has Population_Parameter column, not Subject
expect_false(any(individual_params$Subject %in%
c("mu.par", "prec.par", "prec.logy")))
})
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The tests use rnorm() to generate random data but do not seed the random number generator. According to the coding guidelines and patterns in the codebase (see tests/testthat/test-run_mod.R), tests that involve random number generation should use withr::local_seed() for reproducibility. Add withr::local_seed(123) (or another seed value) at the beginning of each test that uses rnorm().

Copilot uses AI. Check for mistakes.
Comment on lines +52 to +61
#' - `population_params`: Modeled population parameters, indexed by
#' `Iteration`,
#' `Chain`, `Parameter`, `Iso_type`, and `Stratification`. 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.
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The documentation for population_params is incomplete. It lists the columns as "Iteration, Chain, Parameter, Iso_type, and Stratification" but doesn't mention the Population_Parameter column (which identifies which population parameter it is: mu.par, prec.par, or prec.logy) or the value column (which contains the MCMC sample values). These columns should be documented to match the actual data structure.

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings January 28, 2026 04:12
@sschildhauer
Copy link
Collaborator Author

@copilot open a new pull request to apply changes based on the comments in this thread

Copy link
Contributor

Copilot AI commented Jan 28, 2026

@sschildhauer I've opened a new pull request, #185, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 14 out of 15 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants