Skip to content

Commit

Permalink
Andromeda update
Browse files Browse the repository at this point in the history
updating for Andromeda update
  • Loading branch information
jreps committed Jul 9, 2020
1 parent 934dc5f commit 5dbd461
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 35 deletions.
13 changes: 6 additions & 7 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: BipolarMisclassificationValidation
Type: Package
Title: External Validation of Model Predicting Bipolar Misdiagnosed as MDD
Version: 0.0.1
Date: 2020-01-01
Version: 0.0.2
Date: 2020-07-09
Author: Jenna Reps
Maintainer: Jenna Reps <youremail@address>
Description: This study applies and evaluates a simple score model to OMOP CDM data that predicts which newly diagnosed MDD patients will be diagnosed with bipolar within the next 3 years
Expand All @@ -12,17 +12,16 @@ Depends:
DatabaseConnector (>= 1.11.4),
survival
Imports:
FeatureExtraction (>= 2.0.0),
FeatureExtraction (>= 3.0.0),
SqlRender,
Cyclops (>= 1.2.2),
PatientLevelPrediction (>= 3.0.10),
PatientLevelPrediction (>= 4.0.0),
ggplot2,
gridExtra,
ff,
ffbase (>= 0.12.1),
Andromeda,
ParallelLogger,
OhdsiSharing
Suggests:
testthat
NeedsCompilation: no
RoxygenNote: 6.0.1
RoxygenNote: 7.1.0
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export(getTable1)
export(packageResults)
export(transportPlpModels)
import(DatabaseConnector)
importFrom(magrittr,"%>%")
24 changes: 24 additions & 0 deletions R/BipolarMisclassificationValidation.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# @file BipolarMisclassificationValidation.R
#
# Copyright 2020 Observational Health Data Sciences and Informatics
#
# This file is part of BipolarMisclassificationValidation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#' BipolarMisclassificationValidation
#'
#' @docType package
#' @name BipolarMisclassificationValidation
#' @importFrom magrittr %>%
NULL
43 changes: 32 additions & 11 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,26 @@ getBipolarData <- function(connectionDetails,
predictBipolar <- function(plpData, population){
coefficients <- getModel()

if('covariateData'%in%names(plpData)){
plpData$covariateData$coefficients <- tibble::as_tibble(coefficients)
on.exit(plpData$covariateData$coefficients <- NULL)

prediction <- plpData$covariateData$covariates %>%
dplyr::inner_join(plpData$covariateData$coefficients, by = "covariateId") %>%
dplyr::mutate(value = covariateValue*points) %>%
dplyr::select(rowId, value) %>%
dplyr::group_by(rowId) %>%
dplyr::summarise(value = sum(value, na.rm = TRUE)) %>% dplyr::collect()


} else{

prediction <- merge(plpData$covariates, ff::as.ffdf(coefficients), by = "covariateId")
prediction$value <- prediction$covariateValue * prediction$points
prediction <- PatientLevelPrediction:::bySumFf(prediction$value, prediction$rowId)
colnames(prediction) <- c("rowId", "value")
}

prediction <- merge(population, prediction, by ="rowId", all.x = TRUE)
prediction$value[is.na(prediction$value)] <- 0

Expand Down Expand Up @@ -427,17 +443,23 @@ getCohortCovariateData <- function(connection,
countval = covariateSettings$count)
sql <- SqlRender::translate(sql, targetDialect = attr(connection, "dbms"), oracleTempSchema = oracleTempSchema)
# Retrieve the covariate:
covariates <- DatabaseConnector::querySql.ffdf(connection, sql)
covariates <- DatabaseConnector::querySql(connection, sql)
# Convert colum names to camelCase:
colnames(covariates) <- SqlRender::snakeCaseToCamelCase(colnames(covariates))
# Construct covariate reference:
sql <- "select @covariate_id as covariate_id, '@concept_set' as covariate_name,
12 as analysis_id, -1 as concept_id"
456 as analysis_id, -1 as concept_id"
sql <- SqlRender::render(sql, covariate_id = covariateSettings$covariateId,
concept_set=paste(covariateSettings$covariateName,' days before:', covariateSettings$startDay, 'days after:', covariateSettings$endDay))
sql <- SqlRender::translate(sql, targetDialect = attr(connection, "dbms"), oracleTempSchema = oracleTempSchema)
concept_set=paste(ifelse(covariateSettings$count, 'Number of', ''),
covariateSettings$covariateName,
ifelse(covariateSettings$ageInteraction, ' X Age', ''),
' days before:', covariateSettings$startDay, 'days after:', covariateSettings$endDay)

)
sql <- SqlRender::translate(sql, targetDialect = attr(connection, "dbms"),
oracleTempSchema = oracleTempSchema)
# Retrieve the covariateRef:
covariateRef <- DatabaseConnector::querySql.ffdf(connection, sql)
covariateRef <- DatabaseConnector::querySql(connection, sql)
colnames(covariateRef) <- SqlRender::snakeCaseToCamelCase(colnames(covariateRef))

analysisRef <- data.frame(analysisId = 4,
Expand All @@ -447,14 +469,13 @@ getCohortCovariateData <- function(connection,
endDay = 0,
isBinary = "Y",
missingMeansZero = "Y")
analysisRef <- ff::as.ffdf(analysisRef)

metaData <- list(sql = sql, call = match.call())
result <- list(covariates = covariates,
covariateRef = covariateRef,
analysisRef=analysisRef,
metaData = metaData)
class(result) <- "covariateData"
result <- Andromeda::andromeda(covariates = covariates,
covariateRef = covariateRef,
analysisRef = analysisRef)
attr(result, "metaData") <- metaData
class(result) <- "CovariateData"
return(result)
}

Expand Down
6 changes: 6 additions & 0 deletions man/BipolarMisclassificationValidation.Rd

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

4 changes: 0 additions & 4 deletions man/SkeletonValidationPackage.Rd

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

10 changes: 8 additions & 2 deletions man/createCohorts.Rd

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

19 changes: 15 additions & 4 deletions man/execute.Rd

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

14 changes: 11 additions & 3 deletions man/getCohortCovariateData.Rd

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

11 changes: 9 additions & 2 deletions man/getTable1.Rd

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

8 changes: 6 additions & 2 deletions man/transportPlpModels.Rd

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

0 comments on commit 5dbd461

Please sign in to comment.