Plot the Observed vs. expected incidence, by age and gender
Source:R/Plotting.R
plotDemographicSummary.Rd
Plot the Observed vs. expected incidence, by age and gender
Usage
plotDemographicSummary(
plpResult,
typeColumn = "evaluation",
saveLocation = NULL,
fileName = "roc.png"
)
Arguments
- plpResult
A plp result object as generated using the
runPlp
function.- typeColumn
The name of the column specifying the evaluation type
- saveLocation
Directory to save plot (if NULL plot is not saved)
- fileName
Name of the file to save to plot, for example 'plot.png'. See the function
ggsave
in the ggplot2 package for supported file formats.
Value
A ggplot object. Use the ggsave
function to save to file in a different
format.
Examples
# \donttest{
data("simulationProfile")
plpData <- simulatePlpData(simulationProfile, n=1000)
#> Generating covariates
#> Generating cohorts
#> Generating outcomes
saveLoc <- file.path(tempdir(), "plotDemographicSummary")
plpResult <- runPlp(plpData, outcomeId = 3, saveDirectory = saveLoc)
#> Use timeStamp: TRUE
#> Creating save directory at: /tmp/RtmpPJeNgk/plotDemographicSummary/2025-02-17-3
#> Currently in a tryCatch or withCallingHandlers block, so unable to add global calling handlers. ParallelLogger will not capture R messages, errors, and warnings, only explicit calls to ParallelLogger. (This message will not be shown again this R session)
#> Patient-Level Prediction Package version 6.4.0
#> Study started at: 2025-02-17 17:02:51.441872
#> AnalysisID: 2025-02-17-3
#> AnalysisName: Study details
#> TargetID: 1
#> OutcomeID: 3
#> Cohort size: 1000
#> Covariates: 98
#> Creating population
#> Outcome is 0 or 1
#> Population created with: 961 observations, 961 unique subjects and 422 outcomes
#> Population created in 0.0461 secs
#> seed: 123
#> Creating a 25% test and 75% train (into 3 folds) random stratified split by class
#> Data split into 239 test cases and 722 train cases (241, 241, 240)
#> Data split in 0.235 secs
#> Train Set:
#> Fold 1 241 patients with 106 outcomes - Fold 2 241 patients with 106 outcomes - Fold 3 240 patients with 105 outcomes
#> 69 covariates in train data
#> Test Set:
#> 239 patients with 105 outcomes
#> Removing 1 redundant covariates
#> Removing 0 infrequent covariates
#> Normalizing covariates
#> Tidying covariates took 0.694 secs
#> Train Set:
#> Fold 1 241 patients with 106 outcomes - Fold 2 241 patients with 106 outcomes - Fold 3 240 patients with 105 outcomes
#> 68 covariates in train data
#> Test Set:
#> 239 patients with 105 outcomes
#>
#> Running Cyclops
#> Done.
#> GLM fit status: OK
#> Creating variable importance data frame
#> Prediction took 0.114 secs
#> Time to fit model: 0.24 secs
#> Removing infrequent and redundant covariates and normalizing
#> Removing infrequent and redundant covariates covariates and normalizing took 0.145 secs
#> Prediction took 0.103 secs
#> Prediction done in: 0.326 secs
#> Calculating Performance for Test
#> =============
#> AUC 53.62
#> 95% lower AUC: 46.41
#> 95% upper AUC: 60.83
#> AUPRC: 49.96
#> Brier: 0.24
#> Eavg: 0.05
#> Calibration in large- Mean predicted risk 0.443 : observed risk 0.4393
#> Calibration in large- Intercept -0.0957
#> Weak calibration intercept: -0.0957 - gradient:0.6584
#> Hosmer-Lemeshow calibration gradient: 0.88 intercept: 0.02
#> Average Precision: 0.51
#> Calculating Performance for Train
#> =============
#> AUC 62.42
#> 95% lower AUC: 58.41
#> 95% upper AUC: 66.42
#> AUPRC: 58.29
#> Brier: 0.23
#> Eavg: 0.04
#> Calibration in large- Mean predicted risk 0.4391 : observed risk 0.4391
#> Calibration in large- Intercept 0.0466
#> Weak calibration intercept: 0.0466 - gradient:1.1772
#> Hosmer-Lemeshow calibration gradient: 1.23 intercept: -0.09
#> Average Precision: 0.59
#> Calculating Performance for CV
#> =============
#> AUC 57.05
#> 95% lower AUC: 52.77
#> 95% upper AUC: 61.33
#> AUPRC: 53.05
#> Brier: 0.23
#> Eavg: 0.03
#> Calibration in large- Mean predicted risk 0.439 : observed risk 0.4391
#> Calibration in large- Intercept 0.0157
#> Weak calibration intercept: 0.0157 - gradient:1.0604
#> Hosmer-Lemeshow calibration gradient: 1.16 intercept: -0.10
#> Average Precision: 0.54
#> Time to calculate evaluation metrics: 0.209 secs
#> Calculating covariate summary @ 2025-02-17 17:02:53.420352
#> This can take a while...
#> Creating binary labels
#> Joining with strata
#> calculating subset of strata 1
#> calculating subset of strata 2
#> calculating subset of strata 3
#> calculating subset of strata 4
#> Restricting to subgroup
#> Calculating summary for subgroup TrainWithOutcome
#> Restricting to subgroup
#> Calculating summary for subgroup TrainWithNoOutcome
#> Restricting to subgroup
#> Calculating summary for subgroup TestWithOutcome
#> Restricting to subgroup
#> Calculating summary for subgroup TestWithNoOutcome
#> Aggregating with labels and strata
#> Finished covariate summary @ 2025-02-17 17:02:54.266808
#> Time to calculate covariate summary: 0.847 secs
#> Run finished successfully.
#> Saving PlpResult
#> Creating directory to save model
#> plpResult saved to ..\/tmp/RtmpPJeNgk/plotDemographicSummary/2025-02-17-3\plpResult
#> runPlp time taken: 2.9 secs
plotDemographicSummary(plpResult)
# clean up
unlink(saveLoc, recursive = TRUE)
# }