R/Mappers.R

Defines functions reformatePerformance getMap

getMap <- function(model = 'SimpleModel'){
  if(model == 'SimpleModel'){
    map <- function(x){1/(1+exp(-(x-0)))} #logistic function with 0 intercept
  } else {
    mapLoc <- system.file("settings", paste0(model,'_finalMap.rds' ), package = "PCE")
    map <- readRDS(mapLoc)
  }
  return(map)
}


reformatePerformance <- function(performance,analysisId){
  
  nr1 <- length(unlist(performance$evaluationStatistics[-1]))
  performance$evaluationStatistics <- cbind(analysisId= rep(analysisId,nr1),
                                            Eval=rep('validation', nr1),
                                            Metric = names(unlist(performance$evaluationStatistics[-1])),
                                            Value = unlist(performance$evaluationStatistics[-1])
  )
  nr1 <- nrow(performance$thresholdSummary)
  performance$thresholdSummary <- cbind(analysisId=rep(analysisId,nr1),
                                        Eval=rep('validation', nr1),
                                        performance$thresholdSummary)
  nr1 <- nrow(performance$demographicSummary)
  if(!is.null(performance$demographicSummary)){
    performance$demographicSummary <- cbind(analysisId=rep(analysisId,nr1),
                                            Eval=rep('validation', nr1),
                                            performance$demographicSummary)
  }
  nr1 <- nrow(performance$calibrationSummary)
  performance$calibrationSummary <- cbind(analysisId=rep(analysisId,nr1),
                                          Eval=rep('validation', nr1),
                                          performance$calibrationSummary)
  nr1 <- nrow(performance$predictionDistribution)
  performance$predictionDistribution <- cbind(analysisId=rep(analysisId,nr1),
                                              Eval=rep('validation', nr1),
                                              performance$predictionDistribution)
  
  return(performance)
  
}
ohdsi-studies/PCE documentation built on Feb. 15, 2021, 6:33 a.m.