From 7dcbebd1a71524142ae5f461ce09587e6b95e894 Mon Sep 17 00:00:00 2001 From: jgilber2 Date: Tue, 7 Jan 2025 10:28:32 -0800 Subject: [PATCH] changes for data model --- DESCRIPTION | 2 ++ R/RunAnalyses.R | 2 ++ R/SelfControlledCohort.R | 17 ++++++++--------- inst/resultsDataModelSpecification.csv | 11 +++++------ man/getSccRiskWindowStats.Rd | 2 +- man/runSccAnalyses.Rd | 3 +++ man/runSelfControlledCohort.Rd | 4 ++-- tests/testthat/test-RunAnalyses.R | 1 + tests/testthat/test-SelfControlledCohort.R | 1 + 9 files changed, 25 insertions(+), 18 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index be531dc..ce46ce6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -35,6 +35,8 @@ Suggests: DiagrammeR, tidyr, R.utils +Remotes: + OHDSI/ResultModelManager@big_int_type_check License: Apache License 2.0 RoxygenNote: 7.3.2 VignetteBuilder: knitr diff --git a/R/RunAnalyses.R b/R/RunAnalyses.R index 23a5957..7cec271 100644 --- a/R/RunAnalyses.R +++ b/R/RunAnalyses.R @@ -44,6 +44,7 @@ runSccAnalyses <- function(connectionDetails, outputFolder = "./SelfControlledCohortOutput", sccAnalysisList, exposureOutcomeList, + databaseId, controlType = "outcome", analysisThreads = 1, computeThreads = 1) { @@ -116,6 +117,7 @@ runSccAnalyses <- function(connectionDetails, cdmVersion = cdmVersion, exposureIds = exposureIds, outcomeIds = outcomeId, + databaseId = databaseId, controlType = controlType, analysisId = refRow$analysisId, tempEmulationSchema = tempEmulationSchema, diff --git a/R/SelfControlledCohort.R b/R/SelfControlledCohort.R index 63ab160..ea89fb1 100644 --- a/R/SelfControlledCohort.R +++ b/R/SelfControlledCohort.R @@ -44,13 +44,13 @@ computeIrrs <- function(estimates) { timeAtRiskExposed = estimates$time_at_risk_exposed, timeAtRiskUnexposed = estimates$time_at_risk_unexposed) - estimates$irr <- irrs[1,] - estimates$irrLb95 <- irrs[2,] - estimates$irrUb95 <- irrs[3,] + estimates$rr <- irrs[1,] + estimates$irr_lb_95 <- irrs[2,] + estimates$irr_ub_95 <- irrs[3,] - estimates$logRr <- log(estimates$irr) - estimates$seLogRr <- (log(estimates$irrUb95) - log(estimates$irrLb95)) / (2 * qnorm(0.975)) - zTest <- stats::pnorm(estimates$logRr / estimates$seLogRr) + estimates$log_rr <- log(estimates$rr) + estimates$se_log_rr <- (log(estimates$irr_ub_95) - log(estimates$irr_lb_95)) / (2 * qnorm(0.975)) + zTest <- stats::pnorm(estimates$log_rr / estimates$se_log_rr) estimates$p <- 2 * pmin(zTest, 1 - zTest) return(estimates) } @@ -135,7 +135,6 @@ batchComputeEstimates <- function(connection, ncPairsDf |> dplyr::group_by(.data$outcomeCohortId) |> dplyr::group_map(function(data, outcomeCohortId) { - browser() estimates <- andromeda$estimates |> dplyr::filter(.data$outcomeCohortId == outcomeCohortId) @@ -266,7 +265,7 @@ batchComputeEstimates <- function(connection, #' confidence intervals. #' @param resultExportPath Folder where result files are exported #' @param outputFolder Folder where intermediate files are stored -#' @param databaseId Unique identifier for database +#' @param databaseId Unique identifier for database - required #' @param resultExportManager ResultModelManager::ResultExportManager instance - customize this to implement #' an alternative mechanism for exporting results #' @@ -325,7 +324,7 @@ runSelfControlledCohort <- function(connectionDetails = NULL, resultsDatabaseSchema = NULL, resultExportPath = "scc_result", outputFolder = "scc_work", - databaseId = NULL, + databaseId, analysisId = 1, resultExportManager = ResultModelManager::createResultExportManager( tableSpecification = getResultsDataModelSpecifications(), diff --git a/inst/resultsDataModelSpecification.csv b/inst/resultsDataModelSpecification.csv index 54b2687..307629e 100644 --- a/inst/resultsDataModelSpecification.csv +++ b/inst/resultsDataModelSpecification.csv @@ -19,12 +19,11 @@ scc_result,calibrated_lb_95,float,0,0,0,Lower bound of the 95% confidence interv scc_result,calibrated_ub_95,float,0,0,0,Upper bound of the 95% confidence interval for calibrated results scc_result,calibrated_p_value,float,0,0,0,P-value for calibrated results scc_result,exposure_calibrated,int,0,0,0,Is the result calibrated with exposure negative controls or outcomes? -scc_result,c_pt,float,0,0,0,Unexposed pt -scc_result,t_pt,float,0,0,0,Exposed pt -scc_result,t_at_risk,float,0,0,0,Time at risk exposed -scc_result,c_at_risk,float,0,0,0,Time at risk unexposed -scc_result,t_cases,float,0,0,1,Cases while exposed -scc_result,c_cases,float,0,0,1,Cases while unexposed +scc_result,num_persons,float,0,0,0,person count +scc_result,time_at_risk_exposed,float,0,0,0,Time at risk exposed +scc_result,time_at_risk_unexposed,float,0,0,0,Time at risk unexposed +scc_result,num_outcomes_exposed,float,0,0,1,Cases while exposed +scc_result,num_outcomes_unexposed,float,0,0,1,Cases while unexposed scc_result,num_exposures,float,0,0,1,Number of exposures scc_result,i_2,float,0,0,0,I² statistic for heterogeneity scc_stat,database_id,int,1,1,0,Unique identifier for the database diff --git a/man/getSccRiskWindowStats.Rd b/man/getSccRiskWindowStats.Rd index fc18a55..49dee9a 100644 --- a/man/getSccRiskWindowStats.Rd +++ b/man/getSccRiskWindowStats.Rd @@ -63,7 +63,7 @@ table.} \item{resultExportPath}{Folder where result files are exported} -\item{databaseId}{Unique identifier for database} +\item{databaseId}{Unique identifier for database - required} \item{resultExportManager}{ResultModelManager::ResultExportManager instance - customize this to implement an alternative mechanism for exporting results} diff --git a/man/runSccAnalyses.Rd b/man/runSccAnalyses.Rd index e6996ad..8260db8 100644 --- a/man/runSccAnalyses.Rd +++ b/man/runSccAnalyses.Rd @@ -16,6 +16,7 @@ runSccAnalyses( outputFolder = "./SelfControlledCohortOutput", sccAnalysisList, exposureOutcomeList, + databaseId, controlType = "outcome", analysisThreads = 1, computeThreads = 1 @@ -66,6 +67,8 @@ COHORT_END_DATE.} \item{exposureOutcomeList}{A list of objects of type \code{exposureOutcome} as created using the \code{\link{createExposureOutcome}} function.} +\item{databaseId}{Unique identifier for database - required} + \item{controlType}{Calibrate effect estimates with outcome (default) or exposure controls} \item{analysisThreads}{The number of parallel threads to use to execute the analyses.} diff --git a/man/runSelfControlledCohort.Rd b/man/runSelfControlledCohort.Rd index 4862a67..9f763ef 100644 --- a/man/runSelfControlledCohort.Rd +++ b/man/runSelfControlledCohort.Rd @@ -41,7 +41,7 @@ runSelfControlledCohort( resultsDatabaseSchema = NULL, resultExportPath = "scc_result", outputFolder = "scc_work", - databaseId = NULL, + databaseId, analysisId = 1, resultExportManager = ResultModelManager::createResultExportManager(tableSpecification = getResultsDataModelSpecifications(), exportDir = resultExportPath, databaseId = @@ -174,7 +174,7 @@ riskWindowsTable are temporary.} \item{outputFolder}{Folder where intermediate files are stored} -\item{databaseId}{Unique identifier for database} +\item{databaseId}{Unique identifier for database - required} \item{resultExportManager}{ResultModelManager::ResultExportManager instance - customize this to implement an alternative mechanism for exporting results} diff --git a/tests/testthat/test-RunAnalyses.R b/tests/testthat/test-RunAnalyses.R index b61a65b..eda8847 100644 --- a/tests/testthat/test-RunAnalyses.R +++ b/tests/testthat/test-RunAnalyses.R @@ -21,6 +21,7 @@ test_that("multiple analyses", { sccAnalysisList = sccAnalysisList, exposureOutcomeList = exposureOutcomeList, outputFolder = outputFolder, + databaseId = 1, computeThreads = 1) expect_s3_class(rr, "data.frame") diff --git a/tests/testthat/test-SelfControlledCohort.R b/tests/testthat/test-SelfControlledCohort.R index c63feb2..e28e470 100644 --- a/tests/testthat/test-SelfControlledCohort.R +++ b/tests/testthat/test-SelfControlledCohort.R @@ -18,6 +18,7 @@ test_that("SCC method runs on Eunomia", { cdmDatabaseSchema = "main", exposureIds = '', outcomeIds = '', + databaseId = 1, riskWindowEndExposed = 1, riskWindowStartExposed = 30, addLengthOfExposureExposed = F),