Skip to content

Commit

Permalink
Merge pull request #280 from OHDSI/issue_188
Browse files Browse the repository at this point in the history
renaming of estimates
  • Loading branch information
catalamarti authored Dec 20, 2024
2 parents c297a86 + 5ad600f commit 7a24da8
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 82 deletions.
18 changes: 9 additions & 9 deletions R/plotObservationPeriod.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
#'
#' result |>
#' plotObservationPeriod(
#' variableName = "duration in days",
#' variableName = "Duration in days",
#' plotType = "boxplot"
#' )
#'
#' PatientProfiles::mockDisconnect(cdm)
#' }
plotObservationPeriod <- function(result,
variableName = "number subjects",
variableName = "Number subjects",
plotType = "barplot",
facet = NULL,
colour = NULL) {
Expand Down Expand Up @@ -110,13 +110,13 @@ plotObservationPeriod <- function(result,
availablePlotObservationPeriod <- function() {
dplyr::tribble(
~variable_name, ~plot_type, ~facet,
"number subjects", "barplot", "cdm_name+observation_period_ordinal",
"records per person", "densityplot", "cdm_name",
"records per person", "boxplot", "cdm_name",
"duration in days", "densityplot", "cdm_name+observation_period_ordinal",
"duration in days", "boxplot", "cdm_name+observation_period_ordinal",
"days to next observation period", "densityplot", "cdm_name+observation_period_ordinal",
"days to next observation period", "boxplot", "cdm_name+observation_period_ordinal",
"Number subjects", "barplot", "cdm_name+observation_period_ordinal",
"Records per person", "densityplot", "cdm_name",
"Records per person", "boxplot", "cdm_name",
"Duration in days", "densityplot", "cdm_name+observation_period_ordinal",
"Duration in days", "boxplot", "cdm_name+observation_period_ordinal",
"Days to next observation period", "densityplot", "cdm_name+observation_period_ordinal",
"Days to next observation period", "boxplot", "cdm_name+observation_period_ordinal",
)
}
needEstimates <- function(plotType) {
Expand Down
5 changes: 4 additions & 1 deletion R/summariseAllConceptCounts.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ summariseAllConceptCounts <- function(cdm,
) |>
# summarise results
summariseCountsInternal(stratax, counts) |>
dplyr::mutate(omop_table = .env$table)
dplyr::mutate(omop_table = .env$table,
estimate_name = dplyr::if_else(.data$estimate_name == "count_records", "Number records",
dplyr::if_else(.data$estimate_name == "count_subjects", "Number subjects", .data$estimate_name)
))

omopgenerics::dropSourceTable(cdm = cdm, name = dplyr::starts_with(prefix))

Expand Down
13 changes: 7 additions & 6 deletions R/summariseClinicalRecords.R
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ summariseClinicalRecords <- function(cdm,
# Summary
if (inObservation | standardConcept | sourceVocabulary | domainId | typeConcept) {
denominator <- resultsRecordPerPerson |>
dplyr::filter(.data$variable_name == "number records") |>
dplyr::filter(.data$variable_name == "Number records") |>
dplyr::select("strata_name", "strata_level", den = "estimate_value")
variables <- variablesToSummarise(
inObservation, standardConcept, sourceVocabulary, domainId, typeConcept
Expand Down Expand Up @@ -258,7 +258,7 @@ summariseClinicalRecords <- function(cdm,
dplyr::select("strata_name", "strata_level") |>
dplyr::distinct() |>
dplyr::cross_join(dplyr::tibble(variable_name = unique(c(
"number subjects", "number records", "records_per_person",
"Number subjects", "Number records", "records_per_person",
unique(fullResult$variable_name)
)))) |>
dplyr::mutate(order_id = dplyr::row_number()) |>
Expand Down Expand Up @@ -319,17 +319,18 @@ summariseRecordsPerPerson <- function(x, den, strata, estimates) {
variables = list("number_subjects", "n"),
estimates = list(c("count", "percentage"), c(estimates, "sum"))
) |>
suppressMessages()
}) |>
suppressMessages() |>
dplyr::mutate(variable_name = dplyr::if_else(.data$variable_name == "number subjects", "Number subjects", .data$variable_name))
}) |>
dplyr::bind_rows() |>
dplyr::mutate(
variable_name = dplyr::if_else(
.data$variable_name == "n",
dplyr::if_else(.data$estimate_name == "sum", "number records", "records_per_person"),
dplyr::if_else(.data$estimate_name == "sum", "Number records", "records_per_person"),
.data$variable_name
),
estimate_name = dplyr::if_else(
.data$variable_name == "number records", "count", .data$estimate_name
.data$variable_name == "Number records", "count", .data$estimate_name
),
estimate_value = reduceDemicals(.data$estimate_value, 4)
)
Expand Down
2 changes: 1 addition & 1 deletion R/summariseInternal.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ summariseCountsInternal <- function(x, strata, counts) {
'dplyr::n_distinct(.data$person_id)',
'dplyr::n_distinct(.data$subject_id)'
) |>
rlang::set_names(c("count_records", "count_subjecst", "count_subjects")) |>
rlang::set_names(c("count_records", "count_subjects", "count_subjects")) |>
purrr::keep(c("records", "person_id", "subject_id") %in% counts) |>
rlang::parse_exprs()
purrr::map(strata, \(stratak) {
Expand Down
16 changes: 9 additions & 7 deletions R/summariseObservationPeriod.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ summariseObservationPeriod <- function(observationPeriod,
estimates = estimates
) |>
suppressMessages() |>
dplyr::mutate(variable_name = dplyr::if_else(.data$variable_name == "number records", "Number records",
dplyr::if_else(.data$variable_name == "number subjects", "Number subjects" , .data$variable_name))) |>
dplyr::union_all(
obs |>
dplyr::group_by(.data$person_id, dplyr::across(dplyr::any_of(c("sex","age_group")))) |>
Expand All @@ -107,17 +109,17 @@ summariseObservationPeriod <- function(observationPeriod,
suppressMessages()
) |>
addOrdinalLevels() |>
dplyr::filter(.data$variable_name != "number records" | .data$group_level == "all") |>
dplyr::filter(.data$variable_name != "Number records" | .data$group_level == "all") |>
arrangeSr(estimates)
}

obsSr <- obsSr |>
dplyr::mutate(
"cdm_name" = omopgenerics::cdmName(cdm),
"variable_name" = dplyr::case_when(
.data$variable_name == "n" ~ "records per person",
.data$variable_name == "next_obs" ~ "days to next observation period",
.data$variable_name == "duration" ~ "duration in days",
.data$variable_name == "n" ~ "Records per person",
.data$variable_name == "next_obs" ~ "Days to next observation period",
.data$variable_name == "duration" ~ "Duration in days",
.default = .data$variable_name
)
) |>
Expand Down Expand Up @@ -158,14 +160,14 @@ arrangeSr <- function(x, estimates) {
group <- c("all", sort(group[group != "all"]))

order <- dplyr::tibble(
"variable_name" = c("number records"),
"variable_name" = c("Number records"),
"group_level" = "all",
"strata_level" = lev,
"estimate_name" = "count"
) |>
dplyr::union_all(
tidyr::expand_grid(
"variable_name" = c("number subjects"),
"variable_name" = c("Number subjects"),
"group_level" = group,
"strata_level" = lev,
"estimate_name" = "count"
Expand All @@ -191,7 +193,7 @@ arrangeSr <- function(x, estimates) {
) |>
dplyr::left_join(
dplyr::tibble("variable_name" = c(
"number records", "number subjects", "n", "duration", "next_obs"
"Number records", "Number subjects", "n", "duration", "next_obs"
)) |>
dplyr::mutate("order_var" = dplyr::row_number()),
by = "variable_name"
Expand Down
2 changes: 1 addition & 1 deletion R/summariseRecordCount.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ summariseRecordCount <- function(cdm,
dplyr::mutate(
omop_table = .env$table,
estimate_name = "count",
variable_name = "incident_counts",
variable_name = "Number records",
variable_level = getVariableLevel(.data$additional_level),
result_id = 1L,
cdm_name = omopgenerics::cdmName(cdm)
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ OmopSketch also provides functions to explore some of (or all) the concepts in t
acetaminophen <- c(1125315, 1127433, 1127078)
summariseConceptSetCounts(cdm, conceptSet = list("acetaminophen" = acetaminophen)) |>
filter(estimate_name == "record_count") |>
filter(variable_name == "Number records") |>
plotConceptSetCounts()
```

Expand Down
4 changes: 2 additions & 2 deletions man/plotObservationPeriod.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-summariseClinicalRecords.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ test_that("summariseClinicalRecords() sex and ageGroup argument work", {
dplyr::mutate(dplyr::across(dplyr::everything(), as.character))

m_records <- m |>
dplyr::filter(variable_name == "number records", strata_level %in% c("<30", ">= 30"), estimate_name == "count") |>
dplyr::filter(variable_name == "Number records", strata_level %in% c("<30", ">= 30"), estimate_name == "count") |>
dplyr::select("age_group" = "strata_level", "estimate_value") |>
dplyr::collect() |>
dplyr::arrange(age_group)
m_subjects <- m |>
dplyr::filter(variable_name == "number subjects", strata_level %in% c("<30", ">= 30"), estimate_name == "count") |>
dplyr::filter(variable_name == "Number subjects", strata_level %in% c("<30", ">= 30"), estimate_name == "count") |>
dplyr::select("age_group" = "strata_level", "estimate_value") |>
dplyr::collect() |>
dplyr::arrange(age_group)
Expand All @@ -153,7 +153,7 @@ test_that("summariseClinicalRecords() sex and ageGroup argument work", {

# Check sex and age group---
x <- summariseClinicalRecords(cdm, "condition_occurrence", sex = TRUE, ageGroup = list(">= 30" = c(30, Inf), "<30" = c(0, 29))) |>
dplyr::filter(variable_name == "number subjects", estimate_name == "count",
dplyr::filter(variable_name == "Number subjects", estimate_name == "count",
strata_name == "sex" | strata_name == "overall") |>
dplyr::select("strata_name", "strata_level", "estimate_value") |>
dplyr::mutate(group = dplyr::if_else(strata_name == "overall",1, 2)) |>
Expand All @@ -162,7 +162,7 @@ test_that("summariseClinicalRecords() sex and ageGroup argument work", {
expect_equal(x$n[[1]], x$n[[2]])

x <- summariseClinicalRecords(cdm, "condition_occurrence", sex = TRUE, ageGroup = list(">= 30" = c(30, Inf), "<30" = c(0, 29))) |>
dplyr::filter(variable_name == "number records", estimate_name == "count",
dplyr::filter(variable_name == "Number records", estimate_name == "count",
strata_name == "sex" | strata_name == "overall") |>
dplyr::select("strata_name", "strata_level", "estimate_value") |>
dplyr::mutate(group = dplyr::if_else(strata_name == "overall",1, 2)) |>
Expand All @@ -171,7 +171,7 @@ test_that("summariseClinicalRecords() sex and ageGroup argument work", {
expect_equal(x$n[[1]], x$n[[2]])

x <- summariseClinicalRecords(cdm, "condition_occurrence", sex = TRUE, ageGroup = list(">= 30" = c(30, Inf), "<30" = c(0, 29))) |>
dplyr::filter(variable_name == "number records", estimate_name == "count",
dplyr::filter(variable_name == "Number records", estimate_name == "count",
strata_name == "age_group" | strata_name == "overall") |>
dplyr::select("strata_name", "strata_level", "estimate_value") |>
dplyr::mutate(group = dplyr::if_else(strata_name == "overall",1, 2)) |>
Expand Down Expand Up @@ -229,7 +229,7 @@ test_that("summariseClinicalRecords() sex and ageGroup argument work", {

# Check num records
records <- result |>
dplyr::filter(variable_name == "number records", estimate_name == "count")
dplyr::filter(variable_name == "Number records", estimate_name == "count")
expect_identical(records |> dplyr::filter(strata_name == "overall") |> dplyr::pull(estimate_value), "9")
expect_identical(records |> dplyr::filter(strata_level == "old") |> dplyr::pull(estimate_value), "5")
expect_identical(records |> dplyr::filter(strata_level == "young") |> dplyr::pull(estimate_value), "4")
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-summariseConceptSetCounts.R
Original file line number Diff line number Diff line change
Expand Up @@ -578,17 +578,17 @@ test_that("interval argument works", {
skip_on_cran()
# Load mock database ----
cdm <- mockOmopSketch()
expect_no_error(y<-summariseConceptCounts(list(ANTIHISTAMINES= c(21603444)),
expect_no_error(y<-summariseConceptSetCounts(list(ANTIHISTAMINES= c(21603444)),
cdm = cdm,
interval = "years"))

expect_no_error(o<-summariseConceptCounts(list(ANTIHISTAMINES= c(21603444)),
expect_no_error(o<-summariseConceptSetCounts(list(ANTIHISTAMINES= c(21603444)),
cdm = cdm,
interval = "overall"))
expect_no_error(q<-summariseConceptCounts(list(ANTIHISTAMINES= c(21603444)),
expect_no_error(q<-summariseConceptSetCounts(list(ANTIHISTAMINES= c(21603444)),
cdm = cdm,
interval = "quarters"))
expect_no_error(m<-summariseConceptCounts(list(ANTIHISTAMINES= c(21603444)),
expect_no_error(m<-summariseConceptSetCounts(list(ANTIHISTAMINES= c(21603444)),
cdm = cdm,
interval = "months"))

Expand Down
Loading

0 comments on commit 7a24da8

Please sign in to comment.