### Install clinfun package Source: https://context7.com/veseshan/clinfun/llms.txt Instructions for installing the package from CRAN or the development version from GitHub. ```r # Install from CRAN install.packages("clinfun") # Or install development version from GitHub # install.packages("devtools") devtools::install_github("veseshan/clinfun") ``` -------------------------------- ### Install clinfun from GitHub Source: https://github.com/veseshan/clinfun/blob/main/Readme.md Use this command to install the development version of the package directly from GitHub using devtools. ```r # install.packages("devtools") devtools::install_github("veseshan/clinfun") ``` -------------------------------- ### Install clinfun from CRAN Source: https://github.com/veseshan/clinfun/blob/main/Readme.md Use this command to install the stable version of the package from the CRAN repository. ```r install.packages("clinfun") ``` -------------------------------- ### Load clinfun library Source: https://context7.com/veseshan/clinfun/llms.txt Load the package into the R environment. ```r library(clinfun) ``` -------------------------------- ### Create Futility Monitoring Stopping Rules Source: https://context7.com/veseshan/clinfun/llms.txt Creates stopping boundaries for futility monitoring in single-stage Phase II designs using futilbdry. ```r library(clinfun) # Create futility stopping rule for a single-stage design: # - Stop if response rate appears below 25% (rLo) # - Target response rate is 45% (rHi) # - Monitor at every 5 patients up to 50 futility_rule <- futilbdry( rLo = 0.25, # null response rate rHi = 0.45, # alternative response rate n = seq(5, 50, by = 5), # monitoring schedule size = 0.1, # Type I error power = 0.9 # power requirement ) print(futility_rule) ``` -------------------------------- ### ph2simon - Simon's Two-Stage Phase II Design Source: https://context7.com/veseshan/clinfun/llms.txt Calculates optimal and minimax two-stage Phase II designs using Simon's methodology. ```APIDOC ## ph2simon ### Description Calculates optimal and minimax two-stage Phase II designs using Simon's methodology. The function determines sample sizes and response thresholds that minimize either expected sample size (optimal) or maximum sample size (minimax) while controlling Type I and Type II error rates. ### Parameters #### Arguments - **pu** (numeric) - Required - Unacceptable response rate - **pa** (numeric) - Required - Desirable response rate - **ep1** (numeric) - Required - Type I error rate - **ep2** (numeric) - Required - Type II error rate ### Request Example ph2simon(pu = 0.05, pa = 0.2, ep1 = 0.1, ep2 = 0.1) ### Response #### Success Response (200) - **r1** (integer) - Stage 1 response threshold - **n1** (integer) - Stage 1 sample size - **r** (integer) - Overall response threshold - **n** (integer) - Total sample size - **EN(p0)** (numeric) - Expected sample size under null - **PET(p0)** (numeric) - Probability of early termination under null ``` -------------------------------- ### Calculate Simon's Two-Stage Phase II Design Source: https://context7.com/veseshan/clinfun/llms.txt Determine sample sizes and response thresholds for two-stage trials using Simon's methodology. ```r library(clinfun) # Design a two-stage trial where: # - 5% response rate is unacceptable (pu) # - 20% response rate is desirable (pa) # - Type I error (ep1) = 10% # - Type II error (ep2) = 10% trial <- ph2simon(pu = 0.05, pa = 0.2, ep1 = 0.1, ep2 = 0.1) # Print the optimal and minimax designs print(trial) #> Simon 2-stage Phase II design #> #> Unacceptable response rate: 0.05 #> Desirable response rate: 0.2 #> Error rates: alpha = 0.1 ; beta = 0.1 #> #> r1 n1 r n EN(p0) PET(p0) #> Optimal 0 13 3 37 22.72 0.513 #> Minimax 0 18 3 32 25.51 0.397 # Plot the design space showing optimal (O) and minimax (M) designs plot(trial) # Get admissible designs (compromise between optimal and minimax) twostage.admissible(trial) #> r1 n1 r n EN PET qLo qHi #> Minimax 0 18 3 32 25.51 0.397 0.00 0.08 #> 0 15 3 33 24.27 0.463 0.08 0.17 #> 0 14 3 35 23.64 0.488 0.17 0.57 #> Optimal 0 13 3 37 22.72 0.513 0.57 1.00 ``` -------------------------------- ### Calculate sample sizes with fe.ssize Source: https://github.com/veseshan/clinfun/blob/main/Readme.md Calculates CPS and Fisher's exact sample sizes with power estimates for specified response rates. ```r library(clinfun) fe.ssize(p1 = .8, p2 = .2, alpha=0.05, power=0.8) ``` -------------------------------- ### Compute Toxicity Monitoring Stopping Rules Source: https://context7.com/veseshan/clinfun/llms.txt Computes continuous stopping boundaries for toxicity monitoring using toxbdry. ```r library(clinfun) # Create toxicity stopping rule: # - Stop if toxicity rate appears to exceed 35% (pHi) # - Acceptable toxicity rate is 20% (pLo) # - Monitor at 20, 40, 60, and 75 patients tox_rule <- toxbdry( pLo = 0.2, # acceptable toxicity rate pHi = 0.35, # unacceptable toxicity rate n = c(20, 40, 60, 75), # monitoring times cP0 = 0.1, # Type I error (false positive) cP1 = 0.9 # Power to detect high toxicity ) print(tox_rule) # Continuous monitoring example (every patient from 2 to 30) continuous_rule <- toxbdry(pLo = 0.1, pHi = 0.3, n = 2:30) print(continuous_rule) ``` -------------------------------- ### Perform Statistical Inference After Two-Stage Trial Source: https://context7.com/veseshan/clinfun/llms.txt Calculate p-values, UMVUE estimates, and confidence intervals for completed two-stage trials. ```r library(clinfun) # After completing a two-stage trial with: # - r1=0, n1=18 (stage 1: stop if 0 responses in 18 patients) # - r=3, n=32 (overall: recommend if >3 responses in 32 patients) # Observed: x=5 responses total result <- twostage.inference( x = 5, # observed responses r1 = 0, # stage 1 threshold n1 = 18, # stage 1 sample size n = 32, # total sample size pu = 0.05, # null hypothesis response rate alpha = 0.1 ) print(result) #> UMVUE: 0.1563 #> p-value: 0.0146 #> 80% CI: (0.0741, 0.2615) ``` -------------------------------- ### Calculate Single-Stage Phase II Design Source: https://context7.com/veseshan/clinfun/llms.txt Compute exact single-stage designs for scenarios where two-stage designs are impractical. ```r library(clinfun) # Design a single-stage trial where: # - 40% response rate is unacceptable # - 60% response rate is desirable # - Type I error = 10% # - Type II error = 10% design <- ph2single(pu = 0.4, pa = 0.6, ep1 = 0.1, ep2 = 0.1) print(design) #> n r Type I Type II #> 1 41 20 0.097449 0.09701686 #> 2 46 23 0.094047 0.08432963 #> 3 51 26 0.092067 0.07477155 #> 4 56 29 0.091147 0.06730206 #> 5 61 32 0.091016 0.06129671 # Interpretation: Enroll n=41 patients, treatment is recommended if >20 responses ``` -------------------------------- ### futilbdry - Futility Monitoring Stopping Rule Source: https://context7.com/veseshan/clinfun/llms.txt Creates stopping boundaries for futility monitoring in single-stage Phase II designs. ```APIDOC ## futilbdry ### Description Creates stopping boundaries for futility monitoring in single-stage Phase II designs. ### Method `futilbdry(rLo, rHi, n, size, power)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **rLo** (numeric) - Null response rate (lower bound for efficacy). * **rHi** (numeric) - Alternative response rate (target efficacy). * **n** (numeric vector) - Sample sizes at which to monitor. * **size** (numeric) - Type I error rate (alpha). * **power** (numeric) - Desired power (1 - beta). ### Request Example ```r library(clinfun) futility_rule <- futilbdry( rLo = 0.25, rHi = 0.45, n = seq(5, 50, by = 5), size = 0.1, power = 0.9 ) print(futility_rule) ``` ### Response #### Success Response (200) Returns a data frame with monitoring schedule, futility boundary, and probabilities of stopping or effective rates at each monitoring point. #### Response Example ``` Futility boundary n bdry pstop(rLo) peffective(rLo) pstop(rHi) peffective(rHi) 5 -1 0.000 1.000 0.000 1.000 10 1 0.244 0.756 0.025 0.975 15 3 0.398 0.602 0.054 0.946 ... ``` ``` -------------------------------- ### ph2single - Single-Stage Phase II Design Source: https://context7.com/veseshan/clinfun/llms.txt Calculates exact single-stage Phase II designs for clinical trials. ```APIDOC ## ph2single ### Description Calculates exact single-stage Phase II designs when two-stage designs are not practical. ### Parameters #### Arguments - **pu** (numeric) - Required - Unacceptable response rate - **pa** (numeric) - Required - Desirable response rate - **ep1** (numeric) - Required - Type I error rate - **ep2** (numeric) - Required - Type II error rate ### Request Example ph2single(pu = 0.4, pa = 0.6, ep1 = 0.1, ep2 = 0.1) ### Response #### Success Response (200) - **n** (integer) - Sample size - **r** (integer) - Response threshold - **Type I** (numeric) - Actual Type I error - **Type II** (numeric) - Actual Type II error ``` -------------------------------- ### aucVardiTest - Compare Growth Curves Source: https://context7.com/veseshan/clinfun/llms.txt Performs two-sample tests for comparing growth curves using the area under the curve (AUC) method. ```APIDOC ## aucVardiTest ### Description Compares growth curves between two groups using area under the curve (AUC) statistics. ### Method `aucVardiTest` ### Endpoint None (function call) ### Parameters #### Path Parameters None #### Query Parameters - **y** (numeric vector) - The response variable (e.g., tumor size). - **time** (numeric vector) - The time points at which measurements were taken. - **group** (integer vector) - The group indicator for each observation (e.g., 1 for control, 2 for treatment). ### Request Example ```r library(clinfun) # Example data set.seed(111) time <- rep(c(0, 7, 14, 21, 28), each = 10) control <- 100 * exp(0.05 * time) + rnorm(50, sd = 10) treatment <- 100 * exp(0.03 * time) + rnorm(50, sd = 10) tumor_size <- c(control, treatment) group <- rep(1:2, each = 50) time_all <- rep(time, 2) # Test for difference in growth curves result <- aucVardiTest( y = tumor_size, time = time_all, group = group ) print(result) ``` ### Response #### Success Response (200) - **AUC Group 1** (numeric) - The calculated area under the curve for group 1. - **AUC Group 2** (numeric) - The calculated area under the curve for group 2. - **Z** (numeric) - The Z-statistic for the test. - **p-value** (numeric) - The p-value associated with the Z-statistic. #### Response Example ``` Two-sample test for growth curves AUC Group 1: 3245.6 AUC Group 2: 2876.3 Z = 2.34, p-value = 0.019 ``` ``` -------------------------------- ### Minimum Detectable Response Rate Difference (mdrr) Source: https://context7.com/veseshan/clinfun/llms.txt Computes minimum detectable response rates for marker-stratified designs. ```APIDOC ## mdrr - Minimum Detectable Response Rate Difference ### Description Computes minimum detectable response rates for marker-stratified designs. ### Parameters #### Request Body - **n** (numeric) - Required - Total sample size. - **cprob** (numeric) - Required - Proportion of marker-positive subjects. - **presp** (numeric) - Required - Overall response probability. - **alpha** (numeric) - Optional - Significance level (default is 0.05). - **power** (numeric) - Optional - Statistical power (default is 0.8). ### Response #### Success Response (200) - **result** (list) - A list containing the minimum detectable response rates for marker-positive and marker-negative subjects. ### Request Example ```r library(clinfun) result <- mdrr( n = 200, cprob = 0.3, presp = 0.4, alpha = 0.05, power = 0.8 ) print(result) ``` ### Response Example ``` Minimum detectable response rates P(response | marker+): 0.589 P(response | marker-): 0.319 ``` ``` -------------------------------- ### Design Group Sequential Trial for Binary Outcomes Source: https://context7.com/veseshan/clinfun/llms.txt Calculate sample sizes and boundaries for group sequential designs with binary endpoints. ```r library(clinfun) # Design a 4-look group sequential trial for binary outcomes ``` -------------------------------- ### twostage.inference - Statistical Inference After Two-Stage Trial Source: https://context7.com/veseshan/clinfun/llms.txt Calculates p-values, UMVUE estimates, and confidence intervals for completed two-stage trials. ```APIDOC ## twostage.inference ### Description Calculates p-values, UMVUE estimates, and confidence intervals for completed two-stage trials. ### Parameters #### Arguments - **x** (integer) - Required - Observed responses - **r1** (integer) - Required - Stage 1 threshold - **n1** (integer) - Required - Stage 1 sample size - **n** (integer) - Required - Total sample size - **pu** (numeric) - Required - Null hypothesis response rate - **alpha** (numeric) - Required - Significance level ### Response #### Success Response (200) - **UMVUE** (numeric) - Uniformly Minimum Variance Unbiased Estimator - **p-value** (numeric) - Calculated p-value - **CI** (numeric) - Confidence interval ``` -------------------------------- ### toxbdry - Toxicity Monitoring Stopping Rule Source: https://context7.com/veseshan/clinfun/llms.txt Computes continuous stopping boundaries for toxicity monitoring during clinical trials. ```APIDOC ## toxbdry ### Description Computes continuous stopping boundaries for toxicity monitoring during clinical trials. ### Method `toxbdry(pLo, pHi, n, cP0, cP1)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **pLo** (numeric) - Acceptable toxicity rate under the null hypothesis. * **pHi** (numeric) - Unacceptable toxicity rate under the alternative hypothesis. * **n** (numeric vector) - Sample sizes at which to monitor toxicity. * **cP0** (numeric) - Type I error rate (false positive rate) for stopping early for toxicity. * **cP1** (numeric) - Power to detect high toxicity (1 - Type II error rate). ### Request Example ```r library(clinfun) tox_rule <- toxbdry( pLo = 0.2, pHi = 0.35, n = c(20, 40, 60, 75), cP0 = 0.1, cP1 = 0.9 ) print(tox_rule) # Continuous monitoring example (every patient from 2 to 30) continuous_rule <- toxbdry(pLo = 0.1, pHi = 0.3, n = 2:30) print(continuous_rule) ``` ### Response #### Success Response (200) Returns a matrix with columns for sample size (n), lower boundary, and upper boundary for toxicity. #### Response Example ``` Toxicity boundary with cP(0.2) <= 0.1 and cP(0.35) >= 0.9 n looks lo.bdry hi.bdry [1,] 20 5 6 [2,] 40 11 12 [3,] 60 17 18 [4,] 75 22 23 Stop trial if number of toxicities exceeds boundary ``` ``` -------------------------------- ### gsdesign.binomial - Group Sequential Design for Binomial Outcomes Source: https://context7.com/veseshan/clinfun/llms.txt Calculates sample sizes and boundaries for group sequential trials with binomial outcomes (e.g., response rates). ```APIDOC ## gsdesign.binomial ### Description Calculates sample sizes and boundaries for group sequential trials with binomial outcomes. ### Method `gsdesign.binomial(ifrac, pC, pE, sig.level, power, delta.eb, delta.fb, alternative)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **ifrac** (numeric vector) - Information fractions at which to perform interim analyses. * **pC** (numeric) - Response rate in the control arm. * **pE** (numeric) - Response rate in the experimental arm. * **sig.level** (numeric) - Significance level (Type I error rate). * **power** (numeric) - Desired power of the trial. * **delta.eb** (numeric) - Efficacy boundary parameter (e.g., O'Brien-Fleming). * **delta.fb** (numeric) - Futility boundary parameter (e.g., O'Brien-Fleming). * **alternative** (character) - Type of alternative hypothesis ('two.sided', 'less', 'greater'). ### Request Example ```r library(clinfun) design <- gsdesign.binomial( ifrac = c(0.25, 0.5, 0.75, 1.0), pC = 0.2, pE = 0.35, sig.level = 0.05, power = 0.8, delta.eb = 0.5, delta.fb = 0.5, alternative = "two.sided" ) print(design) ``` ### Response #### Success Response (200) Returns a design object containing information fractions, efficacy boundaries, futility boundaries, and sample size per arm. #### Response Example ``` Group sequential design Information fraction: 0.25 0.5 0.75 1 Efficacy boundary: 4.049 2.863 2.338 2.025 Futility boundary: 0.000 0.000 0.707 2.025 Sample size per arm: 112 ``` ``` -------------------------------- ### Calculate Operating Characteristics of Two-Stage Boundary Source: https://context7.com/veseshan/clinfun/llms.txt Determine the operating characteristics for a specific two-stage design boundary. ```r library(clinfun) # Calculate operating characteristics for a specific design oc <- oc.twostage.bdry( pu = 0.2, # unacceptable response rate pa = 0.4, # desirable response rate r1 = 3, # stage 1 response threshold n1 = 19, # stage 1 sample size r = 15, # overall response threshold n = 54 # total sample size ) print(oc) #> Type I Type II PET(p0) EN(p0) #> 0.04895 0.09982 0.58969 33.63 ``` -------------------------------- ### Perform Permutation Log-Rank Test (permlogrank) Source: https://context7.com/veseshan/clinfun/llms.txt The permlogrank function performs a log-rank test for survival comparisons, utilizing permutation reference distributions suitable for small samples. It requires survival objects and the number of permutations. ```r library(clinfun) library(survival) # Small sample survival comparison set.seed(456) time <- c(rexp(15, 0.1), rexp(15, 0.2)) # survival times status <- sample(0:1, 30, replace = TRUE) # censoring status group <- rep(1:2, each = 15) # treatment groups # Permutation log-rank test result <- permlogrank( Surv(time, status) ~ group, nperm = 5000 ) print(result) #> Permutation log-rank test #> #> Chi-square = 2.45, p-value = 0.124 #> (based on 5000 permutations) ``` -------------------------------- ### Plot Survival Quantiles with Cox Model Source: https://context7.com/veseshan/clinfun/llms.txt Plots survival time quantile curves as a function of covariates using a fitted Cox proportional hazards model. Requires the survival and clinfun packages. ```r library(clinfun) library(survival) # Fit Cox model data(pbc, package = "survival") pbc_subset <- subset(pbc, trt > 0 & copper > 0) cox_fit <- coxph( Surv(time, status == 2) ~ trt + log(copper), data = pbc_subset ) # Plot survival time vs covariate plot(log(pbc_subset$copper), pbc_subset$time, pch = c("o", "x")[1 + (pbc_subset$status == 2)], xlab = "log(Copper)", ylab = "Survival Time (days)", main = "Median Survival by Copper Level") # Add median survival quantile curve coxphQuantile(cox_fit, xrange = c(2.5, 6), p = 0.5, whichx = 2, otherx = 1) # Add 75th percentile curve in red coxphQuantile(cox_fit, xrange = c(2.5, 6), p = 0.75, whichx = 2, otherx = 1, col = 2) ``` -------------------------------- ### Compare ROC Curves (roc.area.test) Source: https://context7.com/veseshan/clinfun/llms.txt Tests for equality of areas under multiple ROC curves using DeLong's method. ```APIDOC ## roc.area.test - Compare ROC Curves ### Description Tests for equality of areas under multiple ROC curves using DeLong's method. ### Parameters #### Request Body - **markers** (matrix or data frame) - Required - A matrix or data frame where columns represent different markers and rows correspond to subjects. - **status** (vector) - Required - Vector of true status (0 for negative, 1 for positive). ### Response #### Success Response (200) - **result** (list) - A list containing the areas under the curve (AUCs) for each marker, their standard errors, and the results of the statistical test for equality of AUCs (Chi-square statistic, degrees of freedom, and p-value). ### Request Example ```r library(clinfun) set.seed(101) status <- rep(0:1, each = 75) marker_x <- rnorm(150) + 0.8 * status marker_y <- rnorm(150) + 1.2 * status marker_z <- rnorm(150) + 1.0 * status result <- roc.area.test( markers = cbind(marker_x, marker_y, marker_z), status = status ) print(result) ``` ### Response Example ``` Areas under the curve: marker_x marker_y marker_z Area 0.7142 0.8156 0.7623 SE 0.0423 0.0356 0.0391 Test for equality of AUCs: Chi-square = 4.82, df = 2, p-value = 0.0898 ``` ``` -------------------------------- ### fe.ssize - Fisher's Exact Sample Size Source: https://context7.com/veseshan/clinfun/llms.txt Calculates sample sizes based on Fisher's exact test for comparing two proportions. ```APIDOC ## fe.ssize ### Description Calculates sample sizes based on Fisher's exact test for comparing two proportions. ### Method `fe.ssize(p1, p2, alpha, power, r)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **p1** (numeric) - Proportion in group 1. * **p2** (numeric) - Proportion in group 2. * **alpha** (numeric) - Significance level (Type I error rate). * **power** (numeric) - Desired power of the test. * **r** (numeric) - Ratio of sample sizes between group 2 and group 1 (e.g., 1 for 1:1 randomization, 2 for 2:1). ### Request Example ```r library(clinfun) result <- fe.ssize( p1 = 0.2, p2 = 0.3, alpha = 0.05, power = 0.8, r = 1 ) print(result) # With unequal allocation (2:1 ratio) fe.ssize(p1 = 0.2, p2 = 0.35, alpha = 0.05, power = 0.9, r = 2) ``` ### Response #### Success Response (200) Returns a data frame with calculated sample sizes per group and the corresponding exact power. #### Response Example ``` Group 1 Group 2 Exact Power CPS 294 294 0.8080441 Fisher Exact 291 291 0.8006813 ``` ``` -------------------------------- ### Compute Minimum Detectable Response Rate Difference (mdrr) Source: https://context7.com/veseshan/clinfun/llms.txt mdrr computes minimum detectable response rates for marker-stratified designs. It requires the total sample size, proportion of marker-positive individuals, overall response probability, alpha, and power. ```r library(clinfun) # What response rates can be detected by marker status? # Given: n=200, 30% marker positive, 40% overall response result <- mdrr( n = 200, # total sample size cprob = 0.3, # proportion marker positive presp = 0.4, # overall response probability alpha = 0.05, power = 0.8 ) print(result) #> Minimum detectable response rates #> P(response | marker+): 0.589 #> P(response | marker-): 0.319 ``` -------------------------------- ### Permutation Log-Rank Test (permlogrank) Source: https://context7.com/veseshan/clinfun/llms.txt Performs log-rank test for survival comparisons using permutation reference distributions for small samples. ```APIDOC ## permlogrank - Permutation Log-Rank Test ### Description Performs log-rank test for survival comparisons using permutation reference distributions for small samples. ### Parameters #### Request Body - **formula** (formula) - Required - A formula object, such as `Surv(time, status) ~ group`. - **data** (data.frame) - Optional - A data frame containing the variables specified in the formula. - **nperm** (integer) - Required - Number of permutations to perform. ### Response #### Success Response (200) - **result** (htest object) - An object of class 'htest' containing the test statistic, p-value, and other relevant information. ### Request Example ```r library(clinfun) library(survival) set.seed(456) time <- c(rexp(15, 0.1), rexp(15, 0.2)) status <- sample(0:1, 30, replace = TRUE) group <- rep(1:2, each = 15) result <- permlogrank( Surv(time, status) ~ group, nperm = 5000 ) print(result) ``` ### Response Example ``` Permutation log-rank test Chi-square = 2.45, p-value = 0.124 (based on 5000 permutations) ``` ``` -------------------------------- ### Design Group Sequential Trial for Binomial Outcomes Source: https://context7.com/veseshan/clinfun/llms.txt Calculates sample sizes for trials with binomial outcomes using gsdesign.binomial. ```r design <- gsdesign.binomial( ifrac = c(0.25, 0.5, 0.75, 1.0), # information fractions pC = 0.2, # control arm response rate pE = 0.35, # experimental arm response rate sig.level = 0.05, power = 0.8, delta.eb = 0.5, # O'Brien-Fleming efficacy boundary delta.fb = 0.5, # O'Brien-Fleming futility boundary alternative = "two.sided" ) print(design) ``` -------------------------------- ### Compare Growth Curves Using AUC Source: https://context7.com/veseshan/clinfun/llms.txt Performs a two-sample test for comparing growth curves based on the area under the curve (AUC). Requires the clinfun package and simulated data. ```r library(clinfun) # Compare tumor growth curves between treatment groups set.seed(111) # Time points time <- rep(c(0, 7, 14, 21, 28), each = 10) # Control group: faster growth control <- 100 * exp(0.05 * time) + rnorm(50, sd = 10) # Treatment group: slower growth treatment <- 100 * exp(0.03 * time) + rnorm(50, sd = 10) # Combine data tumor_size <- c(control, treatment) group <- rep(1:2, each = 50) time_all <- rep(time, 2) # Test for difference in growth curves result <- aucVardiTest( y = tumor_size, time = time_all, group = group ) print(result) ``` -------------------------------- ### Minimum Detectable Odds Ratio (fe.mdor) Source: https://context7.com/veseshan/clinfun/llms.txt Calculates the minimum detectable odds ratio given sample sizes, proportion in control group, alpha, and power. ```APIDOC ## fe.mdor - Minimum Detectable Odds Ratio ### Description Calculates the minimum detectable odds ratio given sample sizes. ### Parameters #### Request Body - **ncase** (numeric) - Required - Number of cases. - **ncontrol** (numeric) - Required - Number of controls. - **pcontrol** (numeric) - Required - Proportion in control group. - **alpha** (numeric) - Optional - Significance level (default is 0.05). - **power** (numeric) - Optional - Statistical power (default is 0.8). ### Response #### Success Response (200) - **result** (list) - A list containing the minimum detectable odds ratio calculated using different methods (Schlesselman, CPS, Fisher Exact) along with their exact power. ### Request Example ```r library(clinfun) result <- fe.mdor( ncase = 100, ncontrol = 200, pcontrol = 0.3, alpha = 0.05, power = 0.8 ) print(result) ``` ### Response Example ``` Min OR Exact Power Schlesselman 2.163 0.8000000 CPS 2.098 0.8009932 Fisher Exact 2.080 0.8014276 ``` ``` -------------------------------- ### coxphQuantile - Survival Quantiles by Covariate Source: https://context7.com/veseshan/clinfun/llms.txt Draws survival time quantile curves as a function of covariates using a fitted Cox proportional hazards model. ```APIDOC ## coxphQuantile ### Description Draws survival time quantile curves as a function of covariates. ### Method `coxphQuantile` ### Parameters #### Path Parameters None #### Query Parameters - **cox_fit** (Coxph object) - The fitted Cox proportional hazards model object from `survival::coxph`. - **xrange** (numeric vector) - The range of covariate values for plotting. - **p** (numeric) - The quantile to plot (e.g., 0.5 for median). - **whichx** (numeric) - The index of the covariate in the `cox_fit` model to vary. - **otherx** (numeric vector, optional) - Fixed values for other covariates in the model. - **col** (character or numeric, optional) - Color for the plotted curve. ### Request Example ```r library(clinfun) library(survival) # Fit Cox model data(pbc, package = "survival") pbc_subset <- subset(pbc, trt > 0 & copper > 0) cox_fit <- coxph( Surv(time, status == 2) ~ trt + log(copper), data = pbc_subset ) # Add median survival quantile curve coxphQuantile(cox_fit, xrange = c(2.5, 6), p = 0.5, whichx = 2, otherx = 1) # Add 75th percentile curve in red coxphQuantile(cox_fit, xrange = c(2.5, 6), p = 0.75, whichx = 2, otherx = 1, col = 2) ``` ### Response This function generates a plot and does not return a value directly. The plot displays survival quantile curves. ``` -------------------------------- ### Calculate Fisher's Exact Sample Size Source: https://context7.com/veseshan/clinfun/llms.txt Calculates sample sizes based on Fisher's exact test for comparing two proportions using fe.ssize. ```r library(clinfun) # Calculate sample size for comparing response rates: # - Standard treatment: 20% response # - Experimental: 30% response # - 80% power, 5% alpha result <- fe.ssize( p1 = 0.2, # response rate group 1 p2 = 0.3, # response rate group 2 alpha = 0.05, power = 0.8, r = 1 # 1:1 randomization ) print(result) # With unequal allocation (2:1 ratio) fe.ssize(p1 = 0.2, p2 = 0.35, alpha = 0.05, power = 0.9, r = 2) ``` -------------------------------- ### Design Group Sequential Trial for Normal Outcomes Source: https://context7.com/veseshan/clinfun/llms.txt Calculates sample sizes for trials comparing means with normally distributed outcomes using gsdesign.normal. ```r library(clinfun) # Design a 3-look group sequential trial for continuous outcomes design <- gsdesign.normal( ifrac = c(1/3, 2/3, 1), # look at 1/3, 2/3, and full enrollment delta = 0.5, # true difference in means sd = 1, # standard deviation sig.level = 0.05, power = 0.9, delta.eb = 0.5, # O'Brien-Fleming boundary alternative = "two.sided" ) print(design) ``` -------------------------------- ### Calculate Minimum Detectable Odds Ratio (fe.mdor) Source: https://context7.com/veseshan/clinfun/llms.txt Use fe.mdor to determine the minimum detectable odds ratio given sample sizes for cases and controls, along with the proportion in the control group, alpha, and power. ```r library(clinfun) # Given sample sizes, what odds ratio can be detected? result <- fe.mdor( ncase = 100, # cases ncontrol = 200, # controls pcontrol = 0.3, # proportion in control group alpha = 0.05, power = 0.8 ) print(result) #> Min OR Exact Power #> Schlesselman 2.163 0.8000000 #> CPS 2.098 0.8009932 #> Fisher Exact 2.080 0.8014276 ``` -------------------------------- ### Perform Jonckheere-Terpstra Test (jonckheere.test) Source: https://context7.com/veseshan/clinfun/llms.txt Use jonckheere.test for exact or permutation-based Jonckheere-Terpstra tests to detect ordered differences among groups. Specify the alternative hypothesis as 'increasing' or 'decreasing'. For tied data, permutation tests are recommended. ```r library(clinfun) # Test for increasing trend across dose groups set.seed(123) dose_group <- rep(1:4, each = 15) # 4 dose levels response <- rnorm(60) + 0.3 * dose_group # increasing trend result <- jonckheere.test( x = response, g = dose_group, alternative = "increasing" ) print(result) #> Jonckheere-Terpstra test #> #> data: response by dose_group #> JT = 1078, p-value = 0.0009213 #> alternative hypothesis: increasing # With tied data, use permutation test response[1:3] <- mean(response[1:3]) # create ties result_perm <- jonckheere.test( x = response, g = dose_group, alternative = "increasing", nperm = 5000 ) print(result_perm) ``` -------------------------------- ### Concordance Probability Estimate (coxphCPE) Source: https://context7.com/veseshan/clinfun/llms.txt Calculates the Gonen-Heller concordance probability estimate for Cox regression models. ```APIDOC ## coxphCPE - Concordance Probability Estimate ### Description Calculates the Gonen-Heller concordance probability estimate for Cox regression models. ### Parameters #### Request Body - **cox_fit** (coxph object) - Required - A fitted Cox proportional hazards model object (from `survival::coxph`). - **out.ties** (logical) - Optional - If TRUE, handles ties in risk scores by averaging. Defaults to FALSE. ### Response #### Success Response (200) - **cpe** (numeric vector) - A vector containing the Concordance Probability Estimate (CPE), its smoothed value, and its standard error. ### Request Example ```r library(clinfun) library(survival) data(pbc, package = "survival") pbc_subset <- subset(pbc, trt > 0 & copper > 0) cox_fit <- coxph( Surv(time, status == 2) ~ age + log(copper) + log(bili), data = pbc_subset ) cpe <- coxphCPE(cox_fit) print(cpe) # For discrete risk groups, use out.ties = TRUE cpe_discrete <- coxphCPE(cox_fit, out.ties = TRUE) ``` ### Response Example ``` CPE smooth.CPE se.CPE 0.7234 0.7189 0.0298 ``` ``` -------------------------------- ### Empirical ROC Curve (roc.curve) Source: https://context7.com/veseshan/clinfun/llms.txt Computes and plots empirical ROC curves for diagnostic markers. ```APIDOC ## roc.curve - Empirical ROC Curve ### Description Computes and plots empirical ROC curves for diagnostic markers. ### Parameters #### Request Body - **marker** (numeric vector) - Required - Vector of marker values. - **status** (vector) - Required - Vector of true status (0 for negative, 1 for positive). - **nboot** (integer) - Optional - Number of bootstrap samples for confidence intervals. Defaults to 0 (no bootstrapping). - **PRC** (logical) - Optional - If TRUE, computes and plots a Precision-Recall Curve instead of an ROC curve. Defaults to FALSE. ### Response #### Success Response (200) - **result** (list) - A list containing AUC, standard error, and optionally confidence intervals. If PRC is TRUE, it returns precision-recall curve data. ### Request Example ```r library(clinfun) set.seed(789) status <- rep(0:1, each = 50) marker1 <- rnorm(100) + status marker2 <- rnorm(100) + 1.5 * status roc1 <- roc.curve(marker = marker1, status = status) roc2 <- roc.curve(marker = marker2, status = status) print(roc1) print(roc2) # Plot ROC curves plot(roc1, main = "ROC Curve Comparison") lines(roc2, col = "red") legend("bottomright", c("Marker 1", "Marker 2"), col = c("black", "red"), lty = 1) # Plot Precision-Recall curve plot(roc1, PRC = TRUE, main = "Precision-Recall Curve") ``` ### Response Example ``` Area under the curve: 0.7368 Standard error: 0.0489 Area under the curve: 0.8624 Standard error: 0.0372 ``` ``` -------------------------------- ### Compare ROC Curve Areas (roc.area.test) Source: https://context7.com/veseshan/clinfun/llms.txt Use roc.area.test to test for equality of areas under multiple ROC curves using DeLong's method. It requires a matrix of marker values and the corresponding disease status. ```r library(clinfun) # Compare multiple diagnostic markers set.seed(101) status <- rep(0:1, each = 75) marker_x <- rnorm(150) + 0.8 * status marker_y <- rnorm(150) + 1.2 * status marker_z <- rnorm(150) + 1.0 * status # Test if AUCs are significantly different result <- roc.area.test( markers = cbind(marker_x, marker_y, marker_z), status = status ) print(result) #> Areas under the curve: #> marker_x marker_y marker_z #> Area 0.7142 0.8156 0.7623 #> SE 0.0423 0.0356 0.0391 #> #> Test for equality of AUCs: #> Chi-square = 4.82, df = 2, p-value = 0.0898 ``` -------------------------------- ### gsdesign.normal - Group Sequential Design for Normal Outcomes Source: https://context7.com/veseshan/clinfun/llms.txt Calculates sample sizes for group sequential trials comparing means with normally distributed outcomes. ```APIDOC ## gsdesign.normal ### Description Calculates sample sizes for trials comparing means with normally distributed outcomes using a group sequential design. ### Method `gsdesign.normal(ifrac, delta, sd, sig.level, power, delta.eb, alternative)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **ifrac** (numeric vector) - Information fractions at which to perform interim analyses. * **delta** (numeric) - True difference in means between the two groups. * **sd** (numeric) - Standard deviation of the outcome. * **sig.level** (numeric) - Significance level (Type I error rate). * **power** (numeric) - Desired power of the trial. * **delta.eb** (numeric) - Efficacy boundary parameter (e.g., O'Brien-Fleming). * **alternative** (character) - Type of alternative hypothesis ('two.sided', 'less', 'greater'). ### Request Example ```r library(clinfun) design <- gsdesign.normal( ifrac = c(1/3, 2/3, 1), delta = 0.5, sd = 1, sig.level = 0.05, power = 0.9, delta.eb = 0.5, alternative = "two.sided" ) print(design) ``` ### Response #### Success Response (200) Returns a design object containing information fractions, efficacy boundaries, and sample size per arm. #### Response Example ``` Group sequential design Information fraction: 0.333 0.667 1.000 Efficacy boundary: 3.471 2.454 2.004 Sample size per arm: 86 ``` ```