### Install and Configure pmsampsize Source: https://context7.com/cran/pmsampsize/llms.txt Installation instructions and the general function signature for pmsampsize. ```r # Install from CRAN install.packages("pmsampsize") library(pmsampsize) # Basic usage structure pmsampsize( type, # "c" (continuous), "b" (binary), or "s" (survival) parameters, # Number of candidate predictor parameters rsquared, # For continuous: expected R-squared csrsquared, # For binary/survival: Cox-Snell R-squared nagrsquared, # For binary/survival: Nagelkerke's R-squared (alternative) cstatistic, # For binary: C-statistic to approximate R-squared shrinkage = 0.9,# Target shrinkage (default 0.9 = 10% shrinkage) prevalence, # For binary: outcome prevalence rate, # For survival: overall event rate timepoint, # For survival: prediction timepoint of interest meanfup, # For survival: mean follow-up time intercept, # For continuous: average outcome value sd, # For continuous: standard deviation of outcome mmoe = 1.1 # For continuous: multiplicative margin of error (default 10%) ) ``` -------------------------------- ### Complete Clinical Prediction Model Workflow Source: https://context7.com/cran/pmsampsize/llms.txt A comprehensive example demonstrating the end-to-end process of planning a study, calculating sample size based on C-statistic, and reviewing planning metrics. ```r library(pmsampsize) # Scenario: Planning a study to develop a prediction model for # 30-day mortality after cardiac surgery # Step 1: Gather information from literature review # - Existing model has C-statistic of 0.78 # - Expected mortality rate (prevalence) is 3% # - Planning to evaluate 15 candidate predictors # - Some predictors are categorical, estimating 30 total parameters # Step 2: Calculate required sample size mortality_model <- pmsampsize( type = "b", cstatistic = 0.78, parameters = 30, prevalence = 0.03, shrinkage = 0.9 ) # Step 3: Review results print(mortality_model) # Step 4: Extract key metrics for study planning cat("\n=== Study Planning Summary ===\n") cat("Minimum sample size:", mortality_model$sample_size, "patients\n") cat("Minimum events needed:", ceiling(mortality_model$events), "deaths\n") cat("Events per parameter:", mortality_model$EPP, "\n") cat("Expected shrinkage:", mortality_model$final_shrinkage, "\n") # Step 5: Check if sample size is feasible # With 3% mortality rate, need ~3333 patients for 100 events # If only 2000 patients available, consider: # - Reducing number of predictors # - Using penalized regression methods # - Extending recruitment period ``` -------------------------------- ### Use Nagelkerke's R-squared Source: https://context7.com/cran/pmsampsize/llms.txt Placeholder for using Nagelkerke's R-squared in binary and survival models. ```r library(pmsampsize) # Using Nagelkerke's R-squared instead of Cox-Snell R-squared ``` -------------------------------- ### pmsampsize Main Function Source: https://context7.com/cran/pmsampsize/llms.txt The core function to calculate minimum sample size requirements for prediction model development. It evaluates multiple criteria and returns the largest sample size needed. ```APIDOC ## Main Function: pmsampsize ### Description The core function that calculates minimum sample size requirements for prediction model development. It evaluates multiple criteria simultaneously and returns the largest sample size needed to satisfy all requirements, along with detailed output showing the breakdown by criterion. ### Method `pmsampsize()` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters (Function Arguments) - **type** (character) - Required - Type of outcome: "c" (continuous), "b" (binary), or "s" (survival). - **parameters** (numeric) - Required - Number of candidate predictor parameters. - **rsquared** (numeric) - Required for continuous type - Expected R-squared. - **csrsquared** (numeric) - Required for binary/survival type - Cox-Snell R-squared. - **nagrsquared** (numeric) - Optional for binary/survival type - Nagelkerke's R-squared (alternative to csrsquared). - **cstatistic** (numeric) - Required for binary type when csrsquared is not available - C-statistic to approximate R-squared. - **shrinkage** (numeric) - Optional - Target shrinkage (default 0.9 = 10% shrinkage). - **prevalence** (numeric) - Required for binary type - Outcome prevalence. - **rate** (numeric) - Required for survival type - Overall event rate. - **timepoint** (numeric) - Required for survival type - Prediction timepoint of interest. - **meanfup** (numeric) - Required for survival type - Mean follow-up time. - **intercept** (numeric) - Optional for continuous type - Average outcome value. - **sd** (numeric) - Optional for continuous type - Standard deviation of outcome. - **mmoe** (numeric) - Optional for continuous type - Multiplicative margin of error (default 1.1 = 10%). ### Request Example ```r # Install from CRAN install.packages("pmsampsize") library(pmsampsize) # Basic usage structure pmsampsize( type, # "c" (continuous), "b" (binary), or "s" (survival) parameters, # Number of candidate predictor parameters rsquared, # For continuous: expected R-squared csrsquared, # For binary/survival: Cox-Snell R-squared nagrsquared, # For binary/survival: Nagelkerke's R-squared (alternative) cstatistic, # For binary: C-statistic to approximate R-squared shrinkage = 0.9,# Target shrinkage (default 0.9 = 10% shrinkage) prevalence, # For binary: outcome prevalence rate, # For survival: overall event rate timepoint, # For survival: prediction timepoint of interest meanfup, # For survival: mean follow-up time intercept, # For continuous: average outcome value sd, # For continuous: standard deviation of outcome mmoe = 1.1 # For continuous: multiplicative margin of error (default 10%) ) ``` ### Response #### Success Response (200) Returns a data frame with sample size calculations based on different criteria, including the final minimum sample size required, shrinkage factor, number of parameters, R-squared values, and Events Per Predictor Parameter (EPP). #### Response Example ``` # Output: # NB: Assuming 0.05 acceptable difference in apparent & adjusted R-squared # NB: Assuming 0.05 margin of error in estimation of intercept # NB: Events per Predictor Parameter (EPP) assumes prevalence = 0.174 # # Samp_size Shrinkage Parameter CS_Rsq Max_Rsq Nag_Rsq EPP # Criteria 1 339 0.9 24 0.288 0.377 0.764 2.46 # Criteria 2 417 0.912 24 0.288 0.377 0.764 3.02 # Criteria 3 531 0.912 24 0.288 0.377 0.764 3.85 # Final 531 0.912 24 0.288 0.377 0.764 3.85 # # Minimum sample size required = 531, with 93 events and EPP = 3.85 ``` ``` -------------------------------- ### Access C-statistic Conversion Source: https://context7.com/cran/pmsampsize/llms.txt Demonstrates internal conversion of C-statistic to Cox-Snell R-squared. ```r # The function internally converts C-statistic to Cox-Snell R-squared result_cstat$rsquared # 0.3418 (approximated from C-statistic) ``` -------------------------------- ### Adjust Shrinkage Target Source: https://context7.com/cran/pmsampsize/llms.txt Compares sample size requirements based on different shrinkage targets to control overfitting. ```r library(pmsampsize) # Compare sample sizes with different shrinkage targets # Higher shrinkage = less overfitting = larger sample size needed # Default shrinkage of 0.9 (10% shrinkage acceptable) result_90 <- pmsampsize( type = "b", csrsquared = 0.288, parameters = 24, prevalence = 0.174, shrinkage = 0.9 ) # Stricter shrinkage of 0.95 (only 5% shrinkage acceptable) result_95 <- pmsampsize( type = "b", csrsquared = 0.288, parameters = 24, prevalence = 0.174, shrinkage = 0.95 ) # Compare results cat("Shrinkage 0.90: N =", result_90$sample_size, "\n") cat("Shrinkage 0.95: N =", result_95$sample_size, "\n") # Shrinkage 0.90: N = 531 # Shrinkage 0.95: N = 719 ``` -------------------------------- ### Binary Models Using C-statistic Source: https://context7.com/cran/pmsampsize/llms.txt Calculate sample size for binary outcome models using the C-statistic (AUC) when Cox-Snell R-squared is unavailable. ```APIDOC ## Binary Models Using C-statistic ### Description When Cox-Snell R-squared is not available from existing studies, use the C-statistic (AUC) instead. The function approximates R-squared using the method from Riley et al. (2020). ### Method `pmsampsize(type = "b", cstatistic, parameters, prevalence, ...)` ### Endpoint N/A (R function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters (Function Arguments) - **type** (character) - Must be set to "b" for binary outcomes. - **cstatistic** (numeric) - Required - C-statistic (AUC) from an existing model. - **parameters** (numeric) - Required - Number of candidate predictor parameters. - **prevalence** (numeric) - Required - Expected outcome prevalence. - **seed** (numeric) - Optional - Seed for reproducibility of R-squared approximation. - **shrinkage** (numeric) - Optional - Target shrinkage (default 0.9). ### Request Example ```r library(pmsampsize) # Example: Using C-statistic when R-squared is not reported # - 24 candidate predictor parameters # - Prevalence of 17.4% # - C-statistic of 0.89 from existing model result_cstat <- pmsampsize( type = "b", cstatistic = 0.89, parameters = 24, prevalence = 0.174, seed = 123456 # For reproducibility of R-squared approximation ) print(result_cstat) ``` ### Response #### Success Response (200) Returns a data frame with sample size calculations for binary outcomes using C-statistic, including minimum sample size, shrinkage, parameters, R-squared values, and EPP. #### Response Example ``` # Given input C-statistic = 0.89 & prevalence = 0.174 # Cox-Snell R-sq = 0.3418 # # Samp_size Shrinkage Parameter CS_Rsq Max_Rsq Nag_Rsq EPP # Criteria 1 262 0.9 24 0.3418 0.377 0.907 1.90 # Criteria 2 283 0.914 24 0.3418 0.377 0.907 2.05 # Criteria 3 531 0.914 24 0.3418 0.377 0.907 3.85 # Final 531 0.914 24 0.3418 0.377 0.907 3.85 # # Minimum sample size required = 531, with 93 events and EPP = 3.85 ``` ``` -------------------------------- ### Calculate Sample Size using Nagelkerke's R-squared Source: https://context7.com/cran/pmsampsize/llms.txt Uses Nagelkerke's R-squared as an input parameter for sample size calculation. The function internally converts this to Cox-Snell R-squared. ```r result_nagelkerke <- pmsampsize( type = "b", nagrsquared = 0.35, # Nagelkerke's R-squared from existing model parameters = 20, prevalence = 0.25 ) print(result_nagelkerke) # The function converts Nagelkerke to Cox-Snell internally # Output includes both metrics for reference result_nagelkerke$rsquared # Cox-Snell R-squared (converted) result_nagelkerke$nag_r2 # Nagelkerke R-squared (back-calculated) ``` -------------------------------- ### Calculate Sample Size Using C-statistic Source: https://context7.com/cran/pmsampsize/llms.txt Use the C-statistic to approximate R-squared when Cox-Snell R-squared is unavailable. ```r library(pmsampsize) # Example: Using C-statistic when R-squared is not reported # - 24 candidate predictor parameters # - Prevalence of 17.4% # - C-statistic of 0.89 from existing model result_cstat <- pmsampsize( type = "b", cstatistic = 0.89, parameters = 24, prevalence = 0.174, seed = 123456 # For reproducibility of R-squared approximation ) print(result_cstat) # Output: # Given input C-statistic = 0.89 & prevalence = 0.174 # Cox-Snell R-sq = 0.3418 # # Samp_size Shrinkage Parameter CS_Rsq Max_Rsq Nag_Rsq EPP # Criteria 1 262 0.9 24 0.3418 0.377 0.907 1.90 # Criteria 2 283 0.914 24 0.3418 0.377 0.907 2.05 # Criteria 3 531 0.914 24 0.3418 0.377 0.907 3.85 # Final 531 0.914 24 0.3418 0.377 0.907 3.85 ``` -------------------------------- ### Binary Outcome Models (Logistic Regression) Source: https://context7.com/cran/pmsampsize/llms.txt Calculate sample size for prediction models with binary outcomes using Cox-Snell R-squared. ```APIDOC ## Binary Outcome Models (Logistic Regression) ### Description Calculate sample size for prediction models with binary outcomes (e.g., disease presence/absence, treatment response). Requires outcome prevalence and an R-squared estimate from existing models. ### Method `pmsampsize(type = "b", csrsquared, parameters, prevalence, ...)` ### Endpoint N/A (R function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters (Function Arguments) - **type** (character) - Must be set to "b" for binary outcomes. - **csrsquared** (numeric) - Required - Cox-Snell R-squared from an existing model. - **parameters** (numeric) - Required - Number of candidate predictor parameters. - **prevalence** (numeric) - Required - Expected outcome prevalence. - **shrinkage** (numeric) - Optional - Target shrinkage (default 0.9). - **seed** (numeric) - Optional - Seed for reproducibility if using C-statistic approximation. ### Request Example ```r library(pmsampsize) # Example: Developing a logistic prediction model for a binary outcome # - 24 candidate predictor parameters # - Prevalence of 17.4% # - Cox-Snell R-squared of 0.288 from an existing model result_binary <- pmsampsize( type = "b", csrsquared = 0.288, parameters = 24, prevalence = 0.174 ) print(result_binary) ``` ### Response #### Success Response (200) Returns a data frame with sample size calculations for binary outcomes, including minimum sample size, shrinkage, parameters, R-squared values, and EPP. #### Response Example ``` # Output: # NB: Assuming 0.05 acceptable difference in apparent & adjusted R-squared # NB: Assuming 0.05 margin of error in estimation of intercept # NB: Events per Predictor Parameter (EPP) assumes prevalence = 0.174 # # Samp_size Shrinkage Parameter CS_Rsq Max_Rsq Nag_Rsq EPP # Criteria 1 339 0.9 24 0.288 0.377 0.764 2.46 # Criteria 2 417 0.912 24 0.288 0.377 0.764 3.02 # Criteria 3 531 0.912 24 0.288 0.377 0.764 3.85 # Final 531 0.912 24 0.288 0.377 0.764 3.85 # # Minimum sample size required = 531, with 93 events and EPP = 3.85 # Access individual results result_binary$sample_size # 531 result_binary$events # 92.394 (rounded to 93) result_binary$EPP # 3.85 result_binary$nag_r2 # Nagelkerke R-squared ``` ``` -------------------------------- ### Calculate Continuous Outcome Sample Size Source: https://context7.com/cran/pmsampsize/llms.txt Estimates sample size for linear regression prediction models. ```r library(pmsampsize) # Example: Developing a linear prediction model for FEV1 (lung function) # - 25 candidate predictor parameters # - R-squared of 0.2 from existing model # - Mean FEV1 of 1.9 L # - Standard deviation of 0.6 L result_continuous <- pmsampsize( type = "c", rsquared = 0.2, parameters = 25, intercept = 1.9, sd = 0.6 ) print(result_continuous) # Output: # NB: Assuming 0.05 acceptable difference in apparent & adjusted R-squared # NB: Assuming MMOE <= 1.1 in estimation of intercept & residual standard deviation # SPP - Subjects per Predictor Parameter # # Samp_size Shrinkage Parameter Rsq SPP # Criteria 1 918 0.900 25 0.2 36.72 # Criteria 2 401 0.976 25 0.2 16.04 # Criteria 3 259 0.985 25 0.2 10.36 # Criteria 4* 918 0.900 25 0.2 36.72 # Final 918 0.900 25 0.2 36.72 # # Minimum sample size required = 918 # # * 95% CI for intercept = (1.77, 2.03), for sample size n = 918 # Access individual components result_continuous$sample_size # 918 result_continuous$SPP # 36.72 (Subjects per Predictor Parameter) result_continuous$int_lci # 1.77 (lower 95% CI for intercept) result_continuous$int_uci # 2.03 (upper 95% CI for intercept) ``` -------------------------------- ### Calculate Survival Outcome Sample Size Source: https://context7.com/cran/pmsampsize/llms.txt Estimates sample size for time-to-event models using Cox regression parameters. ```r library(pmsampsize) # Example: Developing a Cox prediction model for survival outcome # - 30 candidate predictor parameters # - Cox-Snell R-squared of 0.051 from existing model # - Event rate of 0.065 per year # - Prediction at 2-year timepoint # - Mean follow-up of 2.07 years result_survival <- pmsampsize( type = "s", csrsquared = 0.051, parameters = 30, rate = 0.065, timepoint = 2, meanfup = 2.07 ) print(result_survival) # Output: # NB: Assuming 0.05 acceptable difference in apparent & adjusted R-squared # NB: Assuming 0.05 margin of error in estimation of overall risk at time point = 2 # NB: Events per Predictor Parameter (EPP) assumes overall event rate = 0.065 # # Samp_size Shrinkage Parameter CS_Rsq Max_Rsq Nag_Rsq EPP # Criteria 1 1073 0.9 30 0.051 0.499 0.102 4.81 # Criteria 2 3014 0.965 30 0.051 0.499 0.102 13.51 # Criteria 3 * 3014 0.965 30 0.051 0.499 0.102 13.51 # Final SS 3014 0.965 30 0.051 0.499 0.102 13.51 # # Minimum sample size required = 3014, # corresponding to 6238.98 person-time of follow-up, with 406 outcome events # assuming overall event rate = 0.065 and EPP = 13.51 # # * 95% CI for overall risk = (0.109, 0.148), for true value of 0.122 # Access detailed results result_survival$sample_size # 3014 result_survival$events # 405.6846 result_survival$EPP # 13.51 result_survival$tot_per_yrs_final # 6238.98 person-time result_survival$int_cuminc # 0.122 (true cumulative incidence at timepoint) result_survival$int_lci # 0.109 (lower 95% CI) result_survival$int_uci # 0.148 (upper 95% CI) ``` -------------------------------- ### Calculate Sample Size for Binary Outcomes Source: https://context7.com/cran/pmsampsize/llms.txt Calculate required sample size for logistic regression models using prevalence and Cox-Snell R-squared. ```r library(pmsampsize) # Example: Developing a logistic prediction model for a binary outcome # - 24 candidate predictor parameters # - Prevalence of 17.4% expected # - Cox-Snell R-squared of 0.288 from an existing model result_binary <- pmsampsize( type = "b", csrsquared = 0.288, parameters = 24, prevalence = 0.174 ) print(result_binary) # Output: # NB: Assuming 0.05 acceptable difference in apparent & adjusted R-squared # NB: Assuming 0.05 margin of error in estimation of intercept # NB: Events per Predictor Parameter (EPP) assumes prevalence = 0.174 # # Samp_size Shrinkage Parameter CS_Rsq Max_Rsq Nag_Rsq EPP # Criteria 1 339 0.9 24 0.288 0.377 0.764 2.46 # Criteria 2 417 0.912 24 0.288 0.377 0.764 3.02 # Criteria 3 531 0.912 24 0.288 0.377 0.764 3.85 # Final 531 0.912 24 0.288 0.377 0.764 3.85 # # Minimum sample size required = 531, with 93 events and EPP = 3.85 # Access individual results result_binary$sample_size # 531 result_binary$events # 92.394 (rounded to 93) result_binary$EPP # 3.85 result_binary$nag_r2 # Nagelkerke R-squared ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.