Skip to content

Commit

Permalink
Merge branch 'main' into auto-document
Browse files Browse the repository at this point in the history
  • Loading branch information
d-morrison authored Jul 5, 2024
2 parents 8289b85 + 8e94733 commit 5f7706a
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 40 deletions.
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
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 5f7706a

Please sign in to comment.