-
Notifications
You must be signed in to change notification settings - Fork 3
Decay curve 2 #392
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?
Decay curve 2 #392
Conversation
|
@copilot rebase on main; resolve merge conflicts |
|
@d-morrison I've opened a new pull request, #486, to work on those changes. Once the pull request is ready, I'll request review from you. |
Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
Merge main branch and fix workflow failures
|
@copilot fix failing workflows (lint changed files, add new content to pkgdown config, add entries in changelog, etc) |
|
@d-morrison I've opened a new pull request, #489, 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
This pull request adds new antibody and pathogen decay curve modeling functionality to the serocalculator package, including mathematical models for infection dynamics and an interactive Shiny application for visualization.
Changes:
- New decay curve functions:
antibody_decay_curve(),pathogen_decay_curve(),t1f(),y1f(), andplot_decay_curve() - Interactive Shiny app (
curve_app()) with UI and server components for exploring antigen-antibody kinetics - Updated error handling in existing autoplot functions to use
cli::cli_abort()instead ofstop() - New package dependencies:
shinyandconfigfor app functionality - Presentation formatting improvements to methodology vignette
Reviewed changes
Copilot reviewed 28 out of 30 changed files in this pull request and generated 24 comments.
Show a summary per file
| File | Description |
|---|---|
| R/antibody_decay_function.R | New function to calculate antibody concentration over time using a two-phase decay model |
| R/antigen_decay_curve.R | New function to calculate pathogen concentration decay |
| R/t1.R | Helper function to calculate time to end of active infection |
| R/y1.R | Helper function to calculate peak antibody concentration |
| R/plot_decay_curve.R | Plotting utility for decay functions |
| R/curve_app.R | Shiny app launcher for interactive kinetics model exploration |
| R/curve_app_ui.R | Shiny UI definition with parameter sliders |
| R/curve_app_server.R | Shiny server logic for reactive plotting |
| R/app_config.R | Golem framework configuration helpers |
| R/_disable_autoload.R | Shiny autoload configuration |
| R/serocalculator-package.R | Added new package imports for ggplot2 and shiny functions |
| R/autoplot.seroincidence.R | Updated to use cli::cli_abort() for error messages |
| R/autoplot.seroincidence.by.R | Updated to use cli::cli_abort() for error messages |
| DESCRIPTION | Added shiny and config dependencies |
| NAMESPACE | Auto-generated exports for new functions |
| inst/golem-config.yml | Golem app configuration |
| inst/examples/ab-decay-model.Rmd | Standalone Shiny document for antibody decay model |
| app.R | Deployment script for Shiny app |
| .Rbuildignore | Excludes app.R and rsconnect from package build |
| .rscignore | Excludes vignettes from RStudio Connect deployment |
| vignettes/methodology.qmd | Presentation formatting with incremental reveals |
| vignettes/.gitignore | Ignores rsconnect deployment files |
| README.md | Minor whitespace formatting |
| man/*.Rd | Auto-generated documentation for new functions |
| # plotly::plotlyOutput("plot2")), | ||
| shiny::plotOutput(height = "300px", "plot2"), | ||
| shiny::sliderInput( | ||
| inputId = "ymax2", | ||
| label = "log10(ymax)", | ||
| min = 0, | ||
| max = 5, | ||
| step = .1, | ||
| value = 1), | ||
| # shiny::column( | ||
| # width = 6, | ||
| h2("antibodies"), | ||
| # plotly::plotlyOutput("plot1")) |
Copilot
AI
Jan 21, 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.
Commented-out code should be removed. These plotly alternatives and column layout code should either be implemented as an option or removed entirely.
| @@ -0,0 +1,58 @@ | |||
| #' Graph antibody decay function with natural parameters | |||
Copilot
AI
Jan 21, 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 title says "Graph antibody decay function" but the function is named antibody_decay_curve. The title should match the function's actual purpose. Consider changing the title to "Calculate antibody concentration over time" or "Antibody decay curve" to better reflect what the function does (it returns numeric values, not a graph).
| #' Graph antibody decay function with natural parameters | |
| #' Antibody decay curve with natural parameters |
| antibody_decay_curve = function( | ||
| t, | ||
| y0 = 0.74916052, # taken from simpar run from vignette | ||
| b0 = 1, | ||
| mu_b = 0.18432798, | ||
| mu_y = 0.36853621, | ||
| gamma = 0.0013040664, | ||
| alpha = 0.00002192627, | ||
| rho = 2 | ||
| # rho = 2 # exponential decay? | ||
| ) |
Copilot
AI
Jan 21, 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 function lacks input validation. Consider adding checks for:
- Negative values for parameters that should be positive (y0, b0, mu_b, mu_y, gamma, alpha)
- Division by zero when mu_y equals mu_b
- Invalid values for rho (should typically be >= 1)
Input validation would make the function more robust and provide clearer error messages to users.
| ggplot2::theme_bw() + | ||
| # ggplot2::labs(col = "") + | ||
| # ggplot2::theme(legend.position = "bottom") + | ||
| ggplot2::xlim(0, 100) + |
Copilot
AI
Jan 21, 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 xlim is hardcoded to (0, 100) despite having an xmax parameter. The xmax parameter should be used here instead of the hardcoded value 100 to make the function work as documented.
| ggplot2::xlim(0, 100) + | |
| ggplot2::xlim(0, xmax) + |
|
|
||
|
|
Copilot
AI
Jan 21, 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.
There are empty lines at the end of the function. According to tidyverse style guide and best practices, remove trailing blank lines within functions.
| min = -2, | ||
| max = 2, | ||
| step = .1, | ||
| val = 0) |> column(width = 4), |
Copilot
AI
Jan 21, 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.
Inconsistent spacing around equals sign in sliderInput. Most parameters use consistent spacing, but here there are extra spaces before the equals sign in val = 0 and similar lines. Consider standardizing the spacing throughout the file.
| gamma = 0.0013040664, | ||
| alpha = 0.00002192627, | ||
| rho = 2 | ||
| # rho = 2 # exponential decay? |
Copilot
AI
Jan 21, 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.
There's a commented-out line that should be removed. Commented code should not be committed to the codebase. If this is a placeholder for future implementation, consider removing it or using a TODO comment to explain the intent.
| # rho = 2 # exponential decay? |
|
|
||
| plot1 = | ||
| shiny::eventReactive( | ||
| eventExpr = derived_params() | input$ymax1 | input$alpha | input$rho, |
Copilot
AI
Jan 21, 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 eventReactive expression uses the bitwise OR operator | instead of curly braces to combine multiple reactive dependencies. While this may work, the standard Shiny pattern for expressing multiple dependencies is to use curly braces with line breaks or to include them in a list. Consider using eventExpr = {derived_params(); input$ymax1; input$alpha; input$rho} for clarity.
|
|
||
| plot2 = | ||
| shiny::eventReactive( | ||
| eventExpr = derived_params() | input$ymax2, |
Copilot
AI
Jan 21, 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 eventReactive expression uses the bitwise OR operator | instead of curly braces to combine multiple reactive dependencies. While this may work, the standard Shiny pattern for expressing multiple dependencies is to use curly braces with line breaks or to include them in a list. Consider using eventExpr = {derived_params(); input$ymax2} for clarity.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This pull request introduces a new interactive Shiny application for visualizing antigen-antibody kinetics models, along with several supporting functions and package infrastructure updates. It also adds new plotting and mathematical functions for decay curves, exposes additional functions to users, and improves error messaging. The changes enhance the package's interactivity, usability, and extensibility for modeling and visualization.
Major feature: Interactive Shiny app for kinetics modeling
curve_app) for interactively exploring antigen-antibody kinetics, with UI (curve_app_ui), server logic (curve_app_server), and a new launch script (app.R). The app allows users to adjust model parameters via sliders and view real-time plots and derived values. [1] [2] [3] [4]New modeling and plotting utilities
antibody_decay_curveandpathogen_decay_curvefunctions for simulating and plotting antibody and pathogen decay over time. [1] [2]plot_decay_curvefor easy plotting of decay functions using ggplot2.t1f(time to end of active infection) andy1f(peak antibody concentration). [1] [2]Package infrastructure and configuration
.Rbuildignoreand added.rscignoreto exclude app and deployment files from builds; incremented package version to 1.4.0.9004. [1] [2] [3] [4]app_config.Rfor app-specific configuration and file access helpers.Error handling improvements
autoplot.seroincidenceandautoplot.seroincidence.byto usecli::cli_abortfor clearer and more informative errors. [1] [2]Miscellaneous
_disable_autoload.R).These changes significantly expand the package's capabilities for modeling, visualization, and interactive exploration of serological data.