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

Issue 17: Fixes to data.table assignment #18

Merged
merged 3 commits into from
May 10, 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
6 changes: 5 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ Authors@R:
person(given = "Sam Abbott",
role = c("aut"),
email = "contact@samabbott.co.uk",
comment = c(ORCID = "0000-0001-8057-8037")))
comment = c(ORCID = "0000-0001-8057-8037")),
person(given = "Adam Howes",
role = c("aut"),
email = "adamthowes@gmail.com",
comment = c(ORCID = "0000-0003-2386-4031")))
Description: Understanding and accurately estimating epidemiological delay
distributions is important for public health policy. These estimates
directly influence epidemic situational awareness, control strategies, and resource allocation. In this package, we provide methods to address the key challenges in estimating these distributions, including truncation, interval censoring, and dynamical biases. Despite their importance, these issues are frequently overlooked, often resulting in biased conclusions.
Expand Down
2 changes: 1 addition & 1 deletion R/fitting-and-postprocessing.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
fit <- safe_fit_model(model, data, ...)

if (!is.null(fit$error)) {
out[, error := list(fit$error[[1]])]

Check warning on line 18 in R/fitting-and-postprocessing.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/fitting-and-postprocessing.R,line=18,col=11,[object_usage_linter] no visible binding for global variable 'error'
diagnostics <- FALSE
}else {
out[, fit := list(fit$result)]
Expand All @@ -37,12 +37,12 @@
per_divergent_transitions = sum(diag$divergent__) / nrow(diag),
max_treedepth = max(diag$treedepth__)
)
diagnostics[, no_at_max_treedepth := sum(diag$treedepth__ == max_treedepth)]

Check warning on line 40 in R/fitting-and-postprocessing.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/fitting-and-postprocessing.R,line=40,col=19,[object_usage_linter] no visible binding for global variable 'no_at_max_treedepth'

Check warning on line 40 in R/fitting-and-postprocessing.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/fitting-and-postprocessing.R,line=40,col=66,[object_usage_linter] no visible binding for global variable 'max_treedepth'
diagnostics[, per_at_max_treedepth := no_at_max_treedepth / nrow(diag)]

Check warning on line 41 in R/fitting-and-postprocessing.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/fitting-and-postprocessing.R,line=41,col=19,[object_usage_linter] no visible binding for global variable 'per_at_max_treedepth'

Check warning on line 41 in R/fitting-and-postprocessing.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/fitting-and-postprocessing.R,line=41,col=43,[object_usage_linter] no visible binding for global variable 'no_at_max_treedepth'
out <- cbind(out, diagnostics)

timing <- round(fit$time()$total, 1)
out[, run_time := timing]

Check warning on line 45 in R/fitting-and-postprocessing.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/fitting-and-postprocessing.R,line=45,col=11,[object_usage_linter] no visible binding for global variable 'run_time'
}
return(out[])
}
Expand All @@ -68,7 +68,7 @@
fit <- safe_fit_model(model, data, ...)

if (!is.null(fit$error)) {
out[, error := list(fit$error[[1]])]

Check warning on line 71 in R/fitting-and-postprocessing.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/fitting-and-postprocessing.R,line=71,col=11,[object_usage_linter] no visible binding for global variable 'error'
diagnostics <- FALSE
}else {
out[, fit := list(fit$result)]
Expand Down Expand Up @@ -104,8 +104,8 @@
per_divergent_transitions = sum(diag$divergent__) / nrow(diag),
max_treedepth = max(diag$treedepth__)
)
diagnostics[, no_at_max_treedepth := sum(diag$treedepth__ == max_treedepth)]

Check warning on line 107 in R/fitting-and-postprocessing.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/fitting-and-postprocessing.R,line=107,col=19,[object_usage_linter] no visible binding for global variable 'no_at_max_treedepth'

Check warning on line 107 in R/fitting-and-postprocessing.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/fitting-and-postprocessing.R,line=107,col=66,[object_usage_linter] no visible binding for global variable 'max_treedepth'
diagnostics[, per_at_max_treedepth := no_at_max_treedepth / nrow(diag)]

Check warning on line 108 in R/fitting-and-postprocessing.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/fitting-and-postprocessing.R,line=108,col=19,[object_usage_linter] no visible binding for global variable 'per_at_max_treedepth'
out <- cbind(out, diagnostics)

timing <- round(max(fit$metadata()$time$total), 1)
Expand Down Expand Up @@ -204,7 +204,7 @@
draws <- data.table::copy(draws)
draws[, mean := mean - runif(.N, min = 0, max = 1)]
draws[, meanlog := log(mean^2 / sqrt(sd^2 + mean^2))]
draw[, sdlog := sqrt(log(1 + (sd^2 / mean^2)))]
draws[, sdlog := sqrt(log(1 + (sd^2 / mean^2)))]

return(draws[])
}
Expand Down
2 changes: 1 addition & 1 deletion R/observe.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pad_zero <- function(data, pad = 1e-3) {
#' @export
drop_zero <- function(data) {
data <- data.table::copy(data)
data[delay_daily != 0]
data <- data[delay_daily != 0]

return(data)
}
2 changes: 1 addition & 1 deletion R/plot-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ calculate_cohort_mean <- function(data, type = c("cohort", "cumulative"),
mean = mean(delay_daily), n = .N),
by = c("ptime_daily", by)]

out[order(rank(ptime_daily))]
out <- out[order(rank(ptime_daily))]

if (type == "cumulative") {
out[, mean := cumsum(mean * n) / cumsum(n), by = by]
Expand Down
2 changes: 1 addition & 1 deletion R/preprocess.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ event_to_incidence <- function(data, by = c()) {
dd <- data.table::copy(data)

dd[, .(cases = .N), by = c("ptime_daily", by)]
dd[order(ptime_daily)]
dd <- dd[order(ptime_daily)]

setnames(dd, old = c("ptime_daily"), new = c("time"))

Expand Down
Loading