-
Notifications
You must be signed in to change notification settings - Fork 0
Monitor population parameters #141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
❌ 5 Tests Failed:
View the top 3 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
|
📖 https://ucd-serg.github.io/serodynamics/preview/pr141 |
|
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. |
|
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. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this 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>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this 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.
|
@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. |
|
@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. |
- 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.
There was a problem hiding this 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.
| 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"))) | ||
| }) |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
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().
| #' - `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. |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@copilot open a new pull request to apply changes based on the comments in this thread |
|
@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. |
There was a problem hiding this 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.
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.