### Compute Logrank Beta Example Source: https://github.com/alexanderlynl/safestats/blob/master/man/computeLogrankBetaFrom.Rd A basic example demonstrating how to call computeLogrankBetaFrom with a minimal hazard ratio of 0.7, 300 events, and 10 simulations. ```R computeLogrankBetaFrom(hrMin=0.7, 300, nSim=10) ``` -------------------------------- ### Compute Beta Bootstrapper Example Source: https://github.com/alexanderlynl/safestats/blob/master/man/computeBetaBootstrapper.Rd Example usage of computeBetaBootstrapper. First, sample stopping times using sampleStoppingTimesSaviT with parameter 0.7, 10 simulations, and a maximum sample size of 20. Then, call computeNPlanBootstrapper with the sampling result, parameter 0.7, a planned sample size of 0.2, 20, and 100 bootstrap samples. ```R samplingResult <- sampleStoppingTimesSaviT(0.7, nSim=10, nMax=20) result <- computeNPlanBootstrapper(samplingResult, 0.7, 0.2, 20, nBoot=1e2) ``` -------------------------------- ### Install safestats from a downloaded tar.gz file Source: https://github.com/alexanderlynl/safestats/blob/master/vignettes/aInstallationGuide.Rmd Installs the safestats package from a local tar.gz file, with repos set to NULL and type set to 'source'. ```r install.packages(path_to_file, repos = NULL, type="source") ``` -------------------------------- ### Set up knitr options and load safestats Source: https://github.com/alexanderlynl/safestats/blob/master/vignettes/contingency-tables-vignette.Rmd Initial setup for the vignette: configures knitr chunk options and loads the safestats package. This is required for all subsequent examples. ```r knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.height = 4, fig.width = 8 ) library(safestats) ``` -------------------------------- ### Compute bootObj for nPlan Source: https://github.com/alexanderlynl/safestats/blob/master/man/computeBootObj.Rd Example usage of computeBootObj to calculate the bootObj with a specified nPlan and beta value. ```R computeBootObj(1:100, objType="nPlan", beta=0.3) ``` -------------------------------- ### Construct a savi design object Source: https://github.com/alexanderlynl/safestats/blob/master/man/constructSaviDesignObj.Rd Example of initializing a savi design object for a Z-Test. ```R obj <- constructSaviDesignObj("Z-Test") ``` -------------------------------- ### Compute power with computePowerSaviZ Source: https://github.com/alexanderlynl/safestats/blob/master/man/computePowerSaviZ.Rd A basic example demonstrating how to call computePowerSaviZ with a specified mean difference, sample size, and number of simulations. ```R computePowerSaviZ(meanDiffTrue=0.7, 20, nSim=10) ``` -------------------------------- ### Compute nPlan with computeNPlanSaviT Source: https://github.com/alexanderlynl/safestats/blob/master/man/computeNPlanSaviT.Rd Example call to computeNPlanSaviT with deltaTrue=0.7, power=0.2, and nSim=10. This returns a list containing at least nPlan and an adapted boot object. ```R computeNPlanSaviT(0.7, 0.2, nSim=10) ``` -------------------------------- ### Example: saviAnovaOneB with plant data Source: https://github.com/alexanderlynl/safestats/blob/master/man/saviAnovaOneB.Rd Creates a data frame with plant heights for three treatment groups and calls saviAnovaOneB with the formula height ~ treatment and parameter=1. ```R # Data plantData <- data.frame( treatment = factor(rep(c("control", "fertiliserA", "fertiliserB"), each = 10)), height = c( c(12, 14, 11, 13, 12, 15, 13, 11, 14, 12), # Control group c(18, 20, 19, 22, 21, 20, 17, 19, 21, 23), # Fertiliser A group c(15, 17, 16, 15, 18, 14, 16, 17, 15, 16) # Fertiliser B group ) ) saviAnovaOneB(height ~ treatment, data = plantData, parameter=1) ``` -------------------------------- ### Install and load safestats from GitHub Source: https://github.com/alexanderlynl/safestats/blob/master/vignettes/aInstallationGuide.Rmd Installs the development version of safestats from GitHub using the remotes package, specifying the 'futility88' branch, and then loads the package. ```r remotes::install_github("AlexanderLyNL/safestats", ref = "futility88") library(safestats) ``` -------------------------------- ### Install and load the remotes package Source: https://github.com/alexanderlynl/safestats/blob/master/vignettes/aInstallationGuide.Rmd Installs the remotes package and loads it into the R session, required for installing the GitHub version of safestats. ```r install.packages("remotes") library("remotes") ``` -------------------------------- ### Example: conjugateBfTStat(5.2, 2, 3, 3.4, 2, 12) Source: https://github.com/alexanderlynl/safestats/blob/master/man/conjugateBfTStatOld.Rd Example usage of the conjugateBfTStat function (note: the example calls conjugateBfTStat, not conjugateBfTStatOld). It passes sample means, observed standard deviations, and sample sizes for two groups. ```R conjugateBfTStat(5.2, 2, 3, 3.4, 2, 12) ``` -------------------------------- ### Compute nPlan with computeNPlanSaviZ Source: https://github.com/alexanderlynl/safestats/blob/master/man/computeNPlanSaviZ.Rd A basic example showing how to compute the planned sample size using specific mean difference and power parameters with a limited number of simulations. ```R computeNPlanSaviZ(0.7, 0.2, nSim=10) ``` -------------------------------- ### Simulate and visualize two proportions test performance Source: https://github.com/alexanderlynl/safestats/blob/master/man/simulateTwoProportions.Rd This example defines three sets of prior hyperparameters and runs a simulation to compare their performance, followed by printing and plotting the results. ```R priorList1 <- list(betaA1 = 10, betaA2 = 1, betaB1 = 1, betaB2 = 10) priorList2 <- list(betaA1 = 0.18, betaA2 = 0.18, betaB1 = 0.18, betaB2 = 0.18) priorList3 <- list(betaA1 = 1, betaA2 = 1, betaB1 = 1, betaB2 = 1) simResult <- simulateTwoProportions( hyperparameterList = list(priorList1, priorList2, priorList3), alternativeRestriction = "none", alpha = 0.1, beta = 0.2, na = 1, nb = 1, deltamax = -0.4, deltamin = -0.9, deltaGridSize = 3, M = 10 ) print(simResult) plot(simResult) ``` -------------------------------- ### designSaviZ1aWantNPlan example call Source: https://github.com/alexanderlynl/safestats/blob/master/man/designSaviZ1aWantNPlan.Rd Example usage of designSaviZ1aWantNPlan with meanDiffMin=0.9, power=0.7, and nSim=10. This call returns a list with the parameter and targeted nPlan. ```r designSaviZ1aWantNPlan(meanDiffMin=0.9, power=0.7, nSim=10) ``` -------------------------------- ### Install development version from GitHub Source: https://github.com/alexanderlynl/safestats/blob/master/vignettes/safestats-vignetteT.Rmd Installs the development version of safestats from GitHub using the remotes package. Requires the remotes package to be installed. ```r remotes::install_github("AlexanderLyNL/safestats", build_vignettes = TRUE) ``` -------------------------------- ### Install development version from GitHub Source: https://github.com/alexanderlynl/safestats/blob/master/README.md Use the devtools package to install the development version of safestats from GitHub, including vignettes. ```r devtools::install_github("AlexanderLyNL/safestats", build_vignettes = TRUE) ``` -------------------------------- ### Compute planned sample size with computeLogrankNEvents Source: https://github.com/alexanderlynl/safestats/blob/master/man/computeLogrankNEvents.Rd Example call to computeLogrankNEvents with hrMin=0.7, beta=0.2, and nSim=10. This returns a list containing at least nEvents and an adapted boot object. ```R computeLogrankNEvents(0.7, 0.2, nSim=10) ``` -------------------------------- ### Call tTestWidthDerivative with example parameters Source: https://github.com/alexanderlynl/safestats/blob/master/man/tTestWidthDerivative.Rd Example call to tTestWidthDerivative with g=1, nEff=1, and nu=1. The function returns a number that should be zero when g is optimal. ```R tTestWidthDerivative(1, 1, 1) ``` -------------------------------- ### Simulate stopping times with sampleStoppingTimesSaviT Source: https://github.com/alexanderlynl/safestats/blob/master/man/sampleStoppingTimesSaviT.Rd Example call to sampleStoppingTimesSaviT with deltaTrue=0.7, nSim=10, and nMax=20. This simulates stopping times for the safe T-test under continuous monitoring. ```R sampleStoppingTimesSaviT(0.7, nSim=10, nMax=20) ``` -------------------------------- ### Simulate stopping times with sampleStoppingTimesSaviZ Source: https://github.com/alexanderlynl/safestats/blob/master/man/sampleStoppingTimesSaviZ.Rd Calls sampleStoppingTimesSaviZ with meanDiffTrue=0.7, nSim=10, and nMax=20. This is a minimal example to demonstrate the function's usage. ```r sampleStoppingTimesSaviZ(0.7, nSim=10, nMax=20) ``` -------------------------------- ### Switch between exact and Gaussian savi logrank test Source: https://github.com/alexanderlynl/safestats/blob/master/man/saviLogrankTest.Rd Example switching between savi exact and savi Gaussian logrank test. Uses alternative='less' and generates survival data, then runs both exact and Gaussian versions and prints results. ```R ###### Example switching between savi exact and savi Gaussian logrank test designObj <- designSaviLogrank(0.8, alternative="less") dat <- safestats::generateSurvData(300, 300, 2, 0.0065, 0.0065*0.8, seed=1) survTime <- survival::Surv(dat$time, dat$status) resultE <- saviLogrankTest(survTime ~ dat$group, designObj = designObj) resultG <- saviLogrankTest(survTime ~ dat$group, designObj = designObj, exact=FALSE) resultE resultG ``` -------------------------------- ### Example: computeZTSumStats with two samples Source: https://github.com/alexanderlynl/safestats/blob/master/man/computeZTSumStats.Rd Creates two random samples of sizes 23 and 39 with standard deviations 7 and 3, then calls computeZTSumStats with x and y. The function returns a list of summary statistics. ```R n1 <- 23 n2 <- 39 x <- rnorm(n1, sd=7) y <- rnorm(n2, sd=3) computeZTSumStats(x=x, y=y) ``` -------------------------------- ### Compute exact logrank e-value components Source: https://github.com/alexanderlynl/safestats/blob/master/man/logrankSingleEExact.Rd This example demonstrates how to iterate through observation vectors to calculate log e-values and aggregate them into final e-value results. ```R y0Vector <- c(5, 4, 3, 3, 2, 1) y1Vector <- c(5, 5, 4, 2, 2, 0) obs0Vector <- c(1, 1, 0, 1, 0, 1) obs1Vector <- c(0, 0, 1, 0, 1, 0) logEValueGreater <- logEValueLess <- vector("numeric", length(y0Vector)) for (i in seq_along(y0Vector)) { tempResult <- logrankSingleEExact(obs0=obs0Vector[i], obs1=obs1Vector[i], y0=y0Vector[i], y1=y1Vector[i], thetaS=0.7, theta0=1) logEValueLess[i] <- tempResult[["logEValueLess"]] logEValueGreater[i] <- tempResult[["logEValueGreater"]] } eValueLess <- exp(sum(logEValueLess)) eValueLess #1.116161 eValueGreater <- exp(sum(logEValueGreater)) eValueGreater # 0.7665818 eValue <- 1/2*eValueLess + 1/2*eValueGreater eValue # 0.9413714 ``` -------------------------------- ### matchEsMinWith example with parameter=0.4 Source: https://github.com/alexanderlynl/safestats/blob/master/man/matchEsMinWith.Rd Calls matchEsMinWith with the parameter argument set to 0.4, using default values for other arguments (analysisType='z', sigma=1, alternative='twoSided', eType='mom'). Returns the matched parameter value. ```r matchEsMinWith(parameter=0.4) ``` -------------------------------- ### Design a savi T-test with deltaMin and power Source: https://github.com/alexanderlynl/safestats/blob/master/man/designSaviT1aWantNPlan.Rd Example call to designSaviT1aWantNPlan with deltaMin=0.9, power=0.7, and nSim=10. This returns a list with the parameter and targeted nPlan. ```r designSaviT1aWantNPlan(deltaMin=0.9, power=0.7, nSim=10) ``` -------------------------------- ### designSaviLogrank usage examples Source: https://github.com/alexanderlynl/safestats/blob/master/man/designSaviLogrank.Rd These examples show different ways to call designSaviLogrank. The first uses the default exact computation. The second disables exact computation. The third specifies a tolerable type II error beta and a simulation count nSim. The fourth specifies the anticipated number of events nEvents and a simulation count nSim. ```r designSaviLogrank(hrMin=0.7) ``` ```r designSaviLogrank(hrMin=0.7, exact=FALSE) ``` ```r designSaviLogrank(hrMin=0.7, beta=0.3, nSim=10) ``` ```r designSaviLogrank(hrMin=0.7, nEvents=190, nSim=10) ``` -------------------------------- ### Compute e-value with saviAnovaStat Source: https://github.com/alexanderlynl/safestats/blob/master/man/saviAnovaStat.Rd Example call to saviAnovaStat with sumX, n, sumSquares, and parameter arguments. The function returns a list with the e-value. ```R saviAnovaStat(1:6, 1:6, (1:6)^2, parameter=1) ``` -------------------------------- ### Create and print savi design objects Source: https://github.com/alexanderlynl/safestats/blob/master/man/print.saviDesign.Rd These examples create savi design objects for Z, T, and logrank tests, which are then printed using the print method. ```R designSaviZ(meanDiffMin=0.5) ``` ```R designSaviT(deltaMin=0.5) ``` ```R designSaviLogrank(hrMin=0.7) ``` -------------------------------- ### Call designSavi1aHelper with computeNPlanSaviZ output Source: https://github.com/alexanderlynl/safestats/blob/master/man/designSavi1aHelper.Rd Shows how to use designSavi1aHelper with a sampling result from computeNPlanSaviZ. The example passes esMin=0.7, power=0.2, and ratio=1. The function returns a list of partial results for the design scenario. ```r samplingResult <- computeNPlanSaviZ(0.7, nSim=10, nMax=20) result <- designSavi1aHelper(samplingResult, 0.7, 0.2, 1) ``` -------------------------------- ### Call setLowAndHighEsTrueZ with default parameters Source: https://github.com/alexanderlynl/safestats/blob/master/man/setLowAndHighEsTrueZ.Rd Example call to setLowAndHighEsTrueZ with nEff = 10, using default values for eType, alternative, lowEsTrue, and highEsTrue. ```R setLowAndHighEsTrueZ(10) ``` -------------------------------- ### Compute logrank statistic using logrankSingleZ in a loop Source: https://github.com/alexanderlynl/safestats/blob/master/man/logrankSingleZ.Rd This example sets up vectors for the control and treatment groups, then loops over each time point to call logrankSingleZ, storing the oMinE and variance components. Finally, it sums the oMinE values and divides by the square root of the sum of variances to obtain the logrank statistic. ```R y0Vector <- c(6, 4, 4, 1, 0) y1Vector <- c(6, 6, 5, 2, 2) obs0Vector <- c(1, 0, 2, 1, 0) obs1Vector <- c(0, 1, 1, 0, 1) varVector <- oMinEVector <-y0Vector for (i in seq_along(y0Vector)) { tempResult <- logrankSingleZ(obs0=obs0Vector[i], obs1=obs1Vector[i], y0=y0Vector[i], y1=y1Vector[i]) oMinEVector[i] <- tempResult[["oMinE"]] varVector[i] <- tempResult[["v"]] } sum(oMinEVector)/sqrt(sum(varVector)) ``` -------------------------------- ### R example: compute upper bound on log odds ratio with computeConfidenceBoundForLogOddsTwoProportions Source: https://github.com/alexanderlynl/safestats/blob/master/man/computeConfidenceBoundForLogOddsTwoProportions.Rd Creates a balanced SAVI design with na=1, nb=1, 10 planned blocks, and alpha=0.05. Then defines observed data ya and yb, and calls computeConfidenceBoundForLogOddsTwoProportions with bound='upper', deltaStart=-0.01, deltaStop=-4, and precision=20 to establish an upper bound on the log odds ratio. ```r balancedSaviDesign <- designSaviTwoProportions(na = 1, nb = 1, nBlocksPlan = 10, alpha = 0.05) #hypothesize OR < 1 (i.e., log OR < 0) ya <- c(1,1,1,1,1,1,1,1,0,1) yb <- c(0,0,0,0,1,0,0,0,0,0) #one-sided CI for OR-, establish upper bound on log odds ratio computeConfidenceBoundForLogOddsTwoProportions(ya = ya, yb = yb, saviDesign = balancedSaviDesign, bound = "upper", deltaStart = -0.01, deltaStop = -4, precision = 20) ``` -------------------------------- ### Simulated data example for saviZTest Source: https://github.com/alexanderlynl/safestats/blob/master/man/saviZTest.Rd Creates simulated data for a two-sample Z-test: generates 30 observations from N(0,1) and 40 from N(0,1) with a fixed seed for reproducibility. ```R set.seed(1) x <- rnorm(30, mean=0) y <- rnorm(40, mean=0) ``` -------------------------------- ### Switch between exact and Gaussian savi logrank test (greater) Source: https://github.com/alexanderlynl/safestats/blob/master/man/saviLogrankTest.Rd Example switching between savi exact and savi Gaussian logrank test on the other side, using alternative='greater' and checking that both e-values are non-negative. ```R ###### Example switching between savi exact and savi Gaussian logrank test other side designObj <- designSaviLogrank(1/0.8, alternative="greater") resultE <- saviLogrankTest(survTime ~ dat$group, designObj = designObj) resultG <- saviLogrankTest(survTime ~ dat$group, designObj = designObj, exact=FALSE) if (log(resultE$eValue) >= 0 && log(resultG$eValue) >= 0 ) stop("one-sided wrong") ``` -------------------------------- ### Basic saviLogrankTest with ovarian data Source: https://github.com/alexanderlynl/safestats/blob/master/man/saviLogrankTest.Rd Example taken from survival::survdiff. Creates a design object with hrMin=1/2, prepares the ovarian data, and runs saviLogrankTest using both formula and direct argument interfaces. ```R # Example taken from survival::survdiff designObj <- designSaviLogrank(hrMin=1/2) ovData <- survival::ovarian ovData$survTime <- survival::Surv(ovData$futime, ovData$fustat) saviLogrankTest(formula=survTime~ rx, data=ovData, designObj=designObj) saviLogrankTest(survTime=survTime, group=rx, data=ovData, designObj=designObj) ``` -------------------------------- ### Compute evidence for alternative and minimal efficacy with saviRelevanceZStat Source: https://github.com/alexanderlynl/safestats/blob/master/man/saviZTestStat.Rd Examples of using `saviRelevanceZStat` to compute evidence for the alternative over minimal efficacy (z=3) and evidence for minimal efficacy over the alternative (z=0.35). Both use n1=100 and parameter=0.4. ```R # evidence for the alternative over minimal efficacy saviRelevanceZStat(z=3, n1=100, parameter=0.4) # evidence for minimal efficacy over the alternative saviRelevanceZStat(z=0.35, n1=100, parameter=0.4) ``` -------------------------------- ### Simulate follow-up study and combine e-values Source: https://github.com/alexanderlynl/safestats/blob/master/vignettes/contingency-tables-vignette.Rmd Selects e-values >= 10 as promising, designs a follow-up study with 30 blocks (60 participants), simulates the follow-up using the same design, and multiplies the new e-values with the original promising e-values to get combined e-values. ```R promisingEValues <- eValuesNotRejected[eValuesNotRejected >= 10] followUpDesign <- designSaviTwoProportions(na = 1, nb = 1, nBlocksPlan = 30) followUpResults <- simulateOptionalStoppingScenarioTwoProportions(followUpDesign, M = length(promisingEValues), thetaA = 0.2, thetaB = 0.5) newEValues <- followUpResults[["eValues"]] * promisingEValues ``` -------------------------------- ### Compute e-values with saviZTestStat for different eTypes Source: https://github.com/alexanderlynl/safestats/blob/master/man/saviZTestStat.Rd Examples of using `saviZTestStat` with different `eType` values: "grow", "eGauss", and "eCauchy". Each call uses z=3, n1=100, and parameter=0.4 (or 0.4^2 for eGauss). ```R saviZTestStat(z=3, n1=100, parameter=0.4, eType="grow") saviZTestStat(z=3, n1=100, parameter=0.4^2, eType="eGauss") saviZTestStat(z=3, n1=100, parameter=0.4, eType="eCauchy") ``` -------------------------------- ### Compute logrank statistic with computeLogrankZ and compare with survdiff Source: https://github.com/alexanderlynl/safestats/blob/master/man/computeLogrankZ.Rd Generate survival data with generateSurvData, create a Surv object, and compute the logrank statistic using computeLogrankZ. The example also shows how to compare the result with the chi-square statistic from survival::survdiff. ```r data <- generateSurvData(nP = 5, nT = 5, lambdaP = 0.03943723, lambdaT = 0.5*0.03943723, endTime = 40, seed = 2006) survObj <- survival::Surv(data$time, data$status) survObj <- survival::Surv(data$time, data$status) result <- computeLogrankZ(survObj, data$group) result$z sqrt(survival::survdiff(survObj~data$group)$chisq) ``` -------------------------------- ### Usage of returnOne Source: https://github.com/alexanderlynl/safestats/blob/master/man/returnOne.Rd Demonstrates the basic invocation of the returnOne function. ```R returnOne() ``` -------------------------------- ### Install stable version from CRAN Source: https://github.com/alexanderlynl/safestats/blob/master/README.md Install the stable version of the safestats package directly from CRAN. ```r install.packages("safestats") ``` -------------------------------- ### computePowerSaviT(deltaTrue, nPlan, alpha, alternative, testType, parameter, deltaMin, eType, wantSamplePaths, nuMin, wantSimData, pb, seed, nSim, nBoot, relevanceTest, relevanceSize, alphaRelevance, ...) Source: https://github.com/alexanderlynl/safestats/blob/master/man/computePowerSaviT.Rd Computes the power of the saviTTest based on deltaMin and nPlan. Returns a list containing at least the power and an adapted boot object. ```APIDOC ## computePowerSaviT ### Description Computes the power of the saviTTest based on deltaMin and nPlan. ### Usage ```r computePowerSaviT( deltaTrue, nPlan, alpha = 0.05, alternative = c("twoSided", "greater", "less"), testType = c("oneSample", "paired", "twoSample"), parameter = NULL, deltaMin = deltaTrue, eType = c("mom", "eGauss", "imom", "eCauchy", "grow", "lai"), wantSamplePaths = TRUE, nuMin = 2, wantSimData = TRUE, pb = TRUE, seed = NULL, nSim = 1000L, nBoot = nSim, relevanceTest = FALSE, relevanceSize = NULL, alphaRelevance = NULL, ... ) ``` ### Arguments - **deltaTrue** (numeric) - Required - Data governing effect size used for simulations. Default deltaTrue=deltaMin. - **nPlan** (numeric vector) - Required - Optional numeric vector of length at most 2, see scenario 2 and 3 above. - **alpha** (numeric) - Optional - Numeric in (0, 1) that specifies the tolerable type I error and the null rejection rule e >= 1/alpha. Default 0.05. - **alternative** (character) - Optional - A character string specifying the alternative hypothesis. Must be one of "twoSided" (default), "greater" or "less". - **testType** (character) - Optional - Either one of "oneSample", "paired", "twoSample". - **parameter** (numeric) - Optional - An optional savi test defining parameter. Default set to NULL and adapts to meanDiffMin and eType. - **deltaMin** (numeric) - Optional - Numeric that defines the minimal relevant standardised mean difference, the smallest population effect size that we would like to detect (with sufficient power). Default deltaTrue. - **eType** (character) - Optional - Character one of "mom", "grow", "eGauss", and "eCauchy". "mom" is default and uses a non-local moment prior with bump(s) at meanDiffMin, "grow" uses point prior(s) at meanDiffMin, "eGauss" a zero-centred normal prior, "eCauchy" a zero centred Cauchy prior. - **wantSamplePaths** (logical) - Optional - If TRUE then also outputs the sample paths. Default TRUE. - **nuMin** (numeric) - Optional - Numeric > 0, the minimum degrees of freedom under which the results are trivial, thus, 1. Default 2. - **wantSimData** (logical) - Optional - If TRUE then also output the simulated data. Default TRUE. - **pb** (logical) - Optional - If TRUE, then show progress bar. Default TRUE. - **seed** (integer) - Optional - Integer, seed number. - **nSim** (integer) - Optional - Integer > 0, the number of simulations needed to compute power or the number of samples paths for the savi t test under continuous monitoring. Default 1000L. - **nBoot** (integer) - Optional - Integer > 0 representing the number of bootstrap samples to assess the accuracy of the approximations of the power, the number of samples for the savi t test under continuous monitoring, or for the computation of the logarithm of the implied target. Default nSim. - **relevanceTest** (logical) - Optional - If TRUE then impose a rule to stop for minimal efficiency if e <= alphaRelevance. Default FALSE. - **relevanceSize** (numeric) - Optional - The minimal clinical relevant mean difference that we do not want to miss under the alternative. Default relevanceSize=NULL implies relevanceSize=abs(meanDiffMin). - **alphaRelevance** (numeric) - Optional - The threshold for relevance test. Taken to be minimum of alpha and 1-power. - **...** - Optional - Further arguments to be passed to or from methods, but mainly to perform do.calls. ### Value A list which contains at least power and an adapted bootObject of class boot(). ### Examples ```r computePowerSaviT(deltaTrue=0.7, 27, nSim=10) ``` ``` -------------------------------- ### Call designSaviZ3bWantParameter with nPlan=13 Source: https://github.com/alexanderlynl/safestats/blob/master/man/designSaviZ3bWantParameter.Rd Example usage of the designSaviZ3bWantParameter function with the nPlan argument set to 13. This is the only example provided on the page. ```r designSaviZ3bWantParameter(nPlan=13) ``` -------------------------------- ### constructSampleStoppingTimesList(nSim, nMax, wantEValuesAtNMax, wantSamplePaths) Source: https://github.com/alexanderlynl/safestats/blob/master/man/constructSampleStoppingTimesList.Rd Constructs a list to be set in the sampleStoppingTimes... function. It takes parameters for simulation count, maximum sample size, and flags for computing e-values at nMax and outputting sample paths. ```APIDOC ## constructSampleStoppingTimesList ### Description Construct a list to be set in the sampleStoppingTimes... function. ### Usage ```r constructSampleStoppingTimesList( nSim = 1000L, nMax = 1000L, wantEValuesAtNMax = FALSE, wantSamplePaths = TRUE ) ``` ### Parameters - **nSim** (integer) - Required - integer > 0, the number of simulations needed to compute power or the number of sample paths for the savi z test under continuous monitoring. - **nMax** (integer) - Required - integer > 0, maximum sample size of the (first) sample in each sample path. - **wantEValuesAtNMax** (logical) - Optional - If `TRUE`, then compute eValues at nMax. Default `FALSE`. - **wantSamplePaths** (logical) - Optional - If `TRUE`, then output the (stopped) sample paths. Default `TRUE`. ### Return Value A list with names. ### Example ```r obj <- constructSampleStoppingTimesList() ``` ``` -------------------------------- ### Run simulateTwoProportions with three prior lists and print results Source: https://github.com/alexanderlynl/safestats/blob/master/man/print.savi2x2Sim.Rd Creates three prior lists with different beta hyperparameters, then calls simulateTwoProportions() with alternativeRestriction = "none", alpha = 0.1, beta = 0.2, na = 1, nb = 1, deltamax = -0.4, deltamin = -0.9, deltaGridSize = 3, and M = 10. The resulting object is assigned to simResult, which can be printed to display the simulation results. ```R priorList1 <- list(betaA1 = 10, betaA2 = 1, betaB1 = 1, betaB2 = 10) priorList2 <- list(betaA1 = 0.18, betaA2 = 0.18, betaB1 = 0.18, betaB2 = 0.18) priorList3 <- list(betaA1 = 1, betaA2 = 1, betaB1 = 1, betaB2 = 1) simResult <- simulateTwoProportions( hyperparameterList = list(priorList1, priorList2, priorList3), alternativeRestriction = "none", alpha = 0.1, beta = 0.2, na = 1, nb = 1, deltamax = -0.4, deltamin = -0.9, deltaGridSize = 3, M = 10 ) ``` -------------------------------- ### Browse package vignettes Source: https://github.com/alexanderlynl/safestats/blob/master/README.md Access the package vignette tutorial for an extensive overview of functions and usage. ```r browseVignettes("safestats") ``` -------------------------------- ### computePowerSavi2x2(propDiffMin, na, nb, nBlocks, alpha = 0.05, alternative = c("twoSided", "less", "greater"), nSim = 1000L, nBoot = nSim, seed = NULL, wantSamplePaths = FALSE, pb = TRUE) Source: https://github.com/alexanderlynl/safestats/blob/master/man/computePowerSavi2x2.Rd Computes the power of the savi 2x2 test based on propDiffMin and nBlocks. It runs sampleStoppingTimesSavi2x2 with nMax = nBlocks and reports, per curve, the fraction of paths that cross 1/alpha within nBlocks; the worst case is the smallest, since the test must meet its target whatever the baseline is. ```APIDOC ## computePowerSavi2x2 ### Description Computes the power of the savi 2x2 test based on propDiffMin and nBlocks. It runs sampleStoppingTimesSavi2x2 with nMax = nBlocks and reports, per curve, the fraction of paths that cross 1/alpha within nBlocks; the worst case is the smallest, since the test must meet its target whatever the baseline is. ### Usage ```r computePowerSavi2x2( propDiffMin, na, nb, nBlocks, alpha = 0.05, alternative = c("twoSided", "less", "greater"), nSim = 1000L, nBoot = nSim, seed = NULL, wantSamplePaths = FALSE, pb = TRUE ) ``` ### Parameters - **propDiffMin** (numeric) - Required - numeric in (-1, 1) that defines the minimal relevant difference in proportions thetaA - thetaB, the smallest difference that we would like to detect (with sufficient power). - **na** (numeric) - Required - number of observations in group A per data block, one value or one per block. - **nb** (numeric) - Required - number of observations in group B per data block, one value or one per block. - **nBlocks** (integer) - Required - integer > 0, the planned number of data blocks. - **alpha** (numeric) - Optional - numeric in (0, 1) that specifies the tolerable type I error and the null rejection rule e >= 1/alpha. Default is 0.05. - **alternative** (character) - Optional - a character string specifying the alternative hypothesis. Must be one of "twoSided" (default), "greater" or "less", where "greater" means that group A has the larger proportion. - **nSim** (integer) - Optional - integer > 0, the number of simulations needed to compute power or the number of samples paths for the savi 2x2 test under continuous monitoring. Default is 1000L. - **nBoot** (integer) - Optional - integer > 0 representing the number of bootstrap samples to assess the accuracy of the approximations of the power, or the number of blocks for the savi 2x2 test under continuous monitoring. Default is nSim. - **seed** (integer) - Optional - integer, seed number. Default seed=NULL yields seed=2026. - **wantSamplePaths** (logical) - Optional - logical, if TRUE then also outputs the sample paths. Default is FALSE. - **pb** (logical) - Optional - logical, if TRUE, then show progress bar. Default is TRUE. ### Return Value A list which contains at least: - **power** - the worst case over the curves - **bootObjPower** - an adapted bootObject of class boot::boot() on that baseline - **powerVec** - one per curve - **worstCaseThetaA** - worst case thetaA - **worstCaseThetaB** - worst case thetaB - **nBlocks** - number of blocks - **thetaA** - sampler's thetaA - **thetaB** - sampler's thetaB - **stoppingTimes** - stopping times - **breakVector** - break vector - **eValuesStopped** - e-values at stopping - **samplePaths** - sample paths - **n1Vector** - n1 vector ``` -------------------------------- ### Perform a pilot Savi test Source: https://github.com/alexanderlynl/safestats/blob/master/man/saviTwoProportionsTest.Rd Example of performing an exploratory pilot analysis without a design object. ```R #pilot saviTwoProportionsTest(ya = ya, yb = yb, pilot = TRUE) ``` -------------------------------- ### Checking objects for try-error class Source: https://github.com/alexanderlynl/safestats/blob/master/man/isTryError.Rd Example usage of isTryError to identify if any of the provided objects are of class 'try-error'. ```R x <- 1 y <- "a" z <- try(integrate(exp, -Inf, Inf)) isTryError(x, y) isTryError(x, y, z) ``` -------------------------------- ### Perform an unbalanced Savi test Source: https://github.com/alexanderlynl/safestats/blob/master/man/saviTwoProportionsTest.Rd Example of performing a Savi test for two proportions using an unbalanced design. ```R #unbalanced design yb <- c(1,0,1,1,1,0,1) ya <- c(2,2,1,2,0,2,2) saviDesign <- designSaviTwoProportions(na = 2, nb = 1, beta = 0.20, delta = 0.6, alternativeRestriction = "none", M = 1e1) saviTwoProportionsTest(ya = ya, yb = yb, designObj = saviDesign) ``` -------------------------------- ### Design SaviT with nPlan and power goals Source: https://github.com/alexanderlynl/safestats/blob/master/man/designSaviT.Rd Scenario 2 targets power with a fixed nPlan; Scenario 3.a targets meanDiffMin with a fixed nPlan; Scenario 3.b targets an optimal E-variable given only nPlan. Each call returns a design object for plotting. ```R # Scenario 2: Goal: "power" and optimal E-variable designObj <- designSaviT(deltaMin=0.8, nPlan=16, nSim=100) ``` ```R # Scenario 3.a: Goal: "meanDiffMin" and optimal E-variable designObj <- designSaviT(power=0.7, nPlan=16) ``` ```R # Scenario 3.b: Goal: an optimal E-variable. Given: nPlan only. designObj <- designSaviT(nPlan=16) ``` -------------------------------- ### Perform a balanced Savi test Source: https://github.com/alexanderlynl/safestats/blob/master/man/saviTwoProportionsTest.Rd Example of performing a Savi test for two proportions using a balanced design. ```R #balanced design yb <- c(1,0,1,1,1,0,1) ya <- c(1,0,1,0,0,0,1) saviDesign <- designSaviTwoProportions(na = 1, nb = 1, beta = 0.20, delta = 0.6, alternativeRestriction = "none", M = 1e1) saviTwoProportionsTest(ya = ya, yb = yb, designObj = saviDesign) ``` -------------------------------- ### Call matchPowerWith with power 0.8 Source: https://github.com/alexanderlynl/safestats/blob/master/man/matchPowerWith.Rd Example call to matchPowerWith with power set to 0.8. The function returns the power value. ```r matchPowerWith(0.8) ``` -------------------------------- ### Set and Restore Plot Options Source: https://github.com/alexanderlynl/safestats/blob/master/man/setSafeStatsPlotOptionsAndReturnOldOnes.Rd Demonstrates how to capture existing graphical parameters, perform a plot, and restore the original settings. ```R oldPar <- setSafeStatsPlotOptionsAndReturnOldOnes() graphics::plot(1:10, 1:10) setPar <- graphics::par(oldPar) ``` -------------------------------- ### Calculate zMarg Source: https://github.com/alexanderlynl/safestats/blob/master/man/zMarg.Rd Example usage of the zMarg function with sample size 12, sample mean 0.3, and sample variance 2. ```R zMarg(12, 0.3, 2) ``` -------------------------------- ### simulateOptionalStoppingScenarioTwoProportions(saviDesign, M, thetaA, thetaB) Source: https://github.com/alexanderlynl/safestats/blob/master/man/simulateOptionalStoppingScenarioTwoProportions.Rd Simulates an optional stopping scenario according to a savi design for two proportions. Returns a list with simulation results including power, stopping times, and E-values. ```APIDOC ## simulateOptionalStoppingScenarioTwoProportions(saviDesign, M, thetaA, thetaB) ### Description Simulates an optional stopping scenario according to a savi design for two proportions. ### Usage simulateOptionalStoppingScenarioTwoProportions(saviDesign, M, thetaA, thetaB) ### Parameters - **saviDesign** (saviDesign object) - Required - A saviDesign object obtained through designSaviTwoProportions(). - **M** (integer) - Required - The number of data streams to sample. - **thetaA** (numeric) - Required - Bernoulli distribution parameter in group A. - **thetaB** (numeric) - Required - Bernoulli distribution parameter in group B. ### Return Value A list with the simulation results of the savi test under optional stopping with the following components: - **powerOptioStop** (numeric) - Proportion of sequences where H0 was rejected. - **nMean** (numeric) - Mean stopping time. - **probLessNDesign** (numeric) - Proportion of experiments stopped before nBlocksPlan was reached. - **lowN** (integer) - Minimum stopping time. - **eValues** (numeric vector) - All achieved E values. - **allN** (integer vector) - All stopping times. - **allSaviDecisions** (logical vector) - Decisions on rejecting H0 for each M. - **allRejectedN** (integer vector) - Stopping times of experiments where H0 was rejected. ### Example ```r balancedSaviDesign <- designSaviTwoProportions(na = 1, nb = 1, nBlocksPlan = 30) optionalStoppingSimulationResult <- simulateOptionalStoppingScenarioTwoProportions( saviDesign = balancedSaviDesign, M = 1e2, thetaA = 0.2, thetaB = 0.5 ) ``` ``` -------------------------------- ### Simulate optional stopping for two proportions Source: https://github.com/alexanderlynl/safestats/blob/master/man/simulateOptionalStoppingScenarioTwoProportions.Rd Creates a balanced savi design with na=1, nb=1, and nBlocksPlan=30, then simulates M=100 data streams with thetaA=0.2 and thetaB=0.5. The result contains power, stopping times, and E-values. ```R balancedSaviDesign <- designSaviTwoProportions(na = 1, nb = 1, nBlocksPlan = 30) optionalStoppingSimulationResult <- simulateOptionalStoppingScenarioTwoProportions( saviDesign = balancedSaviDesign, M = 1e2, thetaA = 0.2, thetaB = 0.5 ) ``` -------------------------------- ### makeRunningIntersection example Source: https://github.com/alexanderlynl/safestats/blob/master/man/makeRunningIntersection.Rd Computes the running intersection (running minimum by default) of the numeric vector c(6, -1, 3, 12). ```r makeRunningIntersection(c(6, -1, 3, 12)) ``` -------------------------------- ### Simulate sample sizes for standard vs uniform-like Beta priors Source: https://github.com/alexanderlynl/safestats/blob/master/vignettes/contingency-tables-vignette.Rmd Compares the standard Beta prior settings (from the design object) with a uniform-like prior (betaA1=2, betaA2=2, betaB1=1, betaB2=1) by simulating sample sizes for a range of minimal differences. The code is shown with eval=FALSE; the simulation results are loaded from a saved file. ```r #make the plot voor standard parameter settings standardPrior <- unbalancedSaviDesign[["betaPriorParameterValues"]] uniformLikePrior <- list(betaA1 = 2, # pretend we "have seen" 2 success and betaA2 = 2,# 2 failure in group A before starting betaB1 = 1, # and 1 success and failure in group B betaB2 = 1) #set a seed for the simulations set.seed(1082021) sampleSizePerMinimalDifference <- simulateTwoProportions( hyperparameterList = list(standard = standardPrior, uniform = uniformLikePrior), alternativeRestriction = "none", alpha = 0.05, beta = 0.2, na = 2, nb = 1, deltamin = 0.3, deltamax = 0.9 ) ``` -------------------------------- ### Sample from logrank distribution with rLogrank Source: https://github.com/alexanderlynl/safestats/blob/master/man/rLogrank.Rd Draws occurrences in group 1 (treatment) out of obsTotal occurrences. The example samples with y0=360, y1=89, obsTotal=12, and theta=3.14. ```r rLogrank(y0=360, y1=89, obsTotal=12, theta=3.14) ``` -------------------------------- ### Run savi2x2TestStat with eBeta design Source: https://github.com/alexanderlynl/safestats/blob/master/man/savi2x2TestStat.Rd Creates a design object with na=10, nb=10, and eType='eBeta', then defines data blocks ya and yb and calls savi2x2TestStat to compute the test statistic. ```R designObj <- designSavi2x2(na = 10, nb = 10, eType = "eBeta") ya <- c(8, 7, 9, 6) yb <- c(4, 5, 3, 5) savi2x2TestStat(ya, yb, designObj = designObj) ``` -------------------------------- ### Calculate true log odds ratio Source: https://github.com/alexanderlynl/safestats/blob/master/vignettes/contingency-tables-vignette.Rmd Computes the true log odds ratio for the example scenario where treatment success probability is 0.5 and placebo is 0.2. ```r log(0.5/0.5 * 0.8/0.2) ``` -------------------------------- ### Run unrestricted test on propDiff with default Beta prior Source: https://github.com/alexanderlynl/safestats/blob/master/man/designSavi2x2.Rd Runs an unrestricted test on propDiff with the default Beta prior. Use this to obtain a design without planning for a minimal difference. ```R designSavi2x2(na = 10, nb = 10, eType = "eBeta") ```