Plotting
The package also includes basic plotting functions for easier visualization of the data, as well as for visualizing the resulting model and evaluating its performance. Below, the basic functionality of these functions will be demonstrated. Keep in mind, there are various input parameters available to customize the resulting plots according to individual needs. For more details on these parameters, please refer to the documentation. Some of the plotting functions may prompt additional instructions in the console based on the provided dataset. Following these instructions will generate the next plot.
Firstly, a simulated dataset will be created and then a model fitted.
Additionally, the real world dataset hba1c will be loaded
since real wold data can also be plotted.
library(metaROC)
set.seed(8)
control_sim = list(n_studies_min = 5, n_studies_max = 10,
n_subj_min = 20, n_subj_max = 500,
n_thresholds_min = 1, n_thresholds_max = 4,
thresholds_lower_bound = 5,
thresholds_upper_bound = 7,
true_preval_min = 0.1, true_preval_max = 0.3,
model = "stoye2024cloglog",
model_pars = list(beta11 = -38.2, beta12 = 10.26,
beta13 = -0.669,
beta21 = 3.516, beta22 = -0.306,
var_rand_H = 0.6561,
var_rand_D = 0.9216))
sim <- simulate_metaROC(type = "phaseII", n_sims = 5,
control = control_sim)
fitted_model <- fit_metaROC(data = sim$data[sim$data$replicate==5,], model = "stoye2024cloglog",
data_info = sim$data_info)
#> Hello and welcome to metaROC!
#> Requested model: stoye2024cloglog
#> This is a GLMM for the discrete Hazard for multiple thresholds.
#> See https://doi.org/10.1002/jrsm.1753 for more details.
#> Warning in fit_metaROC_stoye2024dGLMM(data = data, model = "cloglog", nAGQ =
#> nAGQ): NAs introduced by coercion
data("hba1c")Plotting Data
To plot either real-world or simulated data, simply provide the dataset to the “plot_data()” function. If real-world data is used, it has to include all the necessary columns also needed for model fitting. For simulated data, one can directly use the object returned by “simulate_metaROC()”. The function automatically detects whether the dataset is real-world event or simulated data. When real-world data is provided, the function generates plots of study-specific ROC curves. In contrast, simulated data plots include the true ROC curve alongside another plot depicting True Sensitivity-Specificity against Threshold curves.
First the hba1c dataset will be plotted:
plot_data(hba1c)
#> Real-world data: only study-specific ROC curves plotted.
As this is a real world dataset, each study specific is plotted without an underyling true ROC curve.
Now the simulated will be plotted. As explained earlier simply
providing the simulated dataset by simulate_metaROC() is
enough:
plot_data(sim, replicate = 5)
#> Press Enter to see the Sensitivity/Specificity plot against threshold...
Now the study specific ROC curve plot also includes the true ROC curve
as the dataset was rightfully flagged as being simulated. The output
also includes another plot, which appears upon inputing enter into the
console. This plot highlights the true sensitivity and specificity
values per threshold for a first investigation of which threshold might
be the optimal one.
Plotting a fitted model
Plotting serves as a valuable tool, especially for evaluation. While
sifting through numerous numbers can be tedious, appropriate plots can
provide the same information and contextualize it effectively. To
facilitate this, the “plot_evaluation” function was included. This
function is designed for a fitted model of class metaROC.
The function generates four plots in total: The first plot is similar to
the first plot of plot_data() when setting
studies=TRUE but includes the estimated ROC curve with its
confidence interval. It is followed by two Sensitivity-Specificity
against threshold plots: one using true values and another using
estimated values, allowing for coverage checks with confidence intervals
in both. Lastly, a Youden Index against threshold plot identifies the
optimal threshold according to the model under the specified Youden
weigth by youd_weight.
plot_model_fit(fitted_model, youd_weight = 0.6, studies = TRUE)
#> Press Enter to see the next plot...

#> Press Enter to see the next plot...

#> Press Enter to see the next plot...

While the function is primarily meant to help with model evaluation when info on the data generating process is provided, it still produces helpful plots if the model was fitted to real-world data. The plots then cannot show the True ROC curve aswell as the true sensitivity and specificity values. However, it still plots the estimated ROC curve as well as the estimated sensitivity and specificity values. Finally, it can still serve as a tool to find the optimal threshold estimated by the model depending on the weight assigned:
mod <- fit_metaROC(hba1c, model = "stoye2024cloglog")
#> Hello and welcome to metaROC!
#> Requested model: stoye2024cloglog
#> This is a GLMM for the discrete Hazard for multiple thresholds.
#> See https://doi.org/10.1002/jrsm.1753 for more details.
#> Warning in fit_metaROC_stoye2024dGLMM(data = data, model = "cloglog", nAGQ =
#> nAGQ): NAs introduced by coercion
plot_model_fit(mod, studies = TRUE)
#> The model was fitted on real-world data. Therefore simpler plots will be shown as info on the data generating process is unknown.
#> Press Enter to see the next plot...

#> Press Enter to see the next plot...

It should be noted: The plots might not look perfect in some edge cases and may not capture every detail of the model. They are mainly designed to help visualize model performance and make evaluation easier for users who aren’t as comfortable with coding.