Skip to content
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

rename scova to biokinetics #10

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ src/stan/**/*.exe
src/stan/**/*.EXE
inst/doc
.idea
*.png
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Generated by roxygen2: do not edit by hand

export(biokinetics)
export(biokinetics_priors)
export(convert_log_scale_inverse)
export(scova)
export(scova_priors)
importFrom(R6,R6Class)
importFrom(data.table,":=")
importFrom(data.table,.BY)
Expand Down
30 changes: 15 additions & 15 deletions R/scova.R → R/biokinetics.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
##' @title SARS-CoV-2 Antibody Kinetics Model
##' @title Biomarker Kinetics Model
##'
##' @description Create an instance of the SARS-CoV-2 antibody model and
##' fit it to a dataset using Gaussian priors and a given hierarchical model structure.
##' @description Create an instance of the biomarker kinetics model and
##' fit it to a dataset.
##' @export
##' @importFrom R6 R6Class
scova <- R6::R6Class(
"scova",
biokinetics <- R6::R6Class(
"biokinetics",
cloneable = FALSE,
private = list(
priors = NULL,
Expand Down Expand Up @@ -152,7 +152,7 @@ scova <- R6::R6Class(
dt_out <- merge(
dt_samples_wide, dt_times, by = "t_id", allow.cartesian = TRUE)

dt_out[, mu := scova_simulate_trajectory(
dt_out[, mu := biokinetics_simulate_trajectory(
t, t0_pop, tp_pop, ts_pop, m1_pop, m2_pop, m3_pop),
by = c("t", "p", "k", ".draw")]

Expand Down Expand Up @@ -223,22 +223,22 @@ scova <- R6::R6Class(
),
public = list(
#' @description Initialise the kinetics model.
#' @return An epikinetics::scova object.
#' @return An epikinetics::biokinetics object.
#' @param data Optional data table of model inputs. One of data or file must be provided. See the data vignette
#' for required columns: \code{vignette("data", package = "epikinetics")}.
#' @param file_path Optional file path to model inputs in CSV format. One of data or file must be provided.
#' @param priors Object of type \link[epikinetics]{scova_priors}. Default scova_priors().
#' @param priors Object of type \link[epikinetics]{biokinetics_priors}. Default biokinetics_priors().
#' @param covariate_formula Formula specifying hierarchical structure of model. Default ~0.
#' @param preds_sd Standard deviation of predictor coefficients. Default 0.25.
#' @param time_type One of 'relative' or 'absolute'. Default 'relative'.
initialize = function(priors = scova_priors(),
initialize = function(priors = biokinetics_priors(),
data = NULL,
file_path = NULL,
covariate_formula = ~0,
preds_sd = 0.25,
time_type = "relative") {
if (!inherits(priors, "scova_priors")) {
stop("'priors' must be of type 'scova_priors'")
if (!inherits(priors, "biokinetics_priors")) {
stop("'priors' must be of type 'biokinetics_priors'")
}
private$priors <- priors
validate_numeric(preds_sd)
Expand Down Expand Up @@ -409,11 +409,11 @@ scova <- R6::R6Class(

logger::log_info("Calculating peak and switch titre values")
dt_peak_switch[, `:=`(
mu_0 = scova_simulate_trajectory(
mu_0 = biokinetics_simulate_trajectory(
0, t0_pop, tp_pop, ts_pop, m1_pop, m2_pop, m3_pop),
mu_p = scova_simulate_trajectory(
mu_p = biokinetics_simulate_trajectory(
tp_pop, t0_pop, tp_pop, ts_pop, m1_pop, m2_pop, m3_pop),
mu_s = scova_simulate_trajectory(
mu_s = biokinetics_simulate_trajectory(
ts_pop, t0_pop, tp_pop, ts_pop, m1_pop, m2_pop, m3_pop)),
by = c("p", "k", "draw")]

Expand Down Expand Up @@ -479,7 +479,7 @@ scova <- R6::R6Class(
# Running the C++ code to simulate trajectories for each parameter sample
# for each individual
logger::log_info("Simulating individual trajectories")
dt_params_ind_traj <- scova_simulate_trajectories(dt_params_ind_trim)
dt_params_ind_traj <- biokinetics_simulate_trajectories(dt_params_ind_trim)

dt_params_ind_traj <- data.table::setDT(convert_log_scale_inverse_cpp(
dt_params_ind_traj, vars_to_transform = "mu"))
Expand Down
14 changes: 7 additions & 7 deletions R/priors.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ gaussian_priors <- function(names, mu_values, sigma_values) {
ret
}

#' @title Construct priors for the SARS-CoV-2 antibody model.
#' @title Construct priors for the biomarker model.
#' @export
#' @description The scova model has 6 parameters: t0, tp, ts, m1, m2, m3 corresponding to critical time points and
#' @description The biokinetics model has 6 parameters: t0, tp, ts, m1, m2, m3 corresponding to critical time points and
#' gradients. See the model vignette for details: \code{vignette("model", package = "epikinetics")}. Each of these
#' parameters has a Gaussian prior, and these can be specified by the user. This function takes means and standard
#' deviations for each prior and constructs an object of type 'scova_priors' to be passed to the model.
#' @return A named list of type 'scova_priors'.
#' deviations for each prior and constructs an object of type 'biokinetics_priors' to be passed to the model.
#' @return A named list of type 'biokinetics_priors'.
#' @param mu_values Mean of Gaussian prior for each of t0, tp, ts, m1, m2, m3, in order.
#' @param sigma_values Standard deviation of Gaussian prior for each of t0, tp, ts, m1, m2, m3, in order.
#' @examples
#' priors <- scova_priors(mu_values = c(4.0, 10, 60, 0.25, -0.02, 0),
#' priors <- biokinetics_priors(mu_values = c(4.0, 10, 60, 0.25, -0.02, 0),
#' sigma_values = c(2.0, 2.0, 3.0, 0.01, 0.01, 0.01))
scova_priors <- function(mu_values = c(4.0, 10, 60, 0.25, -0.02, 0),
biokinetics_priors <- function(mu_values = c(4.0, 10, 60, 0.25, -0.02, 0),
sigma_values = c(2.0, 2.0, 3.0, 0.01, 0.01, 0.01)) {
names <- c("t0", "tp", "ts", "m1", "m2", "m3")
ret <- gaussian_priors(names, mu_values, sigma_values)
class(ret) <- append("scova_priors", class(ret))
class(ret) <- append("biokinetics_priors", class(ret))
ret
}
4 changes: 2 additions & 2 deletions R/simulate.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
scova_simulate_trajectory <- function(t, t0, tp, ts, m1, m2, m3) {
biokinetics_simulate_trajectory <- function(t, t0, tp, ts, m1, m2, m3) {
mu <- t0
if (t < tp) {
mu <- mu + m1 * t
Expand All @@ -10,6 +10,6 @@ scova_simulate_trajectory <- function(t, t0, tp, ts, m1, m2, m3) {
max(mu, 0)
}

scova_simulate_trajectories <- function(dat) {
biokinetics_simulate_trajectories <- function(dat) {
data.table::setDT(simulate_trajectories_cpp(dat))
}
74 changes: 37 additions & 37 deletions man/scova.Rd → man/biokinetics.Rd

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

16 changes: 8 additions & 8 deletions man/scova_priors.Rd → man/biokinetics_priors.Rd

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

12 changes: 6 additions & 6 deletions tests/testthat/test-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ local_mocked_bindings(

test_that("Can construct stan data", {
dt <- data.table::fread(system.file("delta_full.rds", package = "epikinetics"))
mod <- scova$new(data = dt,
priors = scova_priors(),
mod <- biokinetics$new(data = dt,
priors = biokinetics_priors(),
covariate_formula = ~0 + infection_history,
preds_sd = 0.25,
time_type = "relative")
Expand All @@ -20,12 +20,12 @@ test_that("Can construct stan data", {
})

test_that("Can initialise file path data", {
expect_true(inherits(scova$new(file_path = system.file("delta_full.rds", package = "epikinetics"),
priors = scova_priors()), "scova"))
expect_true(inherits(biokinetics$new(file_path = system.file("delta_full.rds", package = "epikinetics"),
priors = biokinetics_priors()), "biokinetics"))
})

test_that("Can provide data directly", {
dat <- data.table::fread(system.file("delta_full.rds", package = "epikinetics"))
expect_true(inherits(scova$new(data = dat,
priors = scova_priors()), "scova"))
expect_true(inherits(biokinetics$new(data = dat,
priors = biokinetics_priors()), "biokinetics"))
})
Loading
Loading