Skip to content

Commit

Permalink
Merge pull request #501 from OHDSI/recalibration_docs
Browse files Browse the repository at this point in the history
fix docs in recalibration code and add model output to recalibratePlpRefit
  • Loading branch information
egillax authored Nov 12, 2024
2 parents 253d1b7 + aa43797 commit 5f53965
Show file tree
Hide file tree
Showing 12 changed files with 314 additions and 237 deletions.
9 changes: 6 additions & 3 deletions R/EvaluationSummary.R
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,14 @@ averagePrecision <- function(prediction){
}



calibrationInLarge <- function(prediction){
#' Calculate the calibration in large
#' @param prediction A prediction dataframe
#' @return data.frame with meanPredictionRisk, observedRisk, and N
#' @keywords internal
calibrationInLarge <- function(prediction) {

result <- data.frame(meanPredictionRisk = mean(prediction$value),
observedRisk = sum(prediction$outcomeCount)/nrow(prediction),
observedRisk = sum(prediction$outcomeCount) / nrow(prediction),
N = nrow(prediction)
)

Expand Down
4 changes: 2 additions & 2 deletions R/Glm.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#' @param data An object of type \code{plpData} - the patient level prediction
#' data extracted from the CDM.
#' @param cohort The population dataframe created using
#' /code{createStudyPopulation} who will have their risks predicted or a cohort
#' \code{createStudyPopulation} who will have their risks predicted or a cohort
#' without the outcome known
#' @export
#' @return A dataframe containing the prediction for each person in the
Expand Down Expand Up @@ -75,7 +75,7 @@ predictGlm <- function(plpModel, data, cohort) {
#' PatientLevelPrediction package.
#' @param coefficients A dataframe containing two columns, coefficients and
#' covariateId, both of type numeric. The covariateId column must contain
#' valid covariateIds that match those used in the /code{FeatureExtraction}
#' valid covariateIds that match those used in the \code{FeatureExtraction}
#' package.
#' @param intercept A numeric value representing the intercept of the model.
#' @param finalMapping A string representing the final mapping from the
Expand Down
12 changes: 6 additions & 6 deletions R/Plotting.R
Original file line number Diff line number Diff line change
Expand Up @@ -1259,14 +1259,14 @@ plotNetBenefit <- function(plpResult,
}

plots[[i]] <- ggplot2::ggplot(data = nbData, ggplot2::aes(x = .data$threshold)) +
ggplot2::geom_line(ggplot2::aes(y = treatAll, color = "Treat All", linetype = "Treat All")) +
ggplot2::geom_line(ggplot2::aes(y = treatNone, color = "Treat None", linetype = "Treat None")) +
ggplot2::geom_line(ggplot2::aes(y = netBenefit, color = "Net Benefit", linetype = "Net Benefit")) +
ggplot2::geom_line(ggplot2::aes(y = .data$treatAll, color = "Treat All", linetype = "Treat All")) +
ggplot2::geom_line(ggplot2::aes(y = .data$treatNone, color = "Treat None", linetype = "Treat None")) +
ggplot2::geom_line(ggplot2::aes(y = .data$netBenefit, color = "Net Benefit", linetype = "Net Benefit")) +
ggplot2::scale_color_manual(
name = "Strategies",
values = c(
"Net Benefit" = "blue",
"Treat All" = "red",
"Model" = "blue",
"Treat all" = "red",
"Treat None" = "brown"
)
) +
Expand All @@ -1290,7 +1290,7 @@ plotNetBenefit <- function(plpResult,

if (!is.null(saveLocation)) {
if (!dir.exists(saveLocation)) {
dir.create(saveLocation, recursive = T)
dir.create(saveLocation, recursive = TRUE)
}
ggplot2::ggsave(file.path(saveLocation, fileName), plot, width = 5, height = 4.5, dpi = 400)
}
Expand Down
Loading

0 comments on commit 5f53965

Please sign in to comment.