Skip to content

Commit

Permalink
Merge branch 'main' into error-on-test-warning
Browse files Browse the repository at this point in the history
  • Loading branch information
d-morrison authored Jul 5, 2024
2 parents 8ffa931 + 8e94733 commit e2ce022
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 40 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: test-coverage

permissions: read-all

jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr, any::xml2
needs: coverage

- name: Test coverage
run: |
cov <- covr::package_coverage(
quiet = FALSE,
clean = FALSE,
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
covr::to_cobertura(cov)
shell: Rscript {0}

- uses: codecov/codecov-action@v4
with:
fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }}
file: ./cobertura.xml
plugin: noop
disable_search: true
token: ${{ secrets.CODECOV_TOKEN }}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v4
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
2 changes: 1 addition & 1 deletion R/add_point_to_graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ add_point_to_graph <- function(
point_data =
tibble(
x = fit$estimate %>% exp(),
y = llik(.data$x, ...),
y = log_likelihood(.data$x, ...),
label = "est.incidence"
),
...) {
Expand Down
2 changes: 1 addition & 1 deletion R/build_likelihood_function.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ build_likelihood_function <- function(
for (cur_antigen in antigen_isos)
{
res <- res +
fdev(
f_dev(
lambda = lambda,
csdata = cross_sectional_data[[cur_antigen]],
lnpars = longitudinal_parameter_samples[[cur_antigen]],
Expand Down
4 changes: 2 additions & 2 deletions R/graph.loglik.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ graph.loglik = function(
plot_data <-
tibble(
x = x %>% sort(),
y = llik(
y = log_likelihood(
pop_data = pop_data,
curve_params = curve_params,
noise_params = noise_params,
Expand All @@ -94,7 +94,7 @@ graph.loglik = function(
ggplot2::geom_point(
data = tibble(
x = highlight_points,
y = llik(
y = log_likelihood(
pop_data = pop_data,
curve_params = curve_params,
noise_params = noise_params,
Expand Down
6 changes: 3 additions & 3 deletions R/llik.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ llik <- function(
#' ) # high cutoff (y.high)
#'
#' # Calculate log-likelihood
#' ll_AG <- llik(
#' ll_AG <- log_likelihood(
#' pop_data = xs_data,
#' curve_params = dmcmc,
#' noise_params = cond,
Expand Down Expand Up @@ -120,14 +120,14 @@ log_likelihood <- function(
}

nllSingle <-
fdev(
f_dev(
lambda = lambda,
csdata = cur_data,
lnpars = cur_curve_params,
cond = cur_noise_params
)

# if (!is.na(nllSingle)) # not meaningful for vectorized fdev()
# if (!is.na(nllSingle)) # not meaningful for vectorized f_dev()
{
nllTotal <- nllTotal + nllSingle # DEM note: summing log likelihoods represents an independence assumption for multiple Antibodies, given time since seroconversion
}
Expand Down
6 changes: 3 additions & 3 deletions R/nll.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#' Calculate negative log-likelihood
#' @description
#' Same as [llik()], except negated and requiring lambda on log scale (used in combination with `nlm()`, to ensure that the optimization search doesn't stray into negative values of `lambda`).
#' Same as [log_likelihood()], except negated and requiring lambda on log scale (used in combination with `nlm()`, to ensure that the optimization search doesn't stray into negative values of `lambda`).
#' @param log.lambda natural logarithm of incidence rate
#' @inheritDotParams llik -lambda
#' @inheritDotParams log_likelihood -lambda

#' @return the negative log-likelihood of the data with the current parameter values
#' @keywords internal
.nll <- function(log.lambda, ...) {
-llik(lambda = exp(log.lambda), ...)
-log_likelihood(lambda = exp(log.lambda), ...)
}
2 changes: 1 addition & 1 deletion R/sim.cs.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ sim.cs <- function(
filter(.data$antigen_iso %in% antigen_isos) %>%
droplevels() %>%
prep_curve_params_for_array() %>%
df.to.array(dim_var_names = c("antigen_iso", "parameter"))
df_to_array(dim_var_names = c("antigen_iso", "parameter"))

stopifnot(length(lambda) == 1)

Expand Down
14 changes: 14 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
coverage:
status:
project: #add everything under here, more options at https://docs.codecov.com/docs/commit-status
default:
# basic
target: auto #default
threshold: 1%
base: auto
informational: true
patch:
default:
target: auto
threshold: 1%
informational: true
2 changes: 1 addition & 1 deletion data-raw/typhoid_results.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ log.lmax <- log(10 * lambda)
objfunc <- function(llam) {
return(res <- fdev(llam, p.hlye.IgG, c.hlye.IgG, cond.hlye.IgG))
return(res <- f_dev(llam, p.hlye.IgG, c.hlye.IgG, cond.hlye.IgG))
}
Expand Down
26 changes: 23 additions & 3 deletions man/dot-nll.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/log_likelihood.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 8 additions & 24 deletions man/plot_curve_params_one_ab.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e2ce022

Please sign in to comment.