### Install pminternal Package Source: https://github.com/stephenrho/pminternal/blob/main/README.md Install the pminternal package from CRAN or the development version from GitHub. ```r install.packages("pminternal") # cran # or devtools::install_github("stephenrho/pminternal") # development ``` -------------------------------- ### Get Prediction Stability Matrix Source: https://context7.com/stephenrho/pminternal/llms.txt Retrieves the prediction stability matrix without generating a plot. The matrix contains stability information for each bootstrap model. Requires fitting a model and validating it first. ```r stabil_matrix <- prediction_stability(val, plot = FALSE) dim(stabil_matrix) # n x (B+1) matrix ``` -------------------------------- ### Calibration Stability Plot with Custom Settings Source: https://context7.com/stephenrho/pminternal/llms.txt Generates a calibration stability plot with custom calibration settings, axis limits, and colors. Requires fitting a model and validating it first. ```r curves <- calibration_stability( val, calib_args = list(smooth = "gam", k = 10, eval = 100), xlim = c(0, 0.5), ylim = c(0, 0.5), col = "gray50" ) ``` -------------------------------- ### Basic Calibration Stability Plot Source: https://context7.com/stephenrho/pminternal/llms.txt Generates a calibration stability plot showing calibration curves from bootstrap models. Requires fitting a model and validating it first. ```r library(pminternal) # Fit model and validate set.seed(456) dat <- pmcalibration::sim_dat(N = 2000, a1 = -2, a3 = -.3) dat$LP <- NULL m1 <- glm(y ~ ., data = dat, family = "binomial") val <- validate(m1, method = "boot_optimism", B = 100) # Calibration stability plot curves <- calibration_stability(val) ``` -------------------------------- ### Calculate Binary Performance Scores Source: https://context7.com/stephenrho/pminternal/llms.txt Computes discrimination and calibration metrics for binary outcomes, with support for custom calibration curve settings. ```r library(pminternal) # Generate sample predictions and outcomes set.seed(123) p <- runif(100) y <- rbinom(length(p), 1, p) # Calculate performance scores scores <- score_binary(y = y, p = p) print(scores) ``` ```r scores_custom <- score_binary( y = y, p = p, calib_args = list( smooth = "gam", k = 10, transf = "logit", eval = seq(min(p), max(p), length.out = 100) ) ) ``` -------------------------------- ### Generate decision curve stability plots Source: https://context7.com/stephenrho/pminternal/llms.txt Visualize decision curve stability using dcurve_stability. Customize threshold ranges and aesthetics as needed. ```r # Decision curve stability plot dcurves <- dcurve_stability(val) # Custom threshold range dcurves <- dcurve_stability( val, thresholds = seq(0, 0.5, by = 0.01), col = "gray60" ) # Extract curve data for custom plotting print(head(dcurves[[1]])) # First element is apparent curve #> threshold net_benefit #> 1 0.00 0.1523 #> 2 0.01 0.1498 #> ... # Access all bootstrap curves for (i in 2:length(dcurves)) { # Process each bootstrap curve } ``` -------------------------------- ### Validate Prediction Model with Simple Bootstrap Source: https://context7.com/stephenrho/pminternal/llms.txt Performs internal validation using the simple bootstrap method. Ensure B is set to a recommended value (e.g., 200). ```r # Simple bootstrap method val_simple <- validate(fit = mod, method = "boot_simple", B = 200) ``` -------------------------------- ### Plot Calibration Curves Source: https://context7.com/stephenrho/pminternal/llms.txt Visualizes apparent and bias-corrected calibration curves from a validation object, optionally including confidence intervals. ```r library(pminternal) # Fit model and get predictions set.seed(456) dat <- pmcalibration::sim_dat(N = 2000, a1 = -2, a3 = -.3) dat$LP <- NULL m1 <- glm(y ~ x1 + x2, data = dat, family = "binomial") # Get prediction range for calibration curve evaluation p <- predict(m1, type = "response") p100 <- seq(min(p), max(p), length.out = 100) # Validate with calibration curve evaluation points val <- validate( m1, method = "cv_optimism", B = 10, calib_args = list(eval = p100) ) # Plot apparent vs bias-corrected calibration curves cal_data <- cal_plot(val) ``` ```r # With confidence intervals val_ci <- confint(val, level = 0.95, method = "shifted", R = 500) cal_data <- cal_plot(val_ci, plotci = "yes") ``` -------------------------------- ### Validate Prediction Model with 0.632 Bootstrap Source: https://context7.com/stephenrho/pminternal/llms.txt Applies the 0.632 bootstrap method for internal validation. Ensure B is set to a recommended value (e.g., 200). ```r # 0.632 bootstrap method val_632 <- validate(fit = mod, method = ".632", B = 200) ``` -------------------------------- ### Generate Prediction Instability Plot Source: https://github.com/stephenrho/pminternal/blob/main/README.md Creates a prediction (in)stability plot showing predictions from bootstrap models applied to the development data. Use 'smooth_bounds = TRUE' for smoothed confidence intervals. ```r prediction_stability(val, smooth_bounds = TRUE) ``` -------------------------------- ### get_stability Source: https://context7.com/stephenrho/pminternal/llms.txt Extracts the stability matrix from a validation or bootstrap object. ```APIDOC ## get_stability ### Description Extracts the stability matrix from a validation or bootstrap object. Returns predictions from the original model and all bootstrap models, along with the original binary outcome. ### Parameters - **val** (object) - Required - A validation or bootstrap object. ### Response - **stability** (matrix) - A matrix of n observations x (B+1) predictions. - **y** (vector) - The original binary outcome. ``` -------------------------------- ### Examine CII Distribution Source: https://context7.com/stephenrho/pminternal/llms.txt Provides a summary of the Classification Instability Index (CII) distribution, showing minimum, quartiles, median, mean, and maximum values. ```r summary(cii) ``` -------------------------------- ### Basic Prediction Stability Plot Source: https://context7.com/stephenrho/pminternal/llms.txt Generates a basic prediction stability plot with default 95% bounds. Requires fitting a model and validating it first. ```r library(pminternal) # Fit model and validate set.seed(456) dat <- pmcalibration::sim_dat(N = 2000, a1 = -2, a3 = -.3) dat$LP <- NULL m1 <- glm(y ~ ., data = dat, family = "binomial") val <- validate(m1, method = "boot_optimism", B = 200) # Basic prediction stability plot with 95% bounds prediction_stability(val) ``` -------------------------------- ### View Individual MAPE Values Source: https://context7.com/stephenrho/pminternal/llms.txt Displays the first few individual Mean Absolute Prediction Error (MAPE) values from the MAPE stability analysis result. ```r head(mape_result$individual_mape) ``` -------------------------------- ### summary.internal_validate Source: https://context7.com/stephenrho/pminternal/llms.txt Summarizes a validation object showing apparent, optimism, and bias-corrected estimates for performance measures. ```APIDOC ## summary.internal_validate ### Description Summarizes a validation object showing apparent, optimism, and bias-corrected estimates for all performance measures. If confidence intervals have been added via confint(), they are included in the output. ### Parameters - **val** (object) - Required - A validation object. ### Response - **summary** (data.frame) - A data frame containing apparent, optimism, corrected estimates, and confidence intervals if applicable. ``` -------------------------------- ### Perform Bootstrap Optimism Correction Source: https://context7.com/stephenrho/pminternal/llms.txt Calculates bias-corrected performance metrics using standard or .632 bootstrap methods. ```r result <- boot_optimism( data = dat, outcome = "y", model_fun = model_fun, pred_fun = pred_fun, method = "boot", B = 200 ) print(result) ``` ```r result_632 <- boot_optimism( data = dat, outcome = "y", model_fun = model_fun, pred_fun = pred_fun, method = ".632", B = 200 ) ``` -------------------------------- ### Validate GLM Model with Bootstrap Optimism Source: https://github.com/stephenrho/pminternal/blob/main/README.md Calculate bootstrap optimism corrected performance measures for a glm model. Requires the pminternal library and sample data. The B parameter controls the number of bootstrap replicates. ```r library(pminternal) # make some data set.seed(2345) n <- 800 p <- 10 X <- matrix(rnorm(n*p), nrow = n, ncol = p) LP <- -1 + apply(X[, 1:5], 1, sum) # first 5 variables predict outcome y <- rbinom(n, 1, plogis(LP)) dat <- data.frame(y, X) # fit a model mod <- glm(y ~ ., data = dat, family = "binomial") # calculate bootstrap optimism corrected performance measures (val <- validate(fit = mod, method = "boot_optimism", B = 100)) ``` -------------------------------- ### Validate Model with Bootstrap Optimism Source: https://github.com/stephenrho/pminternal/blob/main/README.md Performs bootstrap validation on a model using specified model and prediction functions. It calculates apparent, optimism, and corrected performance metrics. For reliable results, set B (number of bootstrap resamples) to 200 or higher. ```r (val <- validate(data = dat, outcome = "y", model_fun = lasso_fun, pred_fun = lasso_predict, method = "boot_optimism", B = 100)) #> It is recommended that B >= 200 for bootstrap validation #> apparent optimism corrected n #> C 0.856 0.0070 0.849 100 #> Brier 0.143 -0.0041 0.147 100 #> Intercept 0.080 0.0191 0.061 100 #> Slope 1.155 0.0449 1.110 100 #> Eavg 0.020 0.0013 0.019 100 #> E50 0.019 0.0026 0.017 100 #> E90 0.040 0.0021 0.038 100 #> Emax 0.044 0.0145 0.029 100 #> ECI 0.053 0.0087 0.044 100 ``` -------------------------------- ### Calculate Confidence Intervals for Validation Source: https://context7.com/stephenrho/pminternal/llms.txt Estimates confidence intervals for bias-corrected measures using shifted or two-stage bootstrap methods. ```r library(pminternal) # Create validation object first set.seed(456) dat <- pmcalibration::sim_dat(N = 2000, a1 = -2, a3 = -.3) dat$LP <- NULL m1 <- glm(y ~ ., data = dat, family = "binomial") val <- validate(m1, method = "boot_optimism", B = 200) # Add confidence intervals using shifted method (faster) val_with_ci <- confint(val, level = 0.95, method = "shifted", R = 1000) # Print summary with confidence intervals summary(val_with_ci) ``` ```r # Twostage method (more thorough but slower, R*B replicates) val_twostage <- confint(val, level = 0.95, method = "twostage", R = 100) # Get just the CIs without modifying original object ci_only <- confint(val, add = FALSE) print(ci_only$Corrected) ``` -------------------------------- ### Summarize internal validation results Source: https://context7.com/stephenrho/pminternal/llms.txt Summarize validation objects to view apparent, optimism, and bias-corrected estimates. Confidence intervals can be included if computed via confint(). ```r library(pminternal) # Fit model and validate set.seed(456) dat <- pmcalibration::sim_dat(N = 2000, a1 = -2, a3 = -.3) dat$LP <- NULL m1 <- glm(y ~ ., data = dat, family = "binomial") val <- validate(m1, method = "boot_optimism", B = 200) # Basic summary summary(val) #> apparent optimism corrected n #> C 0.7234 0.0052 0.7182 200 #> Brier 0.1856 -0.0031 0.1887 200 #> Intercept 0.0000 0.0098 -0.0098 200 #> Slope 1.0000 0.0312 0.9688 200 #> Eavg 0.0123 -0.0028 0.0151 200 #> E50 0.0098 -0.0021 0.0119 200 #> E90 0.0287 -0.0065 0.0352 200 #> Emax 0.0412 -0.0089 0.0501 200 #> ECI 0.0003 -0.0001 0.0004 200 # Summary with confidence intervals val_ci <- confint(val, level = 0.95, method = "shifted", R = 500) summary(val_ci) #> apparent optimism corrected n corrected_lower corrected_upper #> C 0.7234 0.0052 0.7182 200 0.6956 0.7401 #> Brier 0.1856 -0.0031 0.1887 200 0.1756 0.2021 #> ... # Store summary for further use val_summary <- summary(val) class(val_summary) #> [1] "internal_validatesummary" "data.frame" ``` -------------------------------- ### Prediction Stability Plot with Subset Source: https://context7.com/stephenrho/pminternal/llms.txt Generates a prediction stability plot using a random subset of the data, useful for large datasets. Requires fitting a model and validating it first. ```r stabil_data <- prediction_stability(val, subset = sample(1:nrow(dat), 500)) ``` -------------------------------- ### Calculate K-Fold Cross-Validation Source: https://context7.com/stephenrho/pminternal/llms.txt Computes bias-corrected scores via k-fold cross-validation, returning both optimism-corrected and average estimates. ```r library(pminternal) # Simulate data set.seed(456) dat <- pmcalibration::sim_dat(N = 1000, a1 = -2, a3 = -.3) dat$LP <- NULL # Define model and prediction functions model_fun <- function(data, ...) { glm(y ~ x1 + x2, data = data, family = "binomial") } pred_fun <- function(model, data, ...) { predict(model, newdata = data, type = "response") } # 10-fold cross-validation result <- crossval( data = dat, outcome = "y", model_fun = model_fun, pred_fun = pred_fun, k = 10 ) print(result) ``` -------------------------------- ### Generate Calibration Instability Plot Source: https://github.com/stephenrho/pminternal/blob/main/README.md Depicts the original calibration curve alongside calibration curves from bootstrap models. This plot helps assess the stability of the model's calibration performance. ```r calibration_stability(val) ``` -------------------------------- ### Fit GLM with Lasso Penalty Source: https://github.com/stephenrho/pminternal/blob/main/README.md This function fits a generalized linear model with a lasso penalty (alpha=1) to binomial family data. It uses cross-validation to find the optimal lambda. Requires the 'glmnet' package. ```r library(glmnet) #> Loading required package: Matrix #> Loaded glmnet 4.1-8 lasso_fun <- function(data, ...){ y <- data$y x <- as.matrix(data[, which(colnames(data) != "y")]) cv <- cv.glmnet(x=x, y=y, alpha=1, nfolds = 10, family="binomial") lambda <- cv$lambda.min glmnet(x=x, y=y, alpha = 1, lambda = lambda, family="binomial") } ``` -------------------------------- ### Validate Prediction Model with Parallel Processing Source: https://context7.com/stephenrho/pminternal/llms.txt Enables parallel processing for bootstrap validation to speed up computation. Specify the number of cores to use. ```r # Parallel processing for faster bootstrap validation val_parallel <- validate(fit = mod, method = "boot_optimism", B = 200, cores = 4) ``` -------------------------------- ### Basic MAPE Stability Plot Source: https://context7.com/stephenrho/pminternal/llms.txt Generates a Mean Absolute Prediction Error (MAPE) stability plot. Requires fitting a model and validating it first. ```r library(pminternal) # Fit model and validate set.seed(456) dat <- pmcalibration::sim_dat(N = 2000, a1 = -2, a3 = -.3) dat$LP <- NULL m1 <- glm(y ~ ., data = dat, family = "binomial") val <- validate(m1, method = "boot_optimism", B = 200) # MAPE stability plot mape_result <- mape_stability(val) ``` -------------------------------- ### Validate Prediction Model with Bootstrap Optimism Correction Source: https://context7.com/stephenrho/pminternal/llms.txt Performs internal validation using bootstrap optimism correction. Ensure B is set to a recommended value (e.g., 200) for reliable results. ```r library(pminternal) # Generate example data set.seed(2345) n <- 800 p <- 10 X <- matrix(rnorm(n * p), nrow = n, ncol = p) LP <- -1 + apply(X[, 1:5], 1, sum) y <- rbinom(n, 1, plogis(LP)) dat <- data.frame(y, X) # Fit a logistic regression model mod <- glm(y ~ ., data = dat, family = "binomial") # Bootstrap optimism correction (default method, B >= 200 recommended) val <- validate(fit = mod, method = "boot_optimism", B = 200) print(val) ``` -------------------------------- ### Classification Stability Plot at 40% Threshold Source: https://context7.com/stephenrho/pminternal/llms.txt Generates a classification stability plot showing the Classification Instability Index (CII) at a 40% risk threshold. Requires fitting a model and validating it first. ```r library(pminternal) # Fit model and validate set.seed(456) dat <- pmcalibration::sim_dat(N = 2000, a1 = -2, a3 = -.3) dat$LP <- NULL m1 <- glm(y ~ ., data = dat, family = "binomial") val <- validate(m1, method = "boot_optimism", B = 200) # Classification stability at 40% risk threshold cii <- classification_stability(val, threshold = 0.4) ``` -------------------------------- ### Standalone Bootstrap Optimism Calculation Source: https://context7.com/stephenrho/pminternal/llms.txt Calculates optimism and bias-corrected scores directly using bootstrap resampling. This function offers more control than the main validate() function and supports both standard and 0.632 bootstrap methods. ```r library(pminternal) # Simulate data set.seed(456) dat <- pmcalibration::sim_dat(N = 1000, a1 = -2, a3 = -.3) dat$LP <- NULL # Define model and prediction functions model_fun <- function(data, ...) { glm(y ~ x1 + x2, data = data, family = "binomial") } pred_fun <- function(model, data, ...) { predict(model, newdata = data, type = "response") } # Example usage of boot_optimism (assuming it's called elsewhere or for direct use) # Note: The actual call to boot_optimism is not provided in the source, only its definition context. ``` -------------------------------- ### Classification Stability Plot at 20% Threshold Source: https://context7.com/stephenrho/pminternal/llms.txt Generates a classification stability plot showing the Classification Instability Index (CII) at a 20% risk threshold. Requires fitting a model and validating it first. ```r cii <- classification_stability(val, threshold = 0.2) ``` -------------------------------- ### Generate MAPE Stability Plot Source: https://github.com/stephenrho/pminternal/blob/main/README.md Generates a MAPE (Mean Absolute Prediction Error) stability plot. This plot visualizes the difference between the predicted risk from the development model and each of the bootstrap models. ```r mape_stability(val) ``` -------------------------------- ### View Average MAPE Source: https://context7.com/stephenrho/pminternal/llms.txt Prints the average Mean Absolute Prediction Error (MAPE) across all observations from the MAPE stability analysis result. ```r print(mape_result$average_mape) ``` -------------------------------- ### Validate Prediction Model with Cross-Validation Source: https://context7.com/stephenrho/pminternal/llms.txt Conducts internal validation using k-fold cross-validation. Set B to the desired number of folds. ```r # Cross-validation with 10 folds val_cv <- validate(fit = mod, method = "cv_average", B = 10) ``` -------------------------------- ### Customize Calibration Plot Source: https://context7.com/stephenrho/pminternal/llms.txt Customize the appearance of a calibration plot using various arguments for colors, line types, and labels. ```r cal_plot( val, app_col = "blue", bc_col = "red", app_lty = 1, bc_lty = 2, xlab = "Predicted Probability", ylab = "Observed Proportion" ) ``` -------------------------------- ### Extract Calibration Data Source: https://context7.com/stephenrho/pminternal/llms.txt Extracts data from a calibration object for custom plotting, such as with ggplot2. ```r print(head(cal_data)) ``` -------------------------------- ### Extract stability matrix Source: https://context7.com/stephenrho/pminternal/llms.txt Retrieve the stability matrix from a validation object to analyze prediction variability across bootstrap resamples. ```r library(pminternal) # Fit model and validate set.seed(456) dat <- pmcalibration::sim_dat(N = 2000, a1 = -2, a3 = -.3) dat$LP <- NULL m1 <- glm(y ~ ., data = dat, family = "binomial") val <- validate(m1, method = "boot_optimism", B = 100) # Extract stability information stabil <- get_stability(val) # Stability matrix: n observations x (B+1) predictions dim(stabil$stability) #> [1] 2000 101 # First column is original model predictions head(stabil$stability[, 1]) # Bootstrap model predictions head(stabil$stability[, 2:5]) # Original outcome head(stabil$y) # Custom stability analysis orig_pred <- stabil$stability[, 1] boot_preds <- stabil$stability[, -1] # Calculate prediction variability per observation pred_sd <- apply(boot_preds, 1, sd) summary(pred_sd) # Identify patients with highly variable predictions high_var_patients <- which(pred_sd > quantile(pred_sd, 0.95)) ``` -------------------------------- ### Extract Calibration Curve Data Source: https://context7.com/stephenrho/pminternal/llms.txt Extracts calibration curve data from the calibration stability analysis. The result is a list where each element represents a curve (apparent + bootstrap). ```r print(length(curves)) # B+1 curves (1 apparent + B bootstrap) print(head(curves[[1]])) # First element is apparent curve ``` -------------------------------- ### Customized MAPE Stability Plot Source: https://context7.com/stephenrho/pminternal/llms.txt Customizes the appearance of the MAPE stability plot by adjusting colors, point shapes, sizes, and axis labels. Requires fitting a model and validating it first. ```r mape_stability( val, col = "darkred", pch = 19, cex = 0.8, xlab = "Estimated Risk", ylab = "Mean Absolute Prediction Error" ) ``` -------------------------------- ### Validate Model Using Custom LASSO Functions Source: https://context7.com/stephenrho/pminternal/llms.txt Validates a prediction model using user-defined functions for model fitting (LASSO) and prediction. This approach is useful for models not directly supported by the insight package. ```r # Validate with user-defined functions val <- validate( data = dat, outcome = "y", model_fun = lasso_fun, pred_fun = lasso_predict, method = "boot_optimism", B = 200 ) print(val) ``` -------------------------------- ### Predict using Lasso Model Source: https://github.com/stephenrho/pminternal/blob/main/README.md This function takes a fitted glmnet model and data to predict outcomes. It extracts the predictor variables and applies the model to generate response probabilities. Ensure the input data has the same structure as the training data. ```r lasso_predict <- function(model, data, ...){ y <- data$y x <- as.matrix(data[, which(colnames(data) != "y")]) predict(model, newx = x, type = "response")[,1] } ``` -------------------------------- ### Generate Classification Instability Plot Source: https://github.com/stephenrho/pminternal/blob/main/README.md Calculates and visualizes the Classification Instability Index (CII), which is the proportion of individuals changing predicted class based on a specified threshold across bootstrap models. Set the 'threshold' parameter to define the decision boundary. ```r classification_stability(val, threshold = .4) ``` -------------------------------- ### Customized Prediction Stability Plot Source: https://context7.com/stephenrho/pminternal/llms.txt Customizes the prediction stability plot by adjusting bounds, smoothing, colors, point sizes, and axis labels. Requires fitting a model and validating it first. ```r prediction_stability( val, bounds = 0.90, # 90% stability interval smooth_bounds = TRUE, col = "steelblue", cex = 0.3, xlab = "Development Model Predictions", ylab = "Bootstrap Model Predictions" ) ``` -------------------------------- ### Customized Classification Stability Plot Source: https://context7.com/stephenrho/pminternal/llms.txt Customizes the appearance of the classification stability plot by setting the threshold, colors, point shapes, sizes, and y-axis label. Requires fitting a model and validating it first. ```r classification_stability( val, threshold = 0.3, col = "purple", pch = 16, cex = 0.8, ylab = "Classification Instability" ) ``` -------------------------------- ### Generate Decision Curve Stability Plot Source: https://github.com/stephenrho/pminternal/blob/main/README.md Plots decision curves derived from the original and bootstrap models. This visualization helps in evaluating the clinical utility of the model across different threshold probabilities. ```r dcurve_stability(val) ``` -------------------------------- ### dcurve_stability Source: https://context7.com/stephenrho/pminternal/llms.txt Generates a decision curve stability plot and extracts curve data for custom plotting. ```APIDOC ## dcurve_stability ### Description Generates a decision curve stability plot and extracts curve data for custom plotting. ### Parameters - **val** (object) - Required - A validation object. - **thresholds** (numeric vector) - Optional - Custom threshold range (default: seq(0, 0.5, by = 0.01)). - **col** (string) - Optional - Color for the plot (default: "gray60"). ### Response - **dcurves** (list) - A list containing the apparent curve and bootstrap curves. ``` -------------------------------- ### Define Custom LASSO Model Function for Validation Source: https://context7.com/stephenrho/pminternal/llms.txt Defines a custom function to fit a LASSO regression model using glmnet, including internal cross-validation for lambda selection. This function is intended for use with the validate() function when models are not directly supported by the insight package. ```r library(pminternal) library(glmnet) # Define custom model function for LASSO regression lasso_fun <- function(data, ...) { y <- data$y x <- as.matrix(data[, which(colnames(data) != "y")]) # Cross-validation for lambda selection (part of model development) cv <- cv.glmnet(x = x, y = y, alpha = 1, nfolds = 10, family = "binomial") lambda <- cv$lambda.min # Fit final model with optimal lambda glmnet(x = x, y = y, alpha = 1, lambda = lambda, family = "binomial") } ``` -------------------------------- ### Decision Curve Stability Plot Source: https://context7.com/stephenrho/pminternal/llms.txt Generates a decision curve stability plot showing decision curves from bootstrap models evaluated on the original outcome. Requires fitting a model and validating it first. ```r library(pminternal) # Fit model and validate set.seed(456) dat <- pmcalibration::sim_dat(N = 2000, a1 = -2, a3 = -.3) dat$LP <- NULL m1 <- glm(y ~ ., data = dat, family = "binomial") val <- validate(m1, method = "boot_optimism", B = 100) ``` -------------------------------- ### Identify Patients with High Instability Source: https://context7.com/stephenrho/pminternal/llms.txt Identifies and counts the number of patients exhibiting high classification instability (CII > 0.2) based on the classification stability analysis. ```r high_instability <- which(cii > 0.2) print(length(high_instability)) ``` -------------------------------- ### Define Custom Prediction Function for LASSO Model Source: https://context7.com/stephenrho/pminternal/llms.txt Defines a custom function to generate predictions from a fitted LASSO model. This function is used in conjunction with a custom model function when validating models not directly supported by the insight package. ```r # Define custom prediction function lasso_predict <- function(model, data, ...) { y <- data$y x <- as.matrix(data[, which(colnames(data) != "y")]) predict(model, newx = x, type = "response")[, 1] } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.