Title: | Safe Anytime-Valid Inference |
---|---|
Description: | Functions to design and apply tests that are anytime valid. The functions can be used to design hypothesis tests in the prospective/randomised control trial setting or in the observational/retrospective setting. The resulting tests remain valid under both optional stopping and optional continuation. The current version includes safe t-tests and safe tests of two proportions. For details on the theory of safe tests, see Grunwald, de Heide and Koolen (2019) "Safe Testing" <arXiv:1906.07801>, for details on safe logrank tests see ter Schure, Perez-Ortiz, Ly and Grunwald (2020) "The Safe Logrank Test: Error Control under Continuous Monitoring with Unlimited Horizon" <arXiv:2011.06931v3> and Turner, Ly and Grunwald (2021) "Safe Tests and Always-Valid Confidence Intervals for contingency tables and beyond" <arXiv:2106.02693> for details on safe contingency table tests. |
Authors: | Rosanne Turner [aut], Alexander Ly [cre, aut], Muriel Felipe Perez-Ortiz [ctb], Judith ter Schure [ctb], Peter Grunwald [ctb] |
Maintainer: | Alexander Ly <[email protected]> |
License: | LGPL (>= 3) |
Version: | 0.8.7 |
Built: | 2024-11-05 04:12:50 UTC |
Source: | https://github.com/alexanderlynl/safestats |
Checks consistency between the sided of the hypothesis and the minimal clinically relevant effect size or safe test defining parameter. Throws an error if the one-sided hypothesis is incongruent with the
checkAndReturnsEsMinParameterSide( paramToCheck, alternative = c("twoSided", "greater", "less"), esMinName = c("noName", "meanDiffMin", "phiS", "deltaMin", "deltaS", "hrMin", "thetaS", "deltaTrue"), paramDomain = NULL )
checkAndReturnsEsMinParameterSide( paramToCheck, alternative = c("twoSided", "greater", "less"), esMinName = c("noName", "meanDiffMin", "phiS", "deltaMin", "deltaS", "hrMin", "thetaS", "deltaTrue"), paramDomain = NULL )
paramToCheck |
numeric. Either a named safe test defining parameter such as phiS, or thetaS, or a minimal clinically relevant effect size called with a non-null esMinName name |
alternative |
a character string specifying the alternative hypothesis must be one of "twoSided" (default), "greater" or "less". |
esMinName |
provides the name of the effect size. Either "meanDiffMin" for the z-test, "deltaMin" for the t-test, or "hrMin" for the logrank test |
paramDomain |
Domain of the paramToCheck, typically, positiveNumbers. Default |
paramToCheck after checking, perhaps with a change in sign
Check consistency between nPlan and the testType for one and two-sample z and t-tests
checkAndReturnsNPlan( nPlan, ratio = 1, testType = c("oneSample", "paired", "twoSample") )
checkAndReturnsNPlan( nPlan, ratio = 1, testType = c("oneSample", "paired", "twoSample") )
nPlan |
optional numeric vector of length at most 2. When provided, it is used to find the safe test defining parameter phiS. Note that if the purpose is to plan based on nPlan alone, then both meanDiffMin and beta should be set to NULL. |
ratio |
numeric > 0 representing the randomisation ratio of condition 2 over condition 1. If testType is not equal to "twoSample", or if nPlan is of length(1) then ratio=1. |
testType |
either one of "oneSample", "paired", "twoSample". |
nPlan a vector of sample sizes of length 1 or 2
Helper function to check whether arguments are specified in a function at a higher level and already provided in the design object.
checkDoubleArgumentsDesignObject(designObj, ...)
checkDoubleArgumentsDesignObject(designObj, ...)
designObj |
an object of class "safeDesign". |
... |
arguments that need checking. |
Returns nothing only used for its side-effects to produces warnings if needed.
designObj <- designSafeZ(0.4) checkDoubleArgumentsDesignObject(designObj, "alpha"=NULL, alternative=NULL) # Throws a warning checkDoubleArgumentsDesignObject(designObj, "alpha"=0.4, alternative="d")
designObj <- designSafeZ(0.4) checkDoubleArgumentsDesignObject(designObj, "alpha"=NULL, alternative=NULL) # Throws a warning checkDoubleArgumentsDesignObject(designObj, "alpha"=0.4, alternative="d")
Helper function: Computes the type II error based on the minimal clinically relevant effect size and sample size.
computeBetaBatchSafeZ( meanDiffMin, nPlan, alpha = 0.05, sigma = 1, kappa = sigma, alternative = c("twoSided", "greater", "less"), testType = c("oneSample", "paired", "twoSample"), parameter = NULL )
computeBetaBatchSafeZ( meanDiffMin, nPlan, alpha = 0.05, sigma = 1, kappa = sigma, alternative = c("twoSided", "greater", "less"), testType = c("oneSample", "paired", "twoSample"), parameter = NULL )
meanDiffMin |
numeric that defines the minimal relevant mean difference, the smallest population mean that we would like to detect. |
nPlan |
optional numeric vector of length at most 2. When provided, it is used to find the safe test defining parameter phiS. Note that if the purpose is to plan based on nPlan alone, then both meanDiffMin and beta should be set to NULL. |
alpha |
numeric in (0, 1) that specifies the tolerable type I error control –independent on n– that the designed test has to adhere to. Note that it also defines the rejection rule e10 > 1/alpha. |
sigma |
numeric > 0 representing the assumed population standard deviation used for the test. |
kappa |
the true population standard deviation. Default kappa=sigma. |
alternative |
a character string specifying the alternative hypothesis must be one of "twoSided" (default), "greater" or "less". |
testType |
either one of "oneSample", "paired", "twoSample". |
parameter |
optional test defining parameter. Default set to |
numeric that represents the type II error
Helper function: Computes the type II error of the safeTTest based on the minimal clinically relevant standardised mean difference and nPlan.
computeBetaSafeT( deltaMin, nPlan, alpha = 0.05, alternative = c("twoSided", "greater", "less"), testType = c("oneSample", "paired", "twoSample"), seed = NULL, parameter = NULL, pb = TRUE, nSim = 1000L, nBoot = 1000L )
computeBetaSafeT( deltaMin, nPlan, alpha = 0.05, alternative = c("twoSided", "greater", "less"), testType = c("oneSample", "paired", "twoSample"), seed = NULL, parameter = NULL, pb = TRUE, nSim = 1000L, nBoot = 1000L )
deltaMin |
numeric that defines the minimal relevant standardised effect size, the smallest effect size that we would the experiment to be able to detect. |
nPlan |
vector of max length 2 representing the planned sample sizes. |
alpha |
numeric in (0, 1) that specifies the tolerable type I error control –independent of n– that the designed test has to adhere to. Note that it also defines the rejection rule e10 > 1/alpha. |
alternative |
a character string specifying the alternative hypothesis must be one of "twoSided" (default), "greater" or "less". |
testType |
either one of "oneSample", "paired", "twoSample". |
seed |
integer, seed number. |
parameter |
optional test defining parameter. Default set to |
pb |
logical, if |
nSim |
integer > 0, the number of simulations needed to compute power or the number of samples paths for the safe z test under continuous monitoring. |
nBoot |
integer > 0 representing the number of bootstrap samples to assess the accuracy of approximation of the power, the number of samples for the safe z test under continuous monitoring, or for the computation of the logarithm of the implied target. |
a list which contains at least beta and an adapted bootObject of class
boot
.
computeBetaSafeT(deltaMin=0.7, 27, nSim=10)
computeBetaSafeT(deltaMin=0.7, 27, nSim=10)
Helper function: Computes the type II error based on the minimal clinically relevant mean difference and nPlan
computeBetaSafeZ( meanDiffMin, nPlan, alpha = 0.05, alternative = c("twoSided", "greater", "less"), sigma = 1, kappa = sigma, testType = c("oneSample", "paired", "twoSample"), parameter = NULL, pb = TRUE, nSim = 1000L, nBoot = 1000L )
computeBetaSafeZ( meanDiffMin, nPlan, alpha = 0.05, alternative = c("twoSided", "greater", "less"), sigma = 1, kappa = sigma, testType = c("oneSample", "paired", "twoSample"), parameter = NULL, pb = TRUE, nSim = 1000L, nBoot = 1000L )
meanDiffMin |
numeric that defines the minimal relevant mean difference, the smallest population mean that we would like to detect. |
nPlan |
optional numeric vector of length at most 2. When provided, it is used to find the safe test defining parameter phiS. Note that if the purpose is to plan based on nPlan alone, then both meanDiffMin and beta should be set to NULL. |
alpha |
numeric in (0, 1) that specifies the tolerable type I error control –independent on n– that the designed test has to adhere to. Note that it also defines the rejection rule e10 > 1/alpha. |
alternative |
a character string specifying the alternative hypothesis must be one of "twoSided" (default), "greater" or "less". |
sigma |
numeric > 0 representing the assumed population standard deviation used for the test. |
kappa |
the true population standard deviation. Default kappa=sigma. |
testType |
either one of "oneSample", "paired", "twoSample". |
parameter |
optional test defining parameter. Default set to |
pb |
logical, if |
nSim |
integer > 0, the number of simulations needed to compute power or the number of samples paths for the safe z test under continuous monitoring. |
nBoot |
integer > 0 representing the number of bootstrap samples to assess the accuracy of approximation of the power, the number of samples for the safe z test under continuous monitoring, or for the computation of the logarithm of the implied target. |
a list which contains at least beta and an adapted bootObject of class boot
.
computeBetaSafeZ(meanDiffMin=0.7, 20, nSim=10)
computeBetaSafeZ(meanDiffMin=0.7, 20, nSim=10)
Computes the bootObj for sequential sampling procedures regarding nPlan, beta, the implied target
computeBootObj( values, beta = NULL, nPlan = NULL, nBoot = 1000L, alpha = NULL, objType = c("nPlan", "nMean", "beta", "betaFromEValues", "logImpliedTarget", "expectedStopTime") )
computeBootObj( values, beta = NULL, nPlan = NULL, nBoot = 1000L, alpha = NULL, objType = c("nPlan", "nMean", "beta", "betaFromEValues", "logImpliedTarget", "expectedStopTime") )
values |
numeric vector. If objType equals "nPlan" or "beta" then values should be stopping times, if objType equals "logImpliedTarget" then values should be eValues. |
beta |
numeric in (0, 1) that specifies the tolerable type II error control necessary to calculate both "n" and "phiS". Note that 1-beta defines the power. |
nPlan |
integer > 0 representing the number of planned samples (for the first group). |
nBoot |
integer > 0 representing the number of bootstrap samples to assess the accuracy of approximation of the power, the planned sample size(s) of the safe test under continuous monitoring. |
alpha |
numeric in (0, 1) that specifies the tolerable type I error control –independent on n– that the designed test has to adhere to. Note that it also defines the rejection rule e10 > 1/alpha. |
objType |
character string either "nPlan", "nMean", "beta", "betaFromEValues", "expectedStopTime" or "logImpliedTarget". |
bootObj
computeBootObj(1:100, objType="nPlan", beta=0.3)
computeBootObj(1:100, objType="nPlan", beta=0.3)
Estimate an upper or lower bound for a safe confidence sequence on the logarithm of the odds ratio for two proportions.
computeConfidenceBoundForLogOddsTwoProportions( ya, yb, safeDesign, bound = c("lower", "upper"), deltaStart, deltaStop, precision )
computeConfidenceBoundForLogOddsTwoProportions( ya, yb, safeDesign, bound = c("lower", "upper"), deltaStart, deltaStop, precision )
ya |
positive observations/ events per data block in group a: a numeric with integer values
between (and including) 0 and |
yb |
positive observations/ events per data block in group b: a numeric with integer values
between (and including) 0 and |
safeDesign |
a 'safeDesign' object obtained through
|
bound |
type of bound to calculate; "lower" to get a lower bound on positive delta, "upper" to get an upper bound on negative delta. |
deltaStart |
starting value of the grid to search over for the bound on the confidence sequence (in practice: the interval). Numeric >0 when searching for a lower bound, numeric < 0 when searching for an upper bound. |
deltaStop |
end value of the grid to search over for the bound on the confidence sequence (in practice: the interval). Numeric >0 when searching for a lower bound, numeric < 0 when searching for an upper bound. |
precision |
precision of the grid between deltaStart and deltaStop. |
numeric: the established lower- or upper bound on the logarithm of the odds ratio between the groups
balancedSafeDesign <- designSafeTwoProportions(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, safeDesign = balancedSafeDesign, bound = "upper", deltaStart = -0.01, deltaStop = -4, precision = 20)
balancedSafeDesign <- designSafeTwoProportions(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, safeDesign = balancedSafeDesign, bound = "upper", deltaStart = -0.01, deltaStop = -4, precision = 20)
Estimate Lower and Upper Bounds on the Confidence Sequence (Interval) for the Difference Divergence Measure for Two Proportions
computeConfidenceBoundsForDifferenceTwoProportions( ya, yb, precision, safeDesign )
computeConfidenceBoundsForDifferenceTwoProportions( ya, yb, precision, safeDesign )
ya |
positive observations/ events per data block in group a: a numeric with integer values
between (and including) 0 and |
yb |
positive observations/ events per data block in group b: a numeric with integer values
between (and including) 0 and |
precision |
precision of the grid of differences to search over for the lower and upper bounds. |
safeDesign |
a 'safeDesign' object obtained through
|
list with found lower and upper bound.
balancedSafeDesign <- designSafeTwoProportions(na = 1, nb = 1, nBlocksPlan = 10, alpha = 0.05) ya <- c(1,1,1,1,1,1,1,1,0,1) yb <- c(0,0,0,0,1,0,0,0,0,0) computeConfidenceBoundsForDifferenceTwoProportions(ya = ya, yb = yb, precision = 20, safeDesign = balancedSafeDesign)
balancedSafeDesign <- designSafeTwoProportions(na = 1, nb = 1, nBlocksPlan = 10, alpha = 0.05) ya <- c(1,1,1,1,1,1,1,1,0,1) yb <- c(0,0,0,0,1,0,0,0,0,0) computeConfidenceBoundsForDifferenceTwoProportions(ya = ya, yb = yb, precision = 20, safeDesign = balancedSafeDesign)
Helper function: Computes the safe confidence sequence for the mean in a t-test
computeConfidenceIntervalT( meanObs, sdObs, nEff, nu, deltaS, ciValue = 0.95, g = NULL )
computeConfidenceIntervalT( meanObs, sdObs, nEff, nu, deltaS, ciValue = 0.95, g = NULL )
meanObs |
numeric, the observed mean. For two sample tests this is difference of the means. |
sdObs |
numeric, the observed standard deviation. For a two-sample test this is the root of the pooled variance. |
nEff |
numeric > 0, the effective sample size. For one sample test this is just n. |
nu |
numeric > 0, the degrees of freedom. |
deltaS |
numeric > 0, the safe test defining parameter. |
ciValue |
numeric is the ciValue-level of the confidence sequence. Default ciValue=0.95. |
g |
numeric > 0, used as the variance of the normal prior on the population delta
Default is |
numeric vector that contains the upper and lower bound of the safe confidence sequence
computeConfidenceIntervalT(meanObs=0.3, sdObs=2, nEff=12, nu=11, deltaS=0.4)
computeConfidenceIntervalT(meanObs=0.3, sdObs=2, nEff=12, nu=11, deltaS=0.4)
Helper function: Computes the safe confidence sequence for a z-test
computeConfidenceIntervalZ( nEff, meanObs, phiS, sigma = 1, ciValue = 0.95, alternative = "twoSided", a = NULL, g = NULL )
computeConfidenceIntervalZ( nEff, meanObs, phiS, sigma = 1, ciValue = 0.95, alternative = "twoSided", a = NULL, g = NULL )
nEff |
numeric > 0, the effective sample size. |
meanObs |
numeric, the observed mean. For two sample tests this is difference of the means. |
phiS |
numeric > 0, the safe test defining parameter. |
sigma |
numeric > 0 representing the assumed population standard deviation used for the test. |
ciValue |
numeric is the ciValue-level of the confidence sequence. Default ciValue=0.95. |
alternative |
a character string specifying the alternative hypothesis must be one of "twoSided" (default), "greater" or "less". |
a |
numeric, the centre of the normal prior on population mean (of the normal data). Default
is |
g |
numeric > 0, used to define g sigma^2 as the variance of the normal prior on the population
(of the normal data). Default is |
numeric vector that contains the upper and lower bound of the safe confidence sequence
computeConfidenceIntervalZ(nEff=15, meanObs=0.3, phiS=0.2)
computeConfidenceIntervalZ(nEff=15, meanObs=0.3, phiS=0.2)
Helper function: Computes the minimal clinically relevant standardised mean difference for the safe t-test nPlan and beta.
computeEsMinSafeT( nPlan, alpha = 0.05, beta = 0.2, alternative = c("twoSided", "greater", "less"), testType = c("oneSample", "paired", "twoSample"), lowN = 3, highN = 1e+06, ratio = 1 )
computeEsMinSafeT( nPlan, alpha = 0.05, beta = 0.2, alternative = c("twoSided", "greater", "less"), testType = c("oneSample", "paired", "twoSample"), lowN = 3, highN = 1e+06, ratio = 1 )
nPlan |
vector of max length 2 representing the planned sample sizes. |
alpha |
numeric in (0, 1) that specifies the tolerable type I error control –independent of n– that the designed test has to adhere to. Note that it also defines the rejection rule e10 > 1/alpha. |
beta |
numeric in (0, 1) that specifies the tolerable type II error control necessary to calculate both the sample sizes and deltaS, which defines the test. Note that 1-beta defines the power. |
alternative |
a character string specifying the alternative hypothesis must be one of "twoSided" (default), "greater" or "less". |
testType |
either one of "oneSample", "paired", "twoSample". |
lowN |
integer minimal sample size of the (first) sample when computing the power due to optional stopping. Default lowN is set 1. |
highN |
integer minimal sample size of the (first) sample when computing the power due to optional stopping. Default highN is set 1e6. |
ratio |
numeric > 0 representing the randomisation ratio of condition 2 over condition 1. If testType is not equal to "twoSample", or if nPlan is of length(1) then ratio=1. |
a list which contains at least nPlan and the phiS the parameter that defines the safe test
Helper function: Computes the type II error under optional stopping based on the minimal clinically relevant hazard ratio and the maximum number of nEvents.
computeLogrankBetaFrom( hrMin, nEvents, m0 = 50000L, m1 = 50000L, alpha = 0.05, alternative = c("twoSided", "greater", "less"), nSim = 1000L, nBoot = 10000L, groupSizePerTimeFunction = returnOne, parameter = NULL, pb = TRUE )
computeLogrankBetaFrom( hrMin, nEvents, m0 = 50000L, m1 = 50000L, alpha = 0.05, alternative = c("twoSided", "greater", "less"), nSim = 1000L, nBoot = 10000L, groupSizePerTimeFunction = returnOne, parameter = NULL, pb = TRUE )
hrMin |
numeric that defines the minimal relevant hazard ratio, the smallest hazard ratio that we want to detect. |
nEvents |
numeric > 0, targetted number of events. |
m0 |
Number of subjects in the control group 0/1 at the beginning of the trial, i.e., nPlan[1]. |
m1 |
Number of subjects in the treatment group 1/2 at the beginning of the trial, i.e., nPlan[2]. |
alpha |
numeric in (0, 1) that specifies the tolerable type I error control –independent on n– that the designed test has to adhere to. Note that it also defines the rejection rule e10 > 1/alpha. |
alternative |
a character string specifying the alternative hypothesis, which must be one of "twoSided" (default),"greater" or "less". The alternative is pitted against the null hypothesis of equality of the survival distributions. More specifically, let lambda1 be the hazard rate of group 1 (i.e., placebo), and lambda2 the hazard ratio of group 2 (i.e., treatment), then the null hypothesis states that the hazard ratio theta = lambda2/lambda1 = 1. If alternative = "less", the null hypothesis is compared to theta < 1, thus, lambda2 < lambda1, that is, the hazard of group 2 (i.e., treatment) is less than that of group 1 (i.e., placebo), hence, the treatment is beneficial. If alternative = "greater", then the null hypothesis is compared to theta > 1, thus, lambda2 > lambda1, hence, harm. |
nSim |
integer > 0, the number of simulations needed to compute power or the number of events for the exact safe logrank test under continuous monitoring |
nBoot |
integer > 0 representing the number of bootstrap samples to assess the accuracy of the approximation of power or nEvents for the exact safe logrank test under continuous monitoring |
groupSizePerTimeFunction |
A function without parameters and integer output. This function provides the number
of events at each time step. For instance, if |
parameter |
Numeric > 0, represents the safe tests defining thetaS. Default NULL so it's decided by the algorithm, typically, this equals hrMin, which corresponds to the GROW choice. |
pb |
logical, if |
a list which contains at least beta and an adapted bootObject of class boot
.
Muriel Felipe Perez-Ortiz and Alexander Ly
computeLogrankBetaFrom(hrMin=0.7, 300, nSim=10)
computeLogrankBetaFrom(hrMin=0.7, 300, nSim=10)
Helper function: Computes the planned sample size based on the minimal clinical relevant hazard ratio, alpha and beta under optional stopping.
computeLogrankNEvents( hrMin, beta, m0 = 50000, m1 = 50000, alpha = 0.05, alternative = c("twoSided", "greater", "less"), nSim = 1000L, nBoot = 1000L, groupSizePerTimeFunction = returnOne, nMax = Inf, parameter = NULL, digits = getOption("digits"), pb = TRUE )
computeLogrankNEvents( hrMin, beta, m0 = 50000, m1 = 50000, alpha = 0.05, alternative = c("twoSided", "greater", "less"), nSim = 1000L, nBoot = 1000L, groupSizePerTimeFunction = returnOne, nMax = Inf, parameter = NULL, digits = getOption("digits"), pb = TRUE )
hrMin |
numeric that defines the minimal relevant hazard ratio, the smallest hazard ratio that we want to detect. |
beta |
numeric in (0, 1) that specifies the tolerable type II error control necessary to calculate both "n" and "phiS". Note that 1-beta defines the power. |
m0 |
Number of subjects in the control group 0/1 at the beginning of the trial, i.e., nPlan[1]. |
m1 |
Number of subjects in the treatment group 1/2 at the beginning of the trial, i.e., nPlan[2]. |
alpha |
numeric in (0, 1) that specifies the tolerable type I error control –independent on n– that the designed test has to adhere to. Note that it also defines the rejection rule e10 > 1/alpha. |
alternative |
a character string specifying the alternative hypothesis, which must be one of "twoSided" (default),"greater" or "less". The alternative is pitted against the null hypothesis of equality of the survival distributions. More specifically, let lambda1 be the hazard rate of group 1 (i.e., placebo), and lambda2 the hazard ratio of group 2 (i.e., treatment), then the null hypothesis states that the hazard ratio theta = lambda2/lambda1 = 1. If alternative = "less", the null hypothesis is compared to theta < 1, thus, lambda2 < lambda1, that is, the hazard of group 2 (i.e., treatment) is less than that of group 1 (i.e., placebo), hence, the treatment is beneficial. If alternative = "greater", then the null hypothesis is compared to theta > 1, thus, lambda2 > lambda1, hence, harm. |
nSim |
integer > 0, the number of simulations needed to compute power or the number of events for the exact safe logrank test under continuous monitoring |
nBoot |
integer > 0 representing the number of bootstrap samples to assess the accuracy of the approximation of power or nEvents for the exact safe logrank test under continuous monitoring |
groupSizePerTimeFunction |
A function without parameters and integer output. This function provides the number
of events at each time step. For instance, if |
nMax |
An integer. Once nEvents hits nMax the experiment terminates, if it didn't stop due to threshold crossing crossing already. Default set to Inf. |
parameter |
Numeric > 0, represents the safe tests defining thetaS. Default NULL so it's decided by the algorithm, typically, this equals hrMin, which corresponds to the GROW choice. |
digits |
number of significant digits to be used. |
pb |
logical, if |
a list which contains at least nEvents and an adapted bootObject of class boot
.
Muriel Felipe Perez-Ortiz and Alexander Ly
computeLogrankNEvents(0.7, 0.2, nSim=10)
computeLogrankNEvents(0.7, 0.2, nSim=10)
This function was created to complement survdiff
from the
'survival' package, which is restricted to 'Surv' objects of type "right". Most likely
survdiff
is much faster
computeLogrankZ( survObj, group, computeZ = TRUE, computeExactE = FALSE, theta0 = 1, thetaS = NULL, ... )
computeLogrankZ( survObj, group, computeZ = TRUE, computeExactE = FALSE, theta0 = 1, thetaS = NULL, ... )
survObj |
a Surv object that is either of type |
group |
a grouping factor with 2 levels |
computeZ |
logical. If |
computeExactE |
logical. If |
theta0 |
numeric > 0 used only for the e-value, i.e., if computeExactE is |
thetaS |
numeric > 0 used only for the e-value, i.e., if computeExactE is |
... |
further arguments to be passed to or from methods. |
Returns a list containing at least the following components:
the number of events.
the observed logrank statistic.
vector of observed minus expected.
vector of hypergeometric variances.
vector at which the events occurred.
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)
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)
Computes the smallest mean difference that is detectable with chance 1-beta, for the provided sample size
computeMinEsBatchSafeZ( nPlan, alpha = 0.05, beta = 0.2, sigma = 1, kappa = sigma, alternative = c("twoSided", "greater", "less"), testType = c("oneSample", "paired", "twoSample"), parameter = NULL, maxIter = 10 )
computeMinEsBatchSafeZ( nPlan, alpha = 0.05, beta = 0.2, sigma = 1, kappa = sigma, alternative = c("twoSided", "greater", "less"), testType = c("oneSample", "paired", "twoSample"), parameter = NULL, maxIter = 10 )
nPlan |
optional numeric vector of length at most 2. When provided, it is used to find the safe test defining parameter phiS. Note that if the purpose is to plan based on nPlan alone, then both meanDiffMin and beta should be set to NULL. |
alpha |
numeric in (0, 1) that specifies the tolerable type I error control –independent on n– that the designed test has to adhere to. Note that it also defines the rejection rule e10 > 1/alpha. |
beta |
numeric in (0, 1) that specifies the tolerable type II error control necessary to calculate both "n" and "phiS". Note that 1-beta defines the power. |
sigma |
numeric > 0 representing the assumed population standard deviation used for the test. |
kappa |
the true population standard deviation. Default kappa=sigma. |
alternative |
a character string specifying the alternative hypothesis must be one of "twoSided" (default), "greater" or "less". |
testType |
either one of "oneSample", "paired", "twoSample". |
parameter |
optional test defining parameter. Default set to |
maxIter |
maximum number of iterations in the optimisation process for two-sided designs |
numeric > 0 that represents the minimal detectable mean difference
Help function to compute the effective sample size based on a length 2 vector of samples
computeNEff(n, testType = c("oneSample", "paired", "twoSample"), silent = TRUE)
computeNEff(n, testType = c("oneSample", "paired", "twoSample"), silent = TRUE)
n |
vector of length at most 2 representing the sample sizes of the first and second group |
testType |
either one of "oneSample", "paired", "twoSample". |
silent |
logical, if true, then turn off warnings |
a numeric that represents the effective sample size.
Helper function: Computes the planned sample size for the safe t-test based on the minimal clinically relevant standardised effect size, alpha and beta.
computeNPlanBatchSafeT( deltaMin, alpha = 0.05, beta = 0.2, alternative = c("twoSided", "greater", "less"), testType = c("oneSample", "paired", "twoSample"), lowN = 3, highN = 1e+06, ratio = 1 )
computeNPlanBatchSafeT( deltaMin, alpha = 0.05, beta = 0.2, alternative = c("twoSided", "greater", "less"), testType = c("oneSample", "paired", "twoSample"), lowN = 3, highN = 1e+06, ratio = 1 )
deltaMin |
numeric that defines the minimal relevant standardised effect size, the smallest effect size that we would the experiment to be able to detect. |
alpha |
numeric in (0, 1) that specifies the tolerable type I error control –independent of n– that the designed test has to adhere to. Note that it also defines the rejection rule e10 > 1/alpha. |
beta |
numeric in (0, 1) that specifies the tolerable type II error control necessary to calculate both the sample sizes and deltaS, which defines the test. Note that 1-beta defines the power. |
alternative |
a character string specifying the alternative hypothesis must be one of "twoSided" (default), "greater" or "less". |
testType |
either one of "oneSample", "paired", "twoSample". |
lowN |
integer minimal sample size of the (first) sample when computing the power due to optional stopping. Default lowN is set 1. |
highN |
integer minimal sample size of the (first) sample when computing the power due to optional stopping. Default highN is set 1e6. |
ratio |
numeric > 0 representing the randomisation ratio of condition 2 over condition 1. If testType is not equal to "twoSample", or if nPlan is of length(1) then ratio=1. |
a list which contains at least nPlan and the phiS the parameter that defines the safe test
Helper function: Computes the planned sample size based on the minimal clinical relevant mean difference, alpha and beta.
computeNPlanBatchSafeZ( meanDiffMin, alpha = 0.05, beta = 0.2, sigma = 1, kappa = sigma, alternative = c("twoSided", "greater", "less"), testType = c("oneSample", "paired", "twoSample"), tol = 1e-05, highN = 1e+06, ratio = 1, parameter = NULL, grow = TRUE )
computeNPlanBatchSafeZ( meanDiffMin, alpha = 0.05, beta = 0.2, sigma = 1, kappa = sigma, alternative = c("twoSided", "greater", "less"), testType = c("oneSample", "paired", "twoSample"), tol = 1e-05, highN = 1e+06, ratio = 1, parameter = NULL, grow = TRUE )
meanDiffMin |
numeric that defines the minimal relevant mean difference, the smallest population mean that we would like to detect. |
alpha |
numeric in (0, 1) that specifies the tolerable type I error control –independent on n– that the designed test has to adhere to. Note that it also defines the rejection rule e10 > 1/alpha. |
beta |
numeric in (0, 1) that specifies the tolerable type II error control necessary to calculate both "n" and "phiS". Note that 1-beta defines the power. |
sigma |
numeric > 0 representing the assumed population standard deviation used for the test. |
kappa |
the true population standard deviation. Default kappa=sigma. |
alternative |
a character string specifying the alternative hypothesis must be one of "twoSided" (default), "greater" or "less". |
testType |
either one of "oneSample", "paired", "twoSample". |
tol |
a number that defines the stepsizes between the lowParam and highParam. |
highN |
integer that defines the largest n of our search space for n. This might be the largest n that we are able to fund. |
ratio |
numeric > 0 representing the randomisation ratio of condition 2 over condition 1. If testType is not equal to "twoSample", or if nPlan is of length(1) then ratio=1. |
parameter |
optional test defining parameter. Default set to |
grow |
logical, default set to |
a list which contains at least nPlan and the phiS, that is, the parameter that defines the safe test.
Helper function: Computes the planned sample size of the safe t-test based on the minimal clinical relevant standardised mean difference.
computeNPlanSafeT( deltaMin, beta = 0.2, alpha = 0.05, alternative = c("twoSided", "less", "greater"), testType = c("oneSample", "paired", "twoSample"), lowN = 3, highN = 1e+06, ratio = 1, nSim = 1000L, nBoot = 1000L, parameter = NULL, pb = TRUE, nMax = 1e+06, seed = NULL )
computeNPlanSafeT( deltaMin, beta = 0.2, alpha = 0.05, alternative = c("twoSided", "less", "greater"), testType = c("oneSample", "paired", "twoSample"), lowN = 3, highN = 1e+06, ratio = 1, nSim = 1000L, nBoot = 1000L, parameter = NULL, pb = TRUE, nMax = 1e+06, seed = NULL )
deltaMin |
numeric that defines the minimal relevant standardised effect size, the smallest effect size that we would the experiment to be able to detect. |
beta |
numeric in (0, 1) that specifies the tolerable type II error control necessary to calculate both the sample sizes and deltaS, which defines the test. Note that 1-beta defines the power. |
alpha |
numeric in (0, 1) that specifies the tolerable type I error control –independent of n– that the designed test has to adhere to. Note that it also defines the rejection rule e10 > 1/alpha. |
alternative |
a character string specifying the alternative hypothesis must be one of "twoSided" (default), "greater" or "less". |
testType |
either one of "oneSample", "paired", "twoSample". |
lowN |
integer minimal sample size of the (first) sample when computing the power due to optional stopping. Default lowN is set 1. |
highN |
integer minimal sample size of the (first) sample when computing the power due to optional stopping. Default highN is set 1e6. |
ratio |
numeric > 0 representing the randomisation ratio of condition 2 over condition 1. If testType is not equal to "twoSample", or if nPlan is of length(1) then ratio=1. |
nSim |
integer > 0, the number of simulations needed to compute power or the number of samples paths for the safe z test under continuous monitoring. |
nBoot |
integer > 0 representing the number of bootstrap samples to assess the accuracy of approximation of the power, the number of samples for the safe z test under continuous monitoring, or for the computation of the logarithm of the implied target. |
parameter |
optional test defining parameter. Default set to |
pb |
logical, if |
nMax |
integer > 0, maximum sample size of the (first) sample in each sample path. |
seed |
integer, seed number. |
a list which contains at least nPlan and an adapted bootObject of class boot
.
computeNPlanSafeT(0.7, 0.2, nSim=10)
computeNPlanSafeT(0.7, 0.2, nSim=10)
Helper function: Computes the planned sample size based on the minimal clinical relevant mean difference, alpha and beta
computeNPlanSafeZ( meanDiffMin, beta = 0.2, alpha = 0.05, alternative = c("twoSided", "less", "greater"), testType = c("oneSample", "paired", "twoSample"), sigma = 1, kappa = sigma, ratio = 1, nSim = 1000L, nBoot = 1000L, parameter = NULL, pb = TRUE, nMax = 1e+08 )
computeNPlanSafeZ( meanDiffMin, beta = 0.2, alpha = 0.05, alternative = c("twoSided", "less", "greater"), testType = c("oneSample", "paired", "twoSample"), sigma = 1, kappa = sigma, ratio = 1, nSim = 1000L, nBoot = 1000L, parameter = NULL, pb = TRUE, nMax = 1e+08 )
meanDiffMin |
numeric that defines the minimal relevant mean difference, the smallest population mean that we would like to detect. |
beta |
numeric in (0, 1) that specifies the tolerable type II error control necessary to calculate both "n" and "phiS". Note that 1-beta defines the power. |
alpha |
numeric in (0, 1) that specifies the tolerable type I error control –independent on n– that the designed test has to adhere to. Note that it also defines the rejection rule e10 > 1/alpha. |
alternative |
a character string specifying the alternative hypothesis must be one of "twoSided" (default), "greater" or "less". |
testType |
either one of "oneSample", "paired", "twoSample". |
sigma |
numeric > 0 representing the assumed population standard deviation used for the test. |
kappa |
the true population standard deviation. Default kappa=sigma. |
ratio |
numeric > 0 representing the randomisation ratio of condition 2 over condition 1. If testType is not equal to "twoSample", or if nPlan is of length(1) then ratio=1. |
nSim |
integer > 0, the number of simulations needed to compute power or the number of samples paths for the safe z test under continuous monitoring. |
nBoot |
integer > 0 representing the number of bootstrap samples to assess the accuracy of approximation of the power, the number of samples for the safe z test under continuous monitoring, or for the computation of the logarithm of the implied target. |
parameter |
optional test defining parameter. Default set to |
pb |
logical, if |
nMax |
integer > 0, maximum sample size of the (first) sample in each sample path. |
a list which contains at least nPlan and an adapted bootObject of class boot
.
computeNPlanSafeZ(0.7, 0.2, nSim=10)
computeNPlanSafeZ(0.7, 0.2, nSim=10)
Computes the sufficient statistics needed to compute 'logrankSingleZ'
computeStatsForLogrank( survDataFrame, y0Index, y1Index, timeNow, timeBefore, survType = "right", ... )
computeStatsForLogrank( survDataFrame, y0Index, y1Index, timeNow, timeBefore, survType = "right", ... )
survDataFrame |
a 'Surv' object converted to a matrix, then to a data.frame |
y0Index |
vector of integers corresponding to the control group |
y1Index |
vector of integers corresponding to the treatment group |
timeNow |
numeric, current time |
timeBefore |
numeric, previous time |
survType |
character, either "right" or "counting" (left truncated, right censored) |
... |
further arguments to be passed to or from methods. |
Returns a list containing at least the following components:
number of observations in the control group.
number of observations in the treatment group.
total number of participants in the control group.
total number of participants in the treatment group.
#'
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) survDataFrame <- as.data.frame(as.matrix(survObj)) y0Index <- which(data$group=="P") y1Index <- which(data$group=="T") timeNow <- 4 timeBefore <- 0 computeStatsForLogrank(survDataFrame, y0Index, y1Index, timeNow, timeBefore) timeNow <- 13 timeBefore <- 4 computeStatsForLogrank(survDataFrame, y0Index, y1Index, timeNow, timeBefore)
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) survDataFrame <- as.data.frame(as.matrix(survObj)) y0Index <- which(data$group=="P") y1Index <- which(data$group=="T") timeNow <- 4 timeBefore <- 0 computeStatsForLogrank(survDataFrame, y0Index, y1Index, timeNow, timeBefore) timeNow <- 13 timeBefore <- 4 computeStatsForLogrank(survDataFrame, y0Index, y1Index, timeNow, timeBefore)
Helper function that outputs the sample sizes, effective sample sizes and the degrees of freedom depending on the type of t-test. Also used for z-tests.
defineTTestN( lowN = 3, highN = 100, ratio = 1, testType = c("oneSample", "paired", "twoSample") )
defineTTestN( lowN = 3, highN = 100, ratio = 1, testType = c("oneSample", "paired", "twoSample") )
lowN |
integer minimal sample size of the (first) sample when computing the power due to optional stopping. Default lowN is set 1. |
highN |
integer minimal sample size of the (first) sample when computing the power due to optional stopping. Default highN is set 1e6. |
ratio |
numeric > 0 representing the randomisation ratio of condition 2 over condition 1. If testType is not equal to "twoSample", or if nPlan is of length(1) then ratio=1. |
testType |
either one of "oneSample", "paired", "twoSample". |
Returns the sample sizes and degrees of freedom.
Computes the number of samples necessary to reach a tolerable type I and type II error for the frequentist t-test.
designFreqT( deltaMin, alpha = 0.05, beta = 0.2, alternative = c("twoSided", "greater", "less"), h0 = 0, testType = c("oneSample", "paired", "twoSample"), ... )
designFreqT( deltaMin, alpha = 0.05, beta = 0.2, alternative = c("twoSided", "greater", "less"), h0 = 0, testType = c("oneSample", "paired", "twoSample"), ... )
deltaMin |
numeric that defines the minimal relevant standardised effect size, the smallest effect size that we would the experiment to be able to detect. |
alpha |
numeric in (0, 1) that specifies the tolerable type I error control –independent of n– that the designed test has to adhere to. Note that it also defines the rejection rule e10 > 1/alpha. |
beta |
numeric in (0, 1) that specifies the tolerable type II error control necessary to calculate both the sample sizes and deltaS, which defines the test. Note that 1-beta defines the power. |
alternative |
a character string specifying the alternative hypothesis must be one of "twoSided" (default), "greater" or "less". |
h0 |
a number indicating the hypothesised true value of the mean under the null. For the moment h0=0. |
testType |
either one of "oneSample", "paired", "twoSample". |
... |
further arguments to be passed to or from methods, but mainly to perform do.calls. |
Returns an object of class 'freqTDesign'. An object of class 'freqTDesign' is a list containing at least the following components:
the planned sample size(s).
the minimal clinically relevant standardised effect size provided by the user.
the tolerable type I error provided by the user.
the tolerable type II error provided by the user.
the smallest n of the search space for n provided by the user.
the largest n of the search space for n provided by the user.
any of "oneSample", "paired", "twoSample" provided by the user.
any of "twoSided", "greater", "less" provided by the user.
designFreqT(0.5)
designFreqT(0.5)
Computes the number of samples necessary to reach a tolerable type I and type II error for the frequentist z-test.
designFreqZ( meanDiffMin, alternative = c("twoSided", "greater", "less"), alpha = 0.05, beta = 0.2, testType = c("oneSample", "paired", "twoSample"), ratio = 1, sigma = 1, h0 = 0, kappa = sigma, lowN = 3L, highN = 100L, ... )
designFreqZ( meanDiffMin, alternative = c("twoSided", "greater", "less"), alpha = 0.05, beta = 0.2, testType = c("oneSample", "paired", "twoSample"), ratio = 1, sigma = 1, h0 = 0, kappa = sigma, lowN = 3L, highN = 100L, ... )
meanDiffMin |
numeric that defines the minimal relevant mean difference, the smallest population mean that we would like to detect. |
alternative |
a character string specifying the alternative hypothesis must be one of "twoSided" (default), "greater" or "less". |
alpha |
numeric in (0, 1) that specifies the tolerable type I error control –independent on n– that the designed test has to adhere to. Note that it also defines the rejection rule e10 > 1/alpha. |
beta |
numeric in (0, 1) that specifies the tolerable type II error control necessary to calculate both "n" and "phiS". Note that 1-beta defines the power. |
testType |
either one of "oneSample", "paired", "twoSample". |
ratio |
numeric > 0 representing the randomisation ratio of condition 2 over condition 1. If testType is not equal to "twoSample", or if nPlan is of length(1) then ratio=1. |
sigma |
numeric > 0 representing the assumed population standard deviation used for the test. |
h0 |
numeric, represents the null hypothesis, default h0=0. |
kappa |
the true population standard deviation. Default kappa=sigma. |
lowN |
integer that defines the smallest n of our search space for n. |
highN |
integer that defines the largest n of our search space for n. This might be the largest n that we are able to fund. |
... |
further arguments to be passed to or from methods. |
returns a 'freqZDesign' object.
freqDesign <- designFreqZ(meanDiffMin = 0.5, highN = 100) freqDesign$nPlan freqDesign2 <- designFreqZ(meanDiffMin = 0.2, lowN = 32, highN = 200) freqDesign2$nPlan
freqDesign <- designFreqZ(meanDiffMin = 0.5, highN = 100) freqDesign$nPlan freqDesign2 <- designFreqZ(meanDiffMin = 0.2, lowN = 32, highN = 200) freqDesign2$nPlan
Designs a safe experiment for a prespecified tolerable type I error based on planned sample size(s), which are fixed ahead of time. Outputs a list that includes the deltaS, i.e., the safe test defining parameter.
designPilotSafeT( nPlan = 50, alpha = 0.05, alternative = c("twoSided", "greater", "less"), h0 = 0, lowParam = 0.01, highParam = 1.2, tol = 0.01, inverseMethod = TRUE, logging = FALSE, paired = FALSE, maxIter = 10 )
designPilotSafeT( nPlan = 50, alpha = 0.05, alternative = c("twoSided", "greater", "less"), h0 = 0, lowParam = 0.01, highParam = 1.2, tol = 0.01, inverseMethod = TRUE, logging = FALSE, paired = FALSE, maxIter = 10 )
nPlan |
the planned sample size(s). |
alpha |
numeric in (0, 1) that specifies the tolerable type I error control –independent of n– that the designed test has to adhere to. Note that it also defines the rejection rule e10 > 1/alpha. |
alternative |
a character string specifying the alternative hypothesis must be one of "twoSided" (default), "greater" or "less". |
h0 |
a number indicating the hypothesised true value of the mean under the null. For the moment h0=0. |
lowParam |
numeric defining the smallest delta of the search space for the test-defining deltaS for scenario 3. Currently not yet in use. |
highParam |
numeric defining the largest delta of the search space for the test-defining deltaS for scenario 3. Currently not yet in use. |
tol |
a number that defines the stepsizes between the lowParam and highParam. |
inverseMethod |
logical, always |
logging |
logical, if |
paired |
logical, if |
maxIter |
numeric > 0, the maximum number of iterations of adjustment to the candidate set from lowParam to highParam, if the minimum is not found. |
Returns an object of class 'safeDesign'. An object of class 'safeDesign' is a list containing at least the following components:
the planned sample size(s).
the safe test defining parameter. Here deltaS.
the minimal clinically relevant standardised effect size provided by the user.
the tolerable type I error provided by the user.
the tolerable type II error provided by the user.
any of "twoSided", "greater", "less" provided by the user.
any of "oneSample", "paired", "twoSample" provided by the user.
logical, TRUE
if "paired", FALSE
otherwise.
the specified hypothesised value of the mean or mean difference depending on whether it was a one-sample or a two-sample test.
default is 1. Different from 1, whenever testType equals "twoSample", then it defines ratio between the planned randomisation of condition 2 over condition 1.
the smallest n of the search space for n provided by the user.
the largest n of the search space for n provided by the user.
the smallest delta of the search space for delta provided by the user.
the largest delta of the search space for delta provided by the user.
the step size between lowParam and highParam provided by the user.
FALSE
(default) specified by the user to indicate that the design is not a pilot study.
the expression with which this function is called.
designPilotSafeT(nPlan=30)
designPilotSafeT(nPlan=30)
Designs a safe experiment for a prespecified tolerable type I error based on planned sample size(s), which are fixed ahead of time. Outputs a list that includes phiS, i.e., the safe test defining parameter.
designPilotSafeZ( nPlan, alternative = c("twoSided", "greater", "less"), alpha = 0.05, sigma = 1, h0 = 0, kappa = sigma, tol = 1e-05, paired = FALSE, parameter = NULL )
designPilotSafeZ( nPlan, alternative = c("twoSided", "greater", "less"), alpha = 0.05, sigma = 1, h0 = 0, kappa = sigma, tol = 1e-05, paired = FALSE, parameter = NULL )
nPlan |
optional numeric vector of length at most 2. When provided, it is used to find the safe test defining parameter phiS. Note that if the purpose is to plan based on nPlan alone, then both meanDiffMin and beta should be set to NULL. |
alternative |
a character string specifying the alternative hypothesis must be one of "twoSided" (default), "greater" or "less". |
alpha |
numeric in (0, 1) that specifies the tolerable type I error control –independent on n– that the designed test has to adhere to. Note that it also defines the rejection rule e10 > 1/alpha. |
sigma |
numeric > 0 representing the assumed population standard deviation used for the test. |
h0 |
numeric, represents the null hypothesis, default h0=0. |
kappa |
the true population standard deviation. Default kappa=sigma. |
tol |
a number that defines the stepsizes between the lowParam and highParam. |
paired |
logical, if |
parameter |
optional test defining parameter. Default set to |
Returns a 'safeDesign' object
the sample size(s) to plan for. Provided by the user.
the safe test defining parameter. Here phiS.
NULL
no minimally clinically relevant effect size provided.
the tolerable type I error provided by the user.
NULL
, no tolerable type II error specified.
any of "twoSided", "greater", "less" provided by the user.
any of "oneSample", "paired", "twoSample" effectively provided by the user.
logical, TRUE
if "paired", FALSE
otherwise.
the assumed population standard deviation used for the test provided by the user.
the true population standard deviation, typically, sigma=kappa.
default is 1. Different from 1, whenever testType equals "twoSample", then it defines ratio between the planned randomisation of condition 2 over condition 1.
the step size between parameter values in the candidate space.
logical, specifying whether it's a pilot design.
the expression with which this function is called.
designPilotSafeZ(nPlan=30, alpha = 0.05)
designPilotSafeZ(nPlan=30, alpha = 0.05)
A designed experiment requires (1) an anticipated number of events nEvents, or even better nPlan, the number of
participants to be recruited in the study, and (2) the parameter of the safe test, i.e., thetaS. Provided with a
clinically relevant minimal hazard ratio hrMin, this function outputs thetaS = hrMin as the safe test defining
parameter in accordance to the GROW criterion. If a tolerable type II error beta is provided then nEvents can be
sampled. The sampled nEvents is then the smallest nEvents for which hrMin is found with power of at least 1 - beta
under optional stopping. If exact equal FALSE
, then the computations exploit the local asymptotic normal
approximation to sampling distribution of the logrank test derived by Schoenfeld (1981).
designSafeLogrank( hrMin = NULL, beta = NULL, nEvents = NULL, h0 = 1, alternative = c("twoSided", "greater", "less"), alpha = 0.05, ratio = 1, exact = TRUE, tol = 1e-05, m0 = 50000L, m1 = 50000L, nSim = 1000L, nBoot = 10000L, parameter = NULL, groupSizePerTimeFunction = returnOne, pb = TRUE, ... )
designSafeLogrank( hrMin = NULL, beta = NULL, nEvents = NULL, h0 = 1, alternative = c("twoSided", "greater", "less"), alpha = 0.05, ratio = 1, exact = TRUE, tol = 1e-05, m0 = 50000L, m1 = 50000L, nSim = 1000L, nBoot = 10000L, parameter = NULL, groupSizePerTimeFunction = returnOne, pb = TRUE, ... )
hrMin |
numeric that defines the minimal relevant hazard ratio, the smallest hazard ratio that we want to detect. |
beta |
numeric in (0, 1) that specifies the tolerable type II error control necessary to calculate both "n" and "phiS". Note that 1-beta defines the power. |
nEvents |
numeric > 0, targetted number of events. |
h0 |
numeric > 0, represents the null hypothesis, default h0=1. |
alternative |
a character string specifying the alternative hypothesis, which must be one of "twoSided" (default),"greater" or "less". The alternative is pitted against the null hypothesis of equality of the survival distributions. More specifically, let lambda1 be the hazard rate of group 1 (i.e., placebo), and lambda2 the hazard ratio of group 2 (i.e., treatment), then the null hypothesis states that the hazard ratio theta = lambda2/lambda1 = 1. If alternative = "less", the null hypothesis is compared to theta < 1, thus, lambda2 < lambda1, that is, the hazard of group 2 (i.e., treatment) is less than that of group 1 (i.e., placebo), hence, the treatment is beneficial. If alternative = "greater", then the null hypothesis is compared to theta > 1, thus, lambda2 > lambda1, hence, harm. |
alpha |
numeric in (0, 1) that specifies the tolerable type I error control –independent on n– that the designed test has to adhere to. Note that it also defines the rejection rule e10 > 1/alpha. |
ratio |
numeric > 0 representing the randomisation ratio of condition 2 (Treatment) over condition 1 (Placebo),
thus, m1/m0. Note that m1 and m0 are not used to specify ratio. Ratio is only used when |
exact |
a logical indicating whether the design should be based on the exact safe logrank test based on the
hypergeometric likelihood. Default is |
tol |
a number that defines the stepsizes between the lowParam and highParam. |
m0 |
Number of subjects in the control group 0/1 at the beginning of the trial, i.e., nPlan[1]. |
m1 |
Number of subjects in the treatment group 1/2 at the beginning of the trial, i.e., nPlan[2]. |
nSim |
integer > 0, the number of simulations needed to compute power or the number of events for the exact safe logrank test under continuous monitoring |
nBoot |
integer > 0 representing the number of bootstrap samples to assess the accuracy of the approximation of power or nEvents for the exact safe logrank test under continuous monitoring |
parameter |
Numeric > 0, represents the safe tests defining thetaS. Default NULL so it's decided by the algorithm, typically, this equals hrMin, which corresponds to the GROW choice. |
groupSizePerTimeFunction |
A function without parameters and integer output. This function provides the number
of events at each time step. For instance, if |
pb |
logical, if |
... |
further arguments to be passed to or from methods. |
Returns a safeDesign object that includes:
the anticipated number of events, either (1) specified by the user, or (2) computed based on beta and thetaMin.
the parameter that defines the safe test. Here log(thetaS).
the minimally clinically relevant hazard ratio specified by the user.
the tolerable type I error provided by the user.
the tolerable type II error provided by the user.
any of "twoSided", "greater", "less" provided by the user.
"logrank".
default is 1. It defines the ratio between the planned randomisation of condition 2 over condition 1.
FALSE
to indicate that the design is not a pilot study.
the expression with which this function is called.
Schoenfeld, D. (1981). The asymptotic properties of nonparametric tests for comparing survival distributions. Biometrika, 68(1), 316-319.
designSafeLogrank(hrMin=0.7) designSafeLogrank(hrMin=0.7, zApprox=TRUE) designSafeLogrank(hrMin=0.7, beta=0.3, nSim=10) designSafeLogrank(hrMin=0.7, nEvents=190, nSim=10)
designSafeLogrank(hrMin=0.7) designSafeLogrank(hrMin=0.7, zApprox=TRUE) designSafeLogrank(hrMin=0.7, beta=0.3, nSim=10) designSafeLogrank(hrMin=0.7, nEvents=190, nSim=10)
A designed experiment requires (1) a sample size nPlan to plan for, and (2) the parameter of the safe test, i.e., deltaS. If nPlan is provided, then only the safe test defining parameter deltaS needs to determined. That resulting deltaS leads to an (approximately) most powerful safe test. Typically, nPlan is unknown and the user has to specify (i) a tolerable type II error beta, and (ii) a clinically relevant minimal population standardised effect size deltaMin. The procedure finds the smallest nPlan for which deltaMin is found with power of at least 1 - beta.
designSafeT( deltaMin = NULL, beta = NULL, nPlan = NULL, alpha = 0.05, h0 = 0, alternative = c("twoSided", "greater", "less"), lowN = 3L, highN = 1000000L, lowParam = 0.01, highParam = 1.5, tol = 0.01, testType = c("oneSample", "paired", "twoSample"), ratio = 1, nSim = 1000L, nBoot = 1000L, parameter = NULL, pb = TRUE, seed = NULL, ... )
designSafeT( deltaMin = NULL, beta = NULL, nPlan = NULL, alpha = 0.05, h0 = 0, alternative = c("twoSided", "greater", "less"), lowN = 3L, highN = 1000000L, lowParam = 0.01, highParam = 1.5, tol = 0.01, testType = c("oneSample", "paired", "twoSample"), ratio = 1, nSim = 1000L, nBoot = 1000L, parameter = NULL, pb = TRUE, seed = NULL, ... )
deltaMin |
numeric that defines the minimal relevant standardised effect size, the smallest effect size that we would the experiment to be able to detect. |
beta |
numeric in (0, 1) that specifies the tolerable type II error control necessary to calculate both the sample sizes and deltaS, which defines the test. Note that 1-beta defines the power. |
nPlan |
vector of max length 2 representing the planned sample sizes. |
alpha |
numeric in (0, 1) that specifies the tolerable type I error control –independent of n– that the designed test has to adhere to. Note that it also defines the rejection rule e10 > 1/alpha. |
h0 |
a number indicating the hypothesised true value of the mean under the null. For the moment h0=0. |
alternative |
a character string specifying the alternative hypothesis must be one of "twoSided" (default), "greater" or "less". |
lowN |
integer minimal sample size of the (first) sample when computing the power due to optional stopping. Default lowN is set 1. |
highN |
integer minimal sample size of the (first) sample when computing the power due to optional stopping. Default highN is set 1e6. |
lowParam |
numeric defining the smallest delta of the search space for the test-defining deltaS for scenario 3. Currently not yet in use. |
highParam |
numeric defining the largest delta of the search space for the test-defining deltaS for scenario 3. Currently not yet in use. |
tol |
a number that defines the stepsizes between the lowParam and highParam. |
testType |
either one of "oneSample", "paired", "twoSample". |
ratio |
numeric > 0 representing the randomisation ratio of condition 2 over condition 1. If testType is not equal to "twoSample", or if nPlan is of length(1) then ratio=1. |
nSim |
integer > 0, the number of simulations needed to compute power or the number of samples paths for the safe z test under continuous monitoring. |
nBoot |
integer > 0 representing the number of bootstrap samples to assess the accuracy of approximation of the power, the number of samples for the safe z test under continuous monitoring, or for the computation of the logarithm of the implied target. |
parameter |
optional test defining parameter. Default set to |
pb |
logical, if |
seed |
integer, seed number. |
... |
further arguments to be passed to or from methods, but mainly to perform do.calls. |
Returns an object of class 'safeDesign'. An object of class 'safeDesign' is a list containing at least the following components:
the planned sample size(s).
the safe test defining parameter. Here deltaS.
the minimal clinically relevant standardised effect size provided by the user.
the tolerable type I error provided by the user.
the tolerable type II error provided by the user.
any of "twoSided", "greater", "less" provided by the user.
any of "oneSample", "paired", "twoSample" provided by the user.
logical, TRUE
if "paired", FALSE
otherwise.
the specified hypothesised value of the mean or mean difference depending on whether it was a one-sample or a two-sample test.
default is 1. Different from 1, whenever testType equals "twoSample", then it defines ratio between the planned randomisation of condition 2 over condition 1.
the smallest n of the search space for n provided by the user.
the largest n of the search space for n provided by the user.
the smallest delta of the search space for delta provided by the user.
the largest delta of the search space for delta provided by the user.
the step size between lowParam and highParam provided by the user.
FALSE
(default) specified by the user to indicate that the design is not a pilot study.
the expression with which this function is called.
designObj <- designSafeT(deltaMin=0.8, alpha=0.03, alternative="greater") designObj # "Scenario 1.a": Minimal clinically relevant standarised mean difference and tolerable type # II error also known. Goal: find nPlan. designObj <- designSafeT(deltaMin=0.8, alpha=0.03, beta=0.4, nSim=10, alternative="greater") designObj # "Scenario 2": Minimal clinically relevant standarised mean difference and nPlan known. # Goal: find the power, hence, the type II error of the procedure under optional stopping. designObj <- designSafeT(deltaMin=0.8, alpha=0.03, nPlan=16, nSim=10, alternative="greater") designObj
designObj <- designSafeT(deltaMin=0.8, alpha=0.03, alternative="greater") designObj # "Scenario 1.a": Minimal clinically relevant standarised mean difference and tolerable type # II error also known. Goal: find nPlan. designObj <- designSafeT(deltaMin=0.8, alpha=0.03, beta=0.4, nSim=10, alternative="greater") designObj # "Scenario 2": Minimal clinically relevant standarised mean difference and nPlan known. # Goal: find the power, hence, the type II error of the procedure under optional stopping. designObj <- designSafeT(deltaMin=0.8, alpha=0.03, nPlan=16, nSim=10, alternative="greater") designObj
The design requires the number of observations one expects to collect in each group in each data block.
I.e., when one expects balanced data, one could choose na = nb = 1
and would be allowed to analyse
the data stream each time a new observation in both groups has come in. The best results in terms of power
are achieved when the data blocks are chosen as small as possible, as this allows for analysing and updating
the safe test as often as possible, to fit the data best.
Further, the design requires two out of the following three parameters to be known:
the power one aims to achieve (1 - beta
),
the minimal relevant difference between the groups (delta
)
the number of blocks planned (nBlocksPlan
),
where the unknown out of the three will be estimated. In the case of an exploratory "pilot" analysis, one can also only provide the number of blocks planned.
designSafeTwoProportions( na, nb, nBlocksPlan = NULL, beta = NULL, delta = NULL, alternativeRestriction = c("none", "difference", "logOddsRatio"), alpha = 0.05, pilot = "FALSE", hyperParameterValues = NULL, previousSafeTestResult = NULL, M = 1000, simThetaAMin = NULL, simThetaAMax = NULL )
designSafeTwoProportions( na, nb, nBlocksPlan = NULL, beta = NULL, delta = NULL, alternativeRestriction = c("none", "difference", "logOddsRatio"), alpha = 0.05, pilot = "FALSE", hyperParameterValues = NULL, previousSafeTestResult = NULL, M = 1000, simThetaAMin = NULL, simThetaAMax = NULL )
na |
number of observations in group a per data block |
nb |
number of observations in group b per data block |
nBlocksPlan |
planned number of data blocks collected |
beta |
numeric in (0, 1) that specifies the tolerable type II error control necessary to calculate both "nBlocksPlan" and "delta". Note that 1-beta defines the power. |
delta |
a priori minimal relevant divergence between group means b and a, either a numeric between -1 and 1 for no alternative restriction or a restriction on difference, or a real for a restriction on the log odds ratio. |
alternativeRestriction |
a character string specifying an optional restriction on the alternative hypothesis; must be one of "none" (default), "difference" (difference group mean b minus group b) or "logOddsRatio" (the log odds ratio between group means b and a). |
alpha |
numeric in (0, 1) that specifies the tolerable type I error control –independent on n– that the designed test has to adhere to. Note that it also defines the rejection rule e10 > 1/alpha. |
pilot |
logical, specifying whether it's a pilot design. |
hyperParameterValues |
named list containing numeric values for hyperparameters betaA1, betaA2, betaB1 and betaB2, with betaA1 and betaB1 specifying the parameter
equivalent to |
previousSafeTestResult |
optionally, a previous safe test result can be provided. The posterior of the hyperparameters of this test is then used for the hyperparameter settings. Default NULL. |
M |
number of simulations used to estimate power or nBlocksPlan. Default |
simThetaAMin |
minimal event rate in control group to simulate nPlan or power for.
Can be specified when specifically interested in planning studies for specific event rates.
Default |
simThetaAMax |
maximal event rate in control group to simulate nPlan or power for. Default |
Returns a 'safeDesign' object that includes:
the sample size(s) to plan for. Computed based on beta and meanDiffMin, or provided by the user if known.
the safe test defining parameter: here the hyperparameters.
the minimally clinically relevant effect size provided by the user.
the tolerable type I error provided by the user.
the tolerable type II error specified by the user.
any of "twoSided", "greater", "less" based on the alternativeRestriction
provided by the user.
here 2x2
logical, specifying whether it's a pilot design.
the expression with which this function is called.
#plan for an experiment to detect minimal difference of 0.6 with a balanced design set.seed(3152021) designSafeTwoProportions(na = 1, nb = 1, alpha = 0.1, beta = 0.20, delta = 0.6, alternativeRestriction = "none", M = 75) #safe analysis of a pilot: number of samples already known designSafeTwoProportions(na = 1, nb = 1, nBlocksPlan = 20, pilot = TRUE) #specify own hyperparameters hyperParameterValues <- list(betaA1 = 10, betaA2 = 1, betaB1 = 1, betaB2 = 10) designSafeTwoProportions(na = 1, nb = 1, alpha = 0.1, beta = 0.20, delta = 0.6, hyperParameterValues = hyperParameterValues, alternativeRestriction = "none", M = 75) #restrict range of proportions for estimating nPlan in the control group designSafeTwoProportions(na = 1, nb = 1, beta = 0.20, delta = 0.3, alternativeRestriction = "none", M = 75, simThetaAMin = 0.1, simThetaAMax = 0.2)
#plan for an experiment to detect minimal difference of 0.6 with a balanced design set.seed(3152021) designSafeTwoProportions(na = 1, nb = 1, alpha = 0.1, beta = 0.20, delta = 0.6, alternativeRestriction = "none", M = 75) #safe analysis of a pilot: number of samples already known designSafeTwoProportions(na = 1, nb = 1, nBlocksPlan = 20, pilot = TRUE) #specify own hyperparameters hyperParameterValues <- list(betaA1 = 10, betaA2 = 1, betaB1 = 1, betaB2 = 10) designSafeTwoProportions(na = 1, nb = 1, alpha = 0.1, beta = 0.20, delta = 0.6, hyperParameterValues = hyperParameterValues, alternativeRestriction = "none", M = 75) #restrict range of proportions for estimating nPlan in the control group designSafeTwoProportions(na = 1, nb = 1, beta = 0.20, delta = 0.3, alternativeRestriction = "none", M = 75, simThetaAMin = 0.1, simThetaAMax = 0.2)
A designed experiment requires (1) a sample size nPlan to plan for, and (2) the parameter of the safe test, i.e., phiS. Provided with a clinically relevant minimal mean difference meanDiffMin, this function outputs phiS = meanDiffMin as the safe test defining parameter in accordance to the GROW criterion. If a tolerable type II error, i.e., beta, is provided then nPlan can be sampled. The sampled nPlan is then the smallest nPlan for which meanDiffMin can be found with power at least 1 - beta under optional stopping.
designSafeZ( meanDiffMin = NULL, beta = NULL, nPlan = NULL, alpha = 0.05, h0 = 0, alternative = c("twoSided", "greater", "less"), sigma = 1, kappa = sigma, tol = 1e-05, testType = c("oneSample", "paired", "twoSample"), ratio = 1, parameter = NULL, nSim = 1000L, nBoot = 1000L, pb = TRUE, grow = TRUE, ... )
designSafeZ( meanDiffMin = NULL, beta = NULL, nPlan = NULL, alpha = 0.05, h0 = 0, alternative = c("twoSided", "greater", "less"), sigma = 1, kappa = sigma, tol = 1e-05, testType = c("oneSample", "paired", "twoSample"), ratio = 1, parameter = NULL, nSim = 1000L, nBoot = 1000L, pb = TRUE, grow = TRUE, ... )
meanDiffMin |
numeric that defines the minimal relevant mean difference, the smallest population mean that we would like to detect. |
beta |
numeric in (0, 1) that specifies the tolerable type II error control necessary to calculate both "n" and "phiS". Note that 1-beta defines the power. |
nPlan |
optional numeric vector of length at most 2. When provided, it is used to find the safe test defining parameter phiS. Note that if the purpose is to plan based on nPlan alone, then both meanDiffMin and beta should be set to NULL. |
alpha |
numeric in (0, 1) that specifies the tolerable type I error control –independent on n– that the designed test has to adhere to. Note that it also defines the rejection rule e10 > 1/alpha. |
h0 |
numeric, represents the null hypothesis, default h0=0. |
alternative |
a character string specifying the alternative hypothesis must be one of "twoSided" (default), "greater" or "less". |
sigma |
numeric > 0 representing the assumed population standard deviation used for the test. |
kappa |
the true population standard deviation. Default kappa=sigma. |
tol |
a number that defines the stepsizes between the lowParam and highParam. |
testType |
either one of "oneSample", "paired", "twoSample". |
ratio |
numeric > 0 representing the randomisation ratio of condition 2 over condition 1. If testType is not equal to "twoSample", or if nPlan is of length(1) then ratio=1. |
parameter |
optional test defining parameter. Default set to |
nSim |
integer > 0, the number of simulations needed to compute power or the number of samples paths for the safe z test under continuous monitoring. |
nBoot |
integer > 0 representing the number of bootstrap samples to assess the accuracy of approximation of the power, the number of samples for the safe z test under continuous monitoring, or for the computation of the logarithm of the implied target. |
pb |
logical, if |
grow |
logical, default set to |
... |
further arguments to be passed to or from methods. |
Returns a safeDesign object that includes:
the sample size(s) to plan for. Computed based on beta and meanDiffMin, or provided by the user if known.
the safe test defining parameter. Here phiS.
the minimally clinically relevant effect size provided by the user.
the tolerable type I error provided by the user.
the tolerable type II error specified by the user.
any of "twoSided", "greater", "less" provided by the user.
any of "oneSample", "paired", "twoSample" effectively provided by the user.
logical, TRUE
if "paired", FALSE
otherwise.
the assumed population standard deviation used for the test provided by the user.
the true population standard deviation, typically, sigma=kappa.
default is 1. Different from 1, whenever testType equals "twoSample", then it defines ratio between the planned randomisation of condition 2 over condition 1.
the step size between parameter values in the candidate space.
logical, specifying whether it's a pilot design.
the expression with which this function is called.
Grunwald, de Heide and Koolen (2019) "Safe Testing" <arXiv:1906.07801>
designObj <- designSafeZ(meanDiffMin=0.8, alpha=0.08, beta=0.01, alternative="greater") #nPlan known: designObj <- designSafeZ(nPlan = 100, alpha=0.05)
designObj <- designSafeZ(meanDiffMin=0.8, alpha=0.08, beta=0.01, alternative="greater") #nPlan known: designObj <- designSafeZ(nPlan = 100, alpha=0.05)
Helper function: Get all names as entered by the user
extractNameFromArgs(list, name)
extractNameFromArgs(list, name)
list |
list from which the element needs retrieving |
name |
character string, name of the item that need retrieving |
returns a character string
The designs supported are "oneSample", "paired", "twoSample".
generateNormalData( nPlan, nSim = 1000L, deltaTrue = NULL, muGlobal = 0, sigmaTrue = 1, paired = FALSE, seed = NULL, muTrue = NULL )
generateNormalData( nPlan, nSim = 1000L, deltaTrue = NULL, muGlobal = 0, sigmaTrue = 1, paired = FALSE, seed = NULL, muTrue = NULL )
nPlan |
vector of max length 2 representing the planned sample sizes. |
nSim |
the number of replications, that is, experiments with max samples nPlan. |
deltaTrue |
numeric, the value of the true standardised effect size (test-relevant parameter). |
muGlobal |
numeric, the true global mean of a paired or two-sample t-test. Its value should not matter for the test. This parameter is treated as a nuisance. |
sigmaTrue |
numeric > 0,the true standard deviation of the data. Its value should not matter for the test.This parameter treated is treated as a nuisance. |
paired |
logical, if |
seed |
To set the seed for the simulated data. |
muTrue |
numeric representing the true mean for simulations with a z-test.
Default |
Returns a list of two data matrices contains at least the following components:
a matrix of data dimension nSim by nPlan[1]
.
a matrix of data dimension nSim by nPlan[2]
.
generateNormalData(20, 15, deltaTrue=0.3)
generateNormalData(20, 15, deltaTrue=0.3)
Generate Survival Data which Can Be Analysed With the 'survival' Package
generateSurvData( nP, nT, alpha = 1, lambdaP, lambdaT, seed = NULL, nDigits = 0, startTime = 1, endTime = 180, orderTime = TRUE, competeRatio = 0 )
generateSurvData( nP, nT, alpha = 1, lambdaP, lambdaT, seed = NULL, nDigits = 0, startTime = 1, endTime = 180, orderTime = TRUE, competeRatio = 0 )
nP |
integer > 0 representing the number of of patients in the placebo group. |
nT |
integer > 0 representing the number of of patients in the treatment group. |
alpha |
numeric > 0, representing the shape parameter of the Weibull distribution. If alpha=1, then data are generated from the exponential, i.e., constant hazard. For alpha > 1 the hazard increases, if alpha < 1, the hazard decreases. |
lambdaP |
The (relative) hazard of the placebo group. |
lambdaT |
The (relative) hazard of the treatment group. |
seed |
A seed number. |
nDigits |
numeric, the number of digits to round of the random time to |
startTime |
numeric, adds this to the random times. Default 1, so the startTime is not 0, which
is the start time of |
endTime |
The endtime of the experiment. |
orderTime |
logical, if |
competeRatio |
The ratio of the data that is due to competing risk. |
A data set with time, status and group.
generateSurvData(800, 800, alpha=1, lambdaP=0.008, lambdaT=0.008/2)
generateSurvData(800, 800, alpha=1, lambdaP=0.008, lambdaT=0.008/2)
Helper function: Get all arguments as entered by the user
getArgs()
getArgs()
a list of variable names of class "call" that can be changed into names
Helper function that outputs the alternative hypothesis of the analysis.
getNameAlternative( alternative = c("twoSided", "greater", "less"), testType, h0 = 0 )
getNameAlternative( alternative = c("twoSided", "greater", "less"), testType, h0 = 0 )
alternative |
A character string. "twoSided", "greater", "less". |
testType |
A character string either "oneSample", "paired", "twoSample", "gLogrank", or "eLogrank". |
h0 |
the value of the null hypothesis |
Returns a character string with the name of the analysis.
Helper function that outputs the name of the analysis.
getNameTestType(testType, parameterName)
getNameTestType(testType, parameterName)
testType |
A character string. For the t-tests: "oneSample", "paired", "twoSample". |
parameterName |
The name of the parameter to identify test performed |
Returns a character string with the name of the analysis.
Checks whether any of the provided objects contains a try error.
isTryError(...)
isTryError(...)
... |
objects that need testing. |
Returns TRUE
if there's some object that's a try-error, FALSE
when all objects are
not try-errors.
x <- 1 y <- "a" z <- try(integrate(exp, -Inf, Inf)) isTryError(x, y) isTryError(x, y, z)
x <- 1 y <- "a" z <- try(integrate(exp, -Inf, Inf)) isTryError(x, y) isTryError(x, y, z)
Helper function computes single component of the exact logrank e-value
logrankSingleEExact(obs0, obs1, y0, y1, thetaS, theta0 = 1, ...)
logrankSingleEExact(obs0, obs1, y0, y1, thetaS, theta0 = 1, ...)
obs0 |
integer, number of observations in the control group. |
obs1 |
integer, number of observations in the treatment group. |
y0 |
integer, total number of participants in the control group. |
y1 |
integer, total number of participants in the treatment group. |
thetaS |
numeric > 0 represents the safe test defining (GROW) alternative
hypothesis obtained from |
theta0 |
numeric > 0 represents the null hypothesis. Default theta0=1. |
... |
further arguments to be passed to or from methods. |
Returns a list containing at least the following components:
Log likelihood of Fisher's hypergeometric at the null
Log likelihood of Fisher's hypergeometric at the alternative
Log likelihood of Fisher's hypergeometric at 1/alternative
#' 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
#' 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
Helper function computes single component of the logrank statistic
logrankSingleZ(obs0, obs1, y0, y1, ...)
logrankSingleZ(obs0, obs1, y0, y1, ...)
obs0 |
integer, number of observations in the control group |
obs1 |
integer, number of observations in the treatment group |
y0 |
integer, total number of participants in the control group |
y1 |
integer, total number of participants in the treatment group |
... |
further arguments to be passed to or from methods. |
Returns a list containing at least the following components:
observed minus expected.
hypergeometric variance.
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))
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))
Plots Results of Simulations for Comparing Hyperparameters for Safe Tests of Two Proportions
## S3 method for class 'safe2x2Sim' plot(x, ...)
## S3 method for class 'safe2x2Sim' plot(x, ...)
x |
a result object obtained through |
... |
further arguments to be passed to or from methods. |
Plot data, mainly called for side effects, the plot of simulation results.
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 ) plot(simResult)
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 ) plot(simResult)
Plots a 'safeTSim' Object
## S3 method for class 'safeTSim' plot(x, y = NULL, showOnlyNRejected = FALSE, nBin = 25, ...)
## S3 method for class 'safeTSim' plot(x, y = NULL, showOnlyNRejected = FALSE, nBin = 25, ...)
x |
a 'safeDesign' object acquired from |
y |
|
showOnlyNRejected |
logical, when |
nBin |
numeric > 0, the minimum number of bins in the histogram. |
... |
further arguments to be passed to or from methods. |
a histogram object, and called for its side-effect to plot the histogram.
# Design safe test alpha <- 0.05 beta <- 0.20 designObj <- designSafeT(1, alpha=alpha, beta=beta) # Design frequentist test freqObj <- designFreqT(1, alpha=alpha, beta=beta) # Simulate under the alternative with deltaTrue=deltaMin simResults <- simulate(designObj, nSim=100) plot(simResults) plot(simResults, showOnlyNRejected=TRUE)
# Design safe test alpha <- 0.05 beta <- 0.20 designObj <- designSafeT(1, alpha=alpha, beta=beta) # Design frequentist test freqObj <- designFreqT(1, alpha=alpha, beta=beta) # Simulate under the alternative with deltaTrue=deltaMin simResults <- simulate(designObj, nSim=100) plot(simResults) plot(simResults, showOnlyNRejected=TRUE)
Plot bounds of a safe confidence sequence of the difference or log odds ratio for two proportions against the number of data blocks in two data streams ya and yb.
plotConfidenceSequenceTwoProportions( ya, yb, safeDesign, differenceMeasure = c("difference", "odds"), precision = 100, deltaStart = 0.001, deltaStop = 3, trueDifference = NA )
plotConfidenceSequenceTwoProportions( ya, yb, safeDesign, differenceMeasure = c("difference", "odds"), precision = 100, deltaStart = 0.001, deltaStop = 3, trueDifference = NA )
ya |
positive observations/ events per data block in group a: a numeric with integer values
between (and including) 0 and |
yb |
positive observations/ events per data block in group b: a numeric with integer values
between (and including) 0 and |
safeDesign |
a safe test design for two proportions retrieved through |
differenceMeasure |
the difference measure to construct the confidence interval for: one of "difference" and "odds". |
precision |
precision of the grid to search over for the confidence sequence bounds. |
deltaStart |
for the odds difference measure: the (absolute value of the) smallest log odds ratio to assess for in- or exclusion in the confidence sequence. Default 0.001. |
deltaStop |
for the odds difference measure: the (absolute value of the) highest log odds ratio to assess for in- or exclusion in the confidence sequence. Default 3. |
trueDifference |
true difference or log odds ratio in groups A and B: added to the plot. |
no return value; called for its side effects, a plot of the confidence sequence.
set.seed(39413) ya <- rbinom(n = 30, size = 1, prob = 0.1) yb <- rbinom(n = 30, size = 1, prob = 0.8) balancedSafeDesign <- designSafeTwoProportions(na = 1, nb = 1, nBlocksPlan = 30) plotConfidenceSequenceTwoProportions(ya = ya, yb = yb, safeDesign = balancedSafeDesign, differenceMeasure = "difference", precision = 15, trueDifference = 0.7) #log odds ratio difference measure plotConfidenceSequenceTwoProportions(ya = ya, yb = yb, safeDesign = balancedSafeDesign, differenceMeasure = "odds", precision = 15, deltaStop = 5, trueDifference = log(36)) #switch ya and yb: observe negative log odds ratio in the data, plot mirrored in x-axis plotConfidenceSequenceTwoProportions(ya = yb, yb = ya, safeDesign = balancedSafeDesign, differenceMeasure = "odds", precision = 15, deltaStop = 5, trueDifference = -log(36))
set.seed(39413) ya <- rbinom(n = 30, size = 1, prob = 0.1) yb <- rbinom(n = 30, size = 1, prob = 0.8) balancedSafeDesign <- designSafeTwoProportions(na = 1, nb = 1, nBlocksPlan = 30) plotConfidenceSequenceTwoProportions(ya = ya, yb = yb, safeDesign = balancedSafeDesign, differenceMeasure = "difference", precision = 15, trueDifference = 0.7) #log odds ratio difference measure plotConfidenceSequenceTwoProportions(ya = ya, yb = yb, safeDesign = balancedSafeDesign, differenceMeasure = "odds", precision = 15, deltaStop = 5, trueDifference = log(36)) #switch ya and yb: observe negative log odds ratio in the data, plot mirrored in x-axis plotConfidenceSequenceTwoProportions(ya = yb, yb = ya, safeDesign = balancedSafeDesign, differenceMeasure = "odds", precision = 15, deltaStop = 5, trueDifference = -log(36))
Helper function to display the histogram of stopping times.
plotHistogramDistributionStoppingTimes( safeSim, nPlan, deltaTrue, showOnlyNRejected = FALSE, nBin = 25L, ... )
plotHistogramDistributionStoppingTimes( safeSim, nPlan, deltaTrue, showOnlyNRejected = FALSE, nBin = 25L, ... )
safeSim |
A safeSim object, returned from |
nPlan |
numeric > 0, the planned sample size(s). |
deltaTrue |
numeric, that represents the true underlying standardised effect size delta. |
showOnlyNRejected |
logical, when |
nBin |
numeric > 0, the minimum number of bins in the histogram. |
... |
further arguments to be passed to or from methods. |
a histogram object, and called for its side-effect to plot the histogram.
# Design safe test alpha <- 0.05 beta <- 0.20 designObj <- designSafeT(1, alpha=alpha, beta=beta) # Design frequentist test freqObj <- designFreqT(1, alpha=alpha, beta=beta) # Simulate under the alternative with deltaTrue=deltaMin simResults <- replicateTTests(nPlan=designObj$nPlan, deltaTrue=1, parameter=designObj$parameter, nPlanFreq=freqObj$nPlan) plotHistogramDistributionStoppingTimes( simResults$safeSim, nPlan = simResults$nPlan, deltaTrue = simResults$deltaTrue)
# Design safe test alpha <- 0.05 beta <- 0.20 designObj <- designSafeT(1, alpha=alpha, beta=beta) # Design frequentist test freqObj <- designFreqT(1, alpha=alpha, beta=beta) # Simulate under the alternative with deltaTrue=deltaMin simResults <- replicateTTests(nPlan=designObj$nPlan, deltaTrue=1, parameter=designObj$parameter, nPlanFreq=freqObj$nPlan) plotHistogramDistributionStoppingTimes( simResults$safeSim, nPlan = simResults$nPlan, deltaTrue = simResults$deltaTrue)
For given tolerable alpha and beta, (1) the planned sample sizes to using a safe test, (2) the frequentist test, and (3) the average sample size necessary due to optional stopping are plotted as a function of the minimal clinically relevant standardised effect size deltaMin.
plotSafeTDesignSampleSizeProfile( alpha = 0.05, beta = 0.2, nMax = 100, lowDeltaMin = 0.1, highDeltaMin = 1, stepDeltaMin = 0.1, testType = c("oneSample", "paired", "twoSample"), alternative = c("twoSided", "greater", "less"), ratio = 1, nSim = 1000L, nBoot = 1000L, seed = NULL, pb = TRUE, freqPlot = FALSE, ... )
plotSafeTDesignSampleSizeProfile( alpha = 0.05, beta = 0.2, nMax = 100, lowDeltaMin = 0.1, highDeltaMin = 1, stepDeltaMin = 0.1, testType = c("oneSample", "paired", "twoSample"), alternative = c("twoSided", "greater", "less"), ratio = 1, nSim = 1000L, nBoot = 1000L, seed = NULL, pb = TRUE, freqPlot = FALSE, ... )
alpha |
numeric in (0, 1) that specifies the tolerable type I error control –independent of n– that the designed test has to adhere to. Note that it also defines the rejection rule e10 > 1/alpha. |
beta |
numeric in (0, 1) that specifies the tolerable type II error control necessary to calculate both the sample sizes and deltaS, which defines the test. Note that 1-beta defines the power. |
nMax |
numeric, the maximum number of samples one has budget for to collect data. |
lowDeltaMin |
numeric, lowest value for deltaMin of interest |
highDeltaMin |
numeric, largest value for deltaMin of interest |
stepDeltaMin |
numeric, step size between lowDeltaMin and highDeltaMin |
testType |
either one of "oneSample", "paired", "twoSample". |
alternative |
a character string specifying the alternative hypothesis must be one of "twoSided" (default), "greater" or "less". |
ratio |
numeric > 0 representing the randomisation ratio of condition 2 over condition 1. If testType is not equal to "twoSample", or if nPlan is of length(1) then ratio=1. |
nSim |
integer > 0, the number of simulations needed to compute power or the number of samples paths for the safe z test under continuous monitoring. |
nBoot |
integer > 0 representing the number of bootstrap samples to assess the accuracy of approximation of the power, the number of samples for the safe z test under continuous monitoring, or for the computation of the logarithm of the implied target. |
seed |
integer, seed number. |
pb |
logical, if |
freqPlot |
logical, if |
... |
further arguments to be passed to or from methods, but mainly to perform do.calls. |
Returns a list that contains the planned sample size needed for the frequentist and safe tests as a function of the minimal clinically relevant effect sizes. The returned list contains at least the following components:
the tolerable type I error provided by the user.
the tolerable type II error provided by the user.
the largest number of samples provided by the user.
vector of the domain of deltaMin.
vector of the planned sample sizes needed for the frequentist test corresponding to alpha and beta.
vector of the planned sample sizes needed for the safe test corresponding to alpha and beta.
vector of safe test defining deltaS.
plotSafeTDesignSampleSizeProfile(nSim=1e2L)
plotSafeTDesignSampleSizeProfile(nSim=1e2L)
Prints Results of Simulations for Comparing Hyperparameters for Safe Tests of Two Proportions
## S3 method for class 'safe2x2Sim' print(x, ...)
## S3 method for class 'safe2x2Sim' print(x, ...)
x |
a result object obtained through |
... |
further arguments to be passed to or from methods. |
The data frame with simulation results, called for side effects to pretty print the simulation results.
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 )
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 )
Printing objects of class 'safeTest' modelled after print.power.htest()
.
## S3 method for class 'safeDesign' print(x, digits = getOption("digits"), prefix = "\t", ...)
## S3 method for class 'safeDesign' print(x, digits = getOption("digits"), prefix = "\t", ...)
x |
a safeTest object. |
digits |
number of significant digits to be used. |
prefix |
string, passed to strwrap for displaying the method components. |
... |
further arguments to be passed to or from methods. |
No returned value, called for side effects.
designSafeZ(meanDiffMin=0.5) designSafeT(deltaMin=0.5) designSafeLogrank(hrMin=0.7)
designSafeZ(meanDiffMin=0.5) designSafeT(deltaMin=0.5) designSafeLogrank(hrMin=0.7)
Printing objects of class 'safeTest' modelled after print.htest()
.
## S3 method for class 'safeTest' print(x, digits = getOption("digits"), prefix = "\t", ...)
## S3 method for class 'safeTest' print(x, digits = getOption("digits"), prefix = "\t", ...)
x |
a safeTest object. |
digits |
number of significant digits to be used. |
prefix |
string, passed to strwrap for displaying the method components. |
... |
further arguments to be passed to or from methods. |
No returned value, called for side effects.
safeTTest(rnorm(19), pilot=TRUE) safeZTest(rnorm(19), pilot=TRUE)
safeTTest(rnorm(19), pilot=TRUE) safeZTest(rnorm(19), pilot=TRUE)
Prints a safeTSim Object
## S3 method for class 'safeTSim' print(x, ...)
## S3 method for class 'safeTSim' print(x, ...)
x |
a 'safeTSim' object. |
... |
further arguments to be passed to or from methods. |
No returned value, called for side effects.
designObj <- designSafeT(1, beta=0.2, nSim=10) # Data under deltaTrue=deltaMin simObj <- simulate(designObj, nSim=10) print(simObj)
designObj <- designSafeT(1, beta=0.2, nSim=10) # Data under deltaTrue=deltaMin simObj <- simulate(designObj, nSim=10) print(simObj)
Simulate multiple data sets to show the effects of optional testing for safe (and frequentist) tests.
replicateTTests( nPlan, deltaTrue, muGlobal = 0, sigmaTrue = 1, paired = FALSE, alternative = c("twoSided", "greater", "less"), lowN = 3, nSim = 1000L, alpha = 0.05, beta = 0.2, safeOptioStop = TRUE, parameter = NULL, freqOptioStop = FALSE, nPlanFreq = NULL, logging = TRUE, seed = NULL, pb = TRUE, ... )
replicateTTests( nPlan, deltaTrue, muGlobal = 0, sigmaTrue = 1, paired = FALSE, alternative = c("twoSided", "greater", "less"), lowN = 3, nSim = 1000L, alpha = 0.05, beta = 0.2, safeOptioStop = TRUE, parameter = NULL, freqOptioStop = FALSE, nPlanFreq = NULL, logging = TRUE, seed = NULL, pb = TRUE, ... )
nPlan |
vector of max length 2 representing the planned sample sizes. |
deltaTrue |
numeric, the value of the true standardised effect size (test-relevant parameter). |
muGlobal |
numeric, the true global mean of a paired or two-sample t-test. Its value should not matter for the test. This parameter is treated as a nuisance. |
sigmaTrue |
numeric > 0,the true standard deviation of the data. Its value should not matter for the test.This parameter treated is treated as a nuisance. |
paired |
logical, if |
alternative |
a character string specifying the alternative hypothesis must be one of "twoSided" (default), "greater" or "less". |
lowN |
integer that defines the smallest n of our search space for n. |
nSim |
the number of replications, that is, experiments with max samples nPlan. |
alpha |
numeric in (0, 1) that specifies the tolerable type I error control –independent of n– that the designed test has to adhere to. Note that it also defines the rejection rule e10 > 1/alpha. |
beta |
numeric in (0, 1) that specifies the tolerable type II error control necessary to calculate both the sample sizes and deltaS, which defines the test. Note that 1-beta defines the power. |
safeOptioStop |
logical, |
parameter |
numeric, the safe test defining parameter, i.e., deltaS (use designSafeT to find this). |
freqOptioStop |
logical, |
nPlanFreq |
the frequentist sample size(s) to plan for. Acquired from |
logging |
logical, if |
seed |
To set the seed for the simulated data. |
pb |
logical, if |
... |
further arguments to be passed to or from methods. |
Returns an object of class "safeTSim". An object of class "safeTSim" is a list containing at least the following components:
the planned sample size(s).
the value of the true standardised effect size (test-relevant parameter) provided by the user.
the true global mean of a paired or two-sample t-test (nuisance parameter) provided by the user.
if TRUE
then paired t-test.
any of "twoSided", "greater", "less" provided by the user.
the smallest number of samples (first group) at which monitoring of the tests begins.
the number of replications of the experiment.
the tolerable type I error provided by the user.
the tolerable type II error provided by the user.
any of "oneSample", "paired", "twoSample" provided by the user.
the parameter (point prior) used in the safe test derived from the design.
Acquired from designSafeT()
.
the frequentist planned sample size(s). Acquired from designFreqT
()
list with the simulation results of the safe test under optional stopping.
list with the simulation results of the frequentist test under optional stopping.
# Design safe test alpha <- 0.05 beta <- 0.20 designObj <- designSafeT(1, alpha=alpha, beta=beta) # Design frequentist test freqObj <- designFreqT(1, alpha=alpha, beta=beta) # Simulate under the alternative with deltaTrue=deltaMin simResults <- replicateTTests(nPlan=designObj$nPlan, deltaTrue=1, parameter=designObj$parameter, nPlanFreq=freqObj$nPlan, beta=beta, nSim=250) # Should be about 1-beta simResults$safeSim$powerAtN1Plan # This is higher due to optional stopping simResults$safeSim$powerOptioStop # Optional stopping allows us to do better than n1PlanFreq once in a while simResults$safeSim$probLeqN1PlanFreq graphics::hist(simResults$safeSim$allN, main="Histogram of stopping times", xlab="n1", breaks=seq.int(designObj$nPlan[1])) # Simulate under the alternative with deltaTrue > deltaMin simResults <- replicateTTests(nPlan=designObj$nPlan, deltaTrue=1.5, parameter=designObj$parameter, nPlanFreq=freqObj$nPlan, beta=beta, nSim=250) # Should be larger than 1-beta simResults$safeSim$powerAtN1Plan # This is even higher due to optional stopping simResults$safeSim$powerOptioStop # Optional stopping allows us to do better than n1PlanFreq once in a while simResults$safeSim$probLeqN1PlanFreq graphics::hist(simResults$safeSim$allN, main="Histogram of stopping times", xlab="n1", breaks=seq.int(designObj$nPlan[1])) # Under the null deltaTrue=0 simResults <- replicateTTests(nPlan=designObj$nPlan, deltaTrue=0, parameter=designObj$parameter, nPlanFreq=freqObj$nPlan, freqOptioStop=TRUE, beta=beta, nSim=250) # Should be lower than alpha, because if the null is true, P(S > 1/alpha) < alpha for all n simResults$safeSim$powerAtN1Plan # This is a bit higher due to optional stopping, but if the null is true, # then still P(S > 1/alpha) < alpha for all n simResults$safeSim$powerOptioStop # Should be lowr than alpha, as the experiment is performed as was planned simResults$freqSim$powerAtN1Plan # This is larger than alpha, due to optional stopping. simResults$freqSim$powerOptioStop simResults$freqSim$powerOptioStop > alpha
# Design safe test alpha <- 0.05 beta <- 0.20 designObj <- designSafeT(1, alpha=alpha, beta=beta) # Design frequentist test freqObj <- designFreqT(1, alpha=alpha, beta=beta) # Simulate under the alternative with deltaTrue=deltaMin simResults <- replicateTTests(nPlan=designObj$nPlan, deltaTrue=1, parameter=designObj$parameter, nPlanFreq=freqObj$nPlan, beta=beta, nSim=250) # Should be about 1-beta simResults$safeSim$powerAtN1Plan # This is higher due to optional stopping simResults$safeSim$powerOptioStop # Optional stopping allows us to do better than n1PlanFreq once in a while simResults$safeSim$probLeqN1PlanFreq graphics::hist(simResults$safeSim$allN, main="Histogram of stopping times", xlab="n1", breaks=seq.int(designObj$nPlan[1])) # Simulate under the alternative with deltaTrue > deltaMin simResults <- replicateTTests(nPlan=designObj$nPlan, deltaTrue=1.5, parameter=designObj$parameter, nPlanFreq=freqObj$nPlan, beta=beta, nSim=250) # Should be larger than 1-beta simResults$safeSim$powerAtN1Plan # This is even higher due to optional stopping simResults$safeSim$powerOptioStop # Optional stopping allows us to do better than n1PlanFreq once in a while simResults$safeSim$probLeqN1PlanFreq graphics::hist(simResults$safeSim$allN, main="Histogram of stopping times", xlab="n1", breaks=seq.int(designObj$nPlan[1])) # Under the null deltaTrue=0 simResults <- replicateTTests(nPlan=designObj$nPlan, deltaTrue=0, parameter=designObj$parameter, nPlanFreq=freqObj$nPlan, freqOptioStop=TRUE, beta=beta, nSim=250) # Should be lower than alpha, because if the null is true, P(S > 1/alpha) < alpha for all n simResults$safeSim$powerAtN1Plan # This is a bit higher due to optional stopping, but if the null is true, # then still P(S > 1/alpha) < alpha for all n simResults$safeSim$powerOptioStop # Should be lowr than alpha, as the experiment is performed as was planned simResults$freqSim$powerAtN1Plan # This is larger than alpha, due to optional stopping. simResults$freqSim$powerOptioStop simResults$freqSim$powerOptioStop > alpha
Auxiliary function for sampling of the logrank simulations to return the integer 1 event per time.
returnOne()
returnOne()
1
returnOne()
returnOne()
Draws a number of occurrences in group 1 (treatment) out of obsTotal number of occurrences.
rLogrank(n = 1, y0, y1, obsTotal, theta)
rLogrank(n = 1, y0, y1, obsTotal, theta)
n |
integer, number of observations to be sampled. |
y0 |
Size of the risk set of group 0 (Placebo). |
y1 |
Size of the risk set of group 1 (Treatment). |
obsTotal |
Total number of observations. |
theta |
Odds of group 1 over group 0 (treatment over placebo). |
integer representing the number of occurrences in group 1 out of obsTotal number of occurrences.
Muriel Felipe Perez-Ortiz and Alexander Ly
rLogrank(y0=360, y1=89, obsTotal=12, theta=3.14)
rLogrank(y0=360, y1=89, obsTotal=12, theta=3.14)
A safe test to test whether there is a difference between two survival curves. This function builds on the Mantel-Cox version of the logrank test.
safeLogrankTest( formula, designObj = NULL, ciValue = NULL, data = NULL, survTime = NULL, group = NULL, pilot = FALSE, exact = TRUE, computeZ = TRUE, ... ) safeLogrankTestStat( z, nEvents, designObj, ciValue = NULL, dataNull = 1, sigma = 1 )
safeLogrankTest( formula, designObj = NULL, ciValue = NULL, data = NULL, survTime = NULL, group = NULL, pilot = FALSE, exact = TRUE, computeZ = TRUE, ... ) safeLogrankTestStat( z, nEvents, designObj, ciValue = NULL, dataNull = 1, sigma = 1 )
formula |
a formula expression as for other survival models, of the form Surv(time, status) ~ groupingVariable,
see |
designObj |
a safe logrank design obtained from |
ciValue |
numeric, represents the ciValue-level of the confidence sequence. Default ciValue=NULL, and ciValue = 1 - alpha, where alpha is taken from the design object. |
data |
an optional data frame in which to interpret the variables occurring in survTime and group. |
survTime |
an optional survival time object of class 'Surv' created with |
group |
an optional factor, a grouping variable. Currently, only two levels allowed. Does not need specifying
if a formula is provided, therefore set to |
pilot |
a logical indicating whether a pilot study is run. If |
exact |
a logical indicating whether the exact safe logrank test needs to be performed based on
the hypergeometric likelihood. Default is |
computeZ |
logical. If |
... |
further arguments to be passed to or from methods. |
z |
numeric representing the observed logrank z statistic. |
nEvents |
numeric > 0, observed number of events. |
dataNull |
numeric > 0, the null hypothesis corresponding to the z statistics. By default dataNull = 1 representing equality of the hazard ratio. |
sigma |
numeric > 0, scaling in the data. |
Returns an object of class 'safeTest'. An object of class 'safeTest' is a list containing at least the following components:
the value of the summary, i.e., z-statistic or the e-value.
The number of observed events.
the e-value of the safe test.
An anytime-valid confidence sequence.
To be implemented: An estimate of the hazard ratio.
"logrank".
a character string giving the name(s) of the data.
an object of class "safeDesign" obtained from designSafeLogrank
.
a list containing.the time of events, the progression of the risk sets and events.
the expression with which this function is called.
safeLogrankTestStat()
: Safe Logrank Test based on Summary Statistic Z
All provided data (i.e., z-scores) are assumed to be centred on a hazard ratio = 1, thus, log(hr) = 0 ,
and the proper (e.g., hypergeometric) scaling is applied to the data, so sigma = 1. The null hypothesis
in the design object pertains to the population and is allowed to differ from log(theta) = 0.
# Example taken from survival::survdiff designObj <- designSafeLogrank(hrMin=1/2) ovData <- survival::ovarian ovData$survTime <- survival::Surv(ovData$futime, ovData$fustat) safeLogrankTest(formula=survTime~ rx, data=ovData, designObj=designObj) safeLogrankTest(survTime=survTime, group=rx, data=ovData, designObj=designObj) # Examples taken from coin::logrank_test ## Example data (Callaert, 2003, Tab. 1) #' callaert <- data.frame( time = c(1, 1, 5, 6, 6, 6, 6, 2, 2, 2, 3, 4, 4, 5, 5), group = factor(rep(0:1, c(7, 8))) ) designObj <- designSafeLogrank(hrMin=1/2) safeLogrankTest(survival::Surv(callaert$time)~callaert$group, designObj = designObj) safeLogrankTest(survTime=survival::Surv(callaert$time), group=callaert$group, designObj = designObj) result <- safeLogrankTest(survTime=survival::Surv(callaert$time), group=callaert$group, designObj = designObj) result ## Sequentially # Greater eValueGreater <- exp(cumsum(result$sumStats$logEValueGreater)) # Less eValueLess <- exp(cumsum(result$sumStats$logEValueLess)) # twoSided eValueTwoSided <- 1/2*eValueGreater+1/2*eValueLess eValueTwoSided result$eValue ###### Example switching between safe exact and safe Gaussian logrank test designObj <- designSafeLogrank(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 <- safeLogrankTest(survTime ~ dat$group, designObj = designObj) resultG <- safeLogrankTest(survTime ~ dat$group, designObj = designObj, exact=FALSE) resultE resultG ###### Example switching between safe exact and safe Gaussian logrank test other side designObj <- designSafeLogrank(1/0.8, alternative="greater") resultE <- safeLogrankTest(survTime ~ dat$group, designObj = designObj) resultG <- safeLogrankTest(survTime ~ dat$group, designObj = designObj, exact=FALSE) if (log(resultE$eValue) >= 0 && log(resultG$eValue) >= 0 ) stop("one-sided wrong")
# Example taken from survival::survdiff designObj <- designSafeLogrank(hrMin=1/2) ovData <- survival::ovarian ovData$survTime <- survival::Surv(ovData$futime, ovData$fustat) safeLogrankTest(formula=survTime~ rx, data=ovData, designObj=designObj) safeLogrankTest(survTime=survTime, group=rx, data=ovData, designObj=designObj) # Examples taken from coin::logrank_test ## Example data (Callaert, 2003, Tab. 1) #' callaert <- data.frame( time = c(1, 1, 5, 6, 6, 6, 6, 2, 2, 2, 3, 4, 4, 5, 5), group = factor(rep(0:1, c(7, 8))) ) designObj <- designSafeLogrank(hrMin=1/2) safeLogrankTest(survival::Surv(callaert$time)~callaert$group, designObj = designObj) safeLogrankTest(survTime=survival::Surv(callaert$time), group=callaert$group, designObj = designObj) result <- safeLogrankTest(survTime=survival::Surv(callaert$time), group=callaert$group, designObj = designObj) result ## Sequentially # Greater eValueGreater <- exp(cumsum(result$sumStats$logEValueGreater)) # Less eValueLess <- exp(cumsum(result$sumStats$logEValueLess)) # twoSided eValueTwoSided <- 1/2*eValueGreater+1/2*eValueLess eValueTwoSided result$eValue ###### Example switching between safe exact and safe Gaussian logrank test designObj <- designSafeLogrank(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 <- safeLogrankTest(survTime ~ dat$group, designObj = designObj) resultG <- safeLogrankTest(survTime ~ dat$group, designObj = designObj, exact=FALSE) resultE resultG ###### Example switching between safe exact and safe Gaussian logrank test other side designObj <- designSafeLogrank(1/0.8, alternative="greater") resultE <- safeLogrankTest(survTime ~ dat$group, designObj = designObj) resultG <- safeLogrankTest(survTime ~ dat$group, designObj = designObj, exact=FALSE) if (log(resultE$eValue) >= 0 && log(resultG$eValue) >= 0 ) stop("one-sided wrong")
A safe t-test adapted from t.test()
to perform one and two sample t-tests on vectors of data.
safeTTest( x, y = NULL, designObj = NULL, paired = FALSE, varEqual = TRUE, pilot = FALSE, alpha = NULL, alternative = NULL, ciValue = NULL, na.rm = FALSE, ... ) safe.t.test( x, y = NULL, designObj = NULL, paired = FALSE, var.equal = TRUE, pilot = FALSE, alpha = NULL, alternative = NULL, ... )
safeTTest( x, y = NULL, designObj = NULL, paired = FALSE, varEqual = TRUE, pilot = FALSE, alpha = NULL, alternative = NULL, ciValue = NULL, na.rm = FALSE, ... ) safe.t.test( x, y = NULL, designObj = NULL, paired = FALSE, var.equal = TRUE, pilot = FALSE, alpha = NULL, alternative = NULL, ... )
x |
a (non-empty) numeric vector of data values. |
y |
an optional (non-empty) numeric vector of data values. |
designObj |
an object obtained from |
paired |
a logical indicating whether you want a paired t-test. |
varEqual |
a logical variable indicating whether to treat the two variances as being equal. For
the moment, this is always |
pilot |
a logical indicating whether a pilot study is run. If |
alpha |
numeric > 0 only used if pilot equals |
alternative |
a character only used if pilot equals |
ciValue |
numeric is the ciValue-level of the confidence sequence. Default ciValue=NULL, and ciValue = 1 - alpha |
na.rm |
a logical value indicating whether |
... |
further arguments to be passed to or from methods. |
var.equal |
a logical variable indicating whether to treat the two variances as being equal. For the moment,
this is always |
Returns an object of class "safeTest". An object of class "safeTest" is a list containing at least the following components:
the value of the t-statistic.
The realised sample size(s).
the realised e-value from the safe test.
A safe confidence interval for the mean appropriate to the specific alternative hypothesis.
the estimated mean or difference in means or mean difference depending on whether it a one- sample test or a two-sample test was conducted.
the standard error of the mean (difference), used as denominator in the t-statistic formula.
any of "oneSample", "paired", "twoSample" provided by the user.
a character string giving the name(s) of the data.
an object of class "safeTDesign" obtained from designSafeT()
.
the expression with which this function is called.
designObj <- designSafeT(deltaMin=0.6, alpha=0.008, alternative="greater", testType="twoSample", ratio=1.2) set.seed(1) x <- rnorm(100) y <- rnorm(100) safeTTest(x, y, designObj=designObj) #0.2959334 safeTTest(1:10, y = c(7:20), pilot=TRUE) # s = 658.69 > 1/alpha designObj <- designSafeT(deltaMin=0.6, alpha=0.008, alternative="greater", testType="twoSample", ratio=1.2) set.seed(1) x <- rnorm(100) y <- rnorm(100) safe.t.test(x, y, alternative="greater", designObj=designObj) #0.2959334 safe.t.test(1:10, y = c(7:20), pilot=TRUE) # s = 658.69 > 1/alpha
designObj <- designSafeT(deltaMin=0.6, alpha=0.008, alternative="greater", testType="twoSample", ratio=1.2) set.seed(1) x <- rnorm(100) y <- rnorm(100) safeTTest(x, y, designObj=designObj) #0.2959334 safeTTest(1:10, y = c(7:20), pilot=TRUE) # s = 658.69 > 1/alpha designObj <- designSafeT(deltaMin=0.6, alpha=0.008, alternative="greater", testType="twoSample", ratio=1.2) set.seed(1) x <- rnorm(100) y <- rnorm(100) safe.t.test(x, y, alternative="greater", designObj=designObj) #0.2959334 safe.t.test(1:10, y = c(7:20), pilot=TRUE) # s = 658.69 > 1/alpha
A summary stats version of safeTTest()
with the data replaced by t, n1 and n2, and the
design object by deltaS.
safeTTestStat( t, parameter, n1, n2 = NULL, alternative = c("twoSided", "less", "greater"), tDensity = FALSE, paired = FALSE, ... )
safeTTestStat( t, parameter, n1, n2 = NULL, alternative = c("twoSided", "less", "greater"), tDensity = FALSE, paired = FALSE, ... )
t |
numeric that represents the observed t-statistic. |
parameter |
numeric this defines the safe test S, i.e., a likelihood ratio of t distributions with in the denominator the likelihood with delta = 0 and in the numerator an average likelihood defined by 1/2 time the likelihood at the non-centrality parameter sqrt(nEff)*parameter and 1/2 times the likelihood at the non-centrality parameter -sqrt(nEff)*parameter. |
n1 |
integer that represents the size in a one-sample t-test, (n2= |
n2 |
an optional integer that specifies the size of the second sample. If it's left unspecified, thus,
|
alternative |
a character only used if pilot equals |
tDensity |
Uses the the representation of the safe t-test as the likelihood ratio of t densities. |
paired |
a logical indicating whether you want a paired t-test. |
... |
further arguments to be passed to or from methods. |
Returns a numeric that represent the e10, that is, the e-value in favour of the alternative over the null
safeTTestStat(t=1, n1=100, 0.4) safeTTestStat(t=3, n1=100, parameter=0.3)
safeTTestStat(t=1, n1=100, 0.4) safeTTestStat(t=3, n1=100, parameter=0.3)
This is basically just safeTTestStat()
- 1/alpha. This function is used for root finding for
pilot designs.
safeTTestStatAlpha( t, parameter, n1, n2 = NULL, alpha, alternative = c("twoSided", "greater", "less"), tDensity = FALSE )
safeTTestStatAlpha( t, parameter, n1, n2 = NULL, alpha, alternative = c("twoSided", "greater", "less"), tDensity = FALSE )
t |
numeric that represents the observed t-statistic. |
parameter |
numeric this defines the safe test S, i.e., a likelihood ratio of t distributions with in the denominator the likelihood with delta = 0 and in the numerator an average likelihood defined by 1/2 time the likelihood at the non-centrality parameter sqrt(nEff)*parameter and 1/2 times the likelihood at the non-centrality parameter -sqrt(nEff)*parameter. |
n1 |
integer that represents the size in a one-sample t-test, (n2= |
n2 |
an optional integer that specifies the size of the second sample. If it's left unspecified, thus,
|
alpha |
numeric > 0 only used if pilot equals |
alternative |
a character only used if pilot equals |
tDensity |
Uses the the representation of the safe t-test as the likelihood ratio of t densities. |
Returns a numeric that represent the e10 - 1/alpha, that is, the e-value in favour of the alternative over the null - 1/alpha.
safeTTestStat(t=1, n1=100, 0.4) safeTTestStat(t=3, n1=100, parameter=0.3)
safeTTestStat(t=1, n1=100, 0.4) safeTTestStat(t=3, n1=100, parameter=0.3)
This is basically just safeTTestStat()
- 1/alpha. This function is used for root finding for
pilot designs.
safeTTestStatTDensity( t, parameter, nu, nEff, alternative = c("twoSided", "less", "greater"), paired = FALSE, ... )
safeTTestStatTDensity( t, parameter, nu, nEff, alternative = c("twoSided", "less", "greater"), paired = FALSE, ... )
t |
numeric that represents the observed t-statistic. |
parameter |
numeric this defines the safe test S, i.e., a likelihood ratio of t distributions with in the denominator the likelihood with delta = 0 and in the numerator an average likelihood defined by 1/2 time the likelihood at the non-centrality parameter sqrt(nEff)*parameter and 1/2 times the likelihood at the non-centrality parameter -sqrt(nEff)*parameter. |
nu |
numeric > 0 representing the degrees of freedom. |
nEff |
numeric > 0 representing the effective sample size in a two-sample problem. For one-sample problems this is equal to the sample size. |
alternative |
a character only used if pilot equals |
paired |
a logical indicating whether you want a paired t-test. |
... |
further arguments to be passed to or from methods. |
Returns a numeric that represent the e10, that is, the e-value in favour of the alternative over the null.
safeTTestStat(t=1, n1=100, 0.4) safeTTestStat(t=3, n1=100, parameter=0.3)
safeTTestStat(t=1, n1=100, 0.4) safeTTestStat(t=3, n1=100, parameter=0.3)
Perform a safe test for two proportions (a 2x2 contingency table test) with a
result object retrieved through the design function for planning an experiment to compare
two proportions in this package, designSafeTwoProportions()
.
safeTwoProportionsTest( ya, yb, designObj = NULL, wantConfidenceSequence = FALSE, ciValue = NULL, confidenceBoundGridPrecision = 20, logOddsConfidenceSearchBounds = c(0.01, 5), pilot = FALSE ) safe.prop.test( ya, yb, designObj = NULL, wantConfidenceSequence = FALSE, ciValue = NULL, confidenceBoundGridPrecision = 20, logOddsConfidenceSearchBounds = c(0.01, 5), pilot = FALSE )
safeTwoProportionsTest( ya, yb, designObj = NULL, wantConfidenceSequence = FALSE, ciValue = NULL, confidenceBoundGridPrecision = 20, logOddsConfidenceSearchBounds = c(0.01, 5), pilot = FALSE ) safe.prop.test( ya, yb, designObj = NULL, wantConfidenceSequence = FALSE, ciValue = NULL, confidenceBoundGridPrecision = 20, logOddsConfidenceSearchBounds = c(0.01, 5), pilot = FALSE )
ya |
positive observations/ events per data block in group a: a numeric with integer values
between (and including) 0 and |
yb |
positive observations/ events per data block in group b: a numeric with integer values
between (and including) 0 and |
designObj |
a safe test design for two proportions retrieved through |
wantConfidenceSequence |
logical that can be set to true when the user wants a safe confidence sequence to be estimated. |
ciValue |
coverage of the safe confidence sequence; default |
confidenceBoundGridPrecision |
integer specifying the grid precision used to search for the confidence bounds. Default 20. |
logOddsConfidenceSearchBounds |
vector of to positive doubles specifying the upper and lower bound of the grid
to search over for finding the confidence bound for the logOddsRatio restriction. Default |
pilot |
logical that can be set to true when performing an exploratory analysis
without a |
Returns an object of class 'safeTest'. An object of class 'safeTest' is a list containing at least the following components:
The realised sample size(s).
the e-value of the safe test.
a character string giving the name(s) of the data.
an object of class "safeDesign" described in designSafeTwoProportions()
.
#balanced design yb <- c(1,0,1,1,1,0,1) ya <- c(1,0,1,0,0,0,1) safeDesign <- designSafeTwoProportions(na = 1, nb = 1, beta = 0.20, delta = 0.6, alternativeRestriction = "none", M = 1e1) safeTwoProportionsTest(ya = ya, yb = yb, designObj = safeDesign) #pilot safeTwoProportionsTest(ya = ya, yb = yb, pilot = TRUE) #unbalanced design yb <- c(1,0,1,1,1,0,1) ya <- c(2,2,1,2,0,2,2) safeDesign <- designSafeTwoProportions(na = 2, nb = 1, beta = 0.20, delta = 0.6, alternativeRestriction = "none", M = 1e1) safeTwoProportionsTest(ya = ya, yb = yb, designObj = safeDesign)
#balanced design yb <- c(1,0,1,1,1,0,1) ya <- c(1,0,1,0,0,0,1) safeDesign <- designSafeTwoProportions(na = 1, nb = 1, beta = 0.20, delta = 0.6, alternativeRestriction = "none", M = 1e1) safeTwoProportionsTest(ya = ya, yb = yb, designObj = safeDesign) #pilot safeTwoProportionsTest(ya = ya, yb = yb, pilot = TRUE) #unbalanced design yb <- c(1,0,1,1,1,0,1) ya <- c(2,2,1,2,0,2,2) safeDesign <- designSafeTwoProportions(na = 2, nb = 1, beta = 0.20, delta = 0.6, alternativeRestriction = "none", M = 1e1) safeTwoProportionsTest(ya = ya, yb = yb, designObj = safeDesign)
This helper function is used in designSafeZ()
to find parameter. The function is the (two-sided)
inverse of 'safeZTestStat'.
safeZ10Inverse(parameter, nEff, sigma = 1, alpha = 0.05)
safeZ10Inverse(parameter, nEff, sigma = 1, alpha = 0.05)
parameter |
optional test defining parameter. Default set to |
nEff |
numeric > 0, the effective sample size. |
sigma |
numeric, the assumed known standard deviation, default 1. |
alpha |
numeric in (0, 1) that specifies the tolerable type I error control –independent on n– that the designed test has to adhere to. Note that it also defines the rejection rule e10 > 1/alpha. |
A number that represents a z-value. The function's domain is the positive real line and the range is the real line, i.e., the outcome space of the z-statistic.
safeZ10Inverse(0.4, n=13)
safeZ10Inverse(0.4, n=13)
Safe one and two sample z-tests on vectors of data. The function is modelled after t.test()
.
safeZTest( x, y = NULL, paired = FALSE, designObj = NULL, pilot = FALSE, ciValue = NULL, tol = 1e-05, na.rm = FALSE, ... ) safe.z.test( x, y = NULL, paired = FALSE, designObj = NULL, pilot = FALSE, tol = 1e-05, ... )
safeZTest( x, y = NULL, paired = FALSE, designObj = NULL, pilot = FALSE, ciValue = NULL, tol = 1e-05, na.rm = FALSE, ... ) safe.z.test( x, y = NULL, paired = FALSE, designObj = NULL, pilot = FALSE, tol = 1e-05, ... )
x |
a (non-empty) numeric vector of data values. |
y |
an optional (non-empty) numeric vector of data values. |
paired |
a logical indicating whether you want the paired z-test. |
designObj |
an object obtained from |
pilot |
a logical indicating whether a pilot study is run. If |
ciValue |
numeric is the ciValue-level of the confidence sequence. Default ciValue=NULL, and ciValue = 1 - alpha |
tol |
numeric > 0, only used if pilot equals |
na.rm |
a logical value indicating whether |
... |
further arguments to be passed to or from methods. |
Returns an object of class 'safeTest'. An object of class 'safeTest' is a list containing at least the following components:
the value of the test statistic. Here the z-statistic.
The realised sample size(s).
the e-value of the safe test.
To be implemented: a safe confidence interval for the mean appropriate to the specific alternative hypothesis.
the estimated mean or difference in means or mean difference depending on whether it was a one- sample test or a two-sample test.
the specified hypothesised value of the mean or mean difference depending on whether it was a one-sample or a two-sample test.
any of "oneSample", "paired", "twoSample" effectively provided by the user.
a character string giving the name(s) of the data.
an object of class "safeDesign" described in designSafeZ()
.
the expression with which this function is called.
designObj <- designSafeZ(meanDiffMin=0.6, alpha=0.008, alternative="greater", testType="twoSample", ratio=1.2) set.seed(1) x <- rnorm(100) y <- rnorm(100) safeZTest(x, y, designObj=designObj) # safeZTest(1:10, y = c(7:20), pilot=TRUE, alternative="less") # s = 7.7543e+20 > 1/alpha
designObj <- designSafeZ(meanDiffMin=0.6, alpha=0.008, alternative="greater", testType="twoSample", ratio=1.2) set.seed(1) x <- rnorm(100) y <- rnorm(100) safeZTest(x, y, designObj=designObj) # safeZTest(1:10, y = c(7:20), pilot=TRUE, alternative="less") # s = 7.7543e+20 > 1/alpha
Computes e-values using the z-statistic and the sample sizes only based on the test defining parameter phiS.
safeZTestStat( z, phiS, n1, n2 = NULL, alternative = c("twoSided", "less", "greater"), paired = FALSE, sigma = 1, ... )
safeZTestStat( z, phiS, n1, n2 = NULL, alternative = c("twoSided", "less", "greater"), paired = FALSE, sigma = 1, ... )
z |
numeric that represents the observed z-statistic. |
phiS |
numeric this defines the safe test S, i.e., a likelihood ratio of z distributions with in the denominator the likelihood with mean difference 0 and in the numerator an average likelihood defined by the likelihood at the parameter value. For the two sided case 1/2 at the parameter value and 1/2 at minus the parameter value. |
n1 |
integer that represents the size in a one-sample z-test, (n2= |
n2 |
an optional integer that specifies the size of the second sample. If it's left unspecified, thus,
|
alternative |
a character string specifying the alternative hypothesis must be one of "twoSided" (default), "greater" or "less". |
paired |
a logical, if |
sigma |
numeric, the assumed known standard deviation, default 1. |
... |
further arguments to be passed to or from methods. |
Returns an e-value.
safeZTestStat(z=1, n1=100, phiS=0.4) safeZTestStat(z=3, n1=100, phiS=0.3)
safeZTestStat(z=1, n1=100, phiS=0.4) safeZTestStat(z=3, n1=100, phiS=0.3)
Simulate stopping times for the exact safe logrank test
sampleLogrankStoppingTimes( hazardRatio, alpha = 0.05, alternative = c("twoSided", "less", "greater"), m0 = 50000L, m1 = 50000L, nSim = 1000L, groupSizePerTimeFunction = returnOne, parameter = NULL, nMax = Inf, pb = TRUE )
sampleLogrankStoppingTimes( hazardRatio, alpha = 0.05, alternative = c("twoSided", "less", "greater"), m0 = 50000L, m1 = 50000L, nSim = 1000L, groupSizePerTimeFunction = returnOne, parameter = NULL, nMax = Inf, pb = TRUE )
hazardRatio |
numeric that defines the data generating hazard ratio with which data are sampled. |
alpha |
numeric in (0, 1) that specifies the tolerable type I error control –independent on n– that the designed test has to adhere to. Note that it also defines the rejection rule e10 > 1/alpha. |
alternative |
a character string specifying the alternative hypothesis, which must be one of "twoSided" (default),"greater" or "less". The alternative is pitted against the null hypothesis of equality of the survival distributions. More specifically, let lambda1 be the hazard rate of group 1 (i.e., placebo), and lambda2 the hazard ratio of group 2 (i.e., treatment), then the null hypothesis states that the hazard ratio theta = lambda2/lambda1 = 1. If alternative = "less", the null hypothesis is compared to theta < 1, thus, lambda2 < lambda1, that is, the hazard of group 2 (i.e., treatment) is less than that of group 1 (i.e., placebo), hence, the treatment is beneficial. If alternative = "greater", then the null hypothesis is compared to theta > 1, thus, lambda2 > lambda1, hence, harm. |
m0 |
Number of subjects in the control group 0/1 at the beginning of the trial, i.e., nPlan[1]. |
m1 |
Number of subjects in the treatment group 1/2 at the beginning of the trial, i.e., nPlan[2]. |
nSim |
integer > 0, the number of simulations needed to compute power or the number of events for the exact safe logrank test under continuous monitoring |
groupSizePerTimeFunction |
A function without parameters and integer output. This function provides the number
of events at each time step. For instance, if |
parameter |
Numeric > 0, represents the safe tests defining thetaS. Default NULL so it's decided by the algorithm, typically, this equals hrMin, which corresponds to the GROW choice. |
nMax |
An integer. Once nEvents hits nMax the experiment terminates, if it didn't stop due to threshold crossing crossing already. Default set to Inf. |
pb |
logical, if |
a list with stoppingTimes and breakVector. Entries of breakVector are 0, 1. A 1 represents stopping due to exceeding nMax, and 0 due to 1/alpha threshold crossing, or running out of participants, which implies that the corresponding stopping time is Inf.
Muriel Felipe Perez-Ortiz and Alexander Ly
sampleLogrankStoppingTimes(0.7, nSim=10)
sampleLogrankStoppingTimes(0.7, nSim=10)
Simulate stopping times for the safe z-test
sampleStoppingTimesSafeT( deltaTrue, alpha = 0.05, alternative = c("twoSided", "less", "greater"), testType = c("oneSample", "paired", "twoSample"), nSim = 1000L, nMax = 1000, ratio = 1, lowN = 3L, parameter = NULL, seed = NULL, wantEValuesAtNMax = FALSE, pb = TRUE )
sampleStoppingTimesSafeT( deltaTrue, alpha = 0.05, alternative = c("twoSided", "less", "greater"), testType = c("oneSample", "paired", "twoSample"), nSim = 1000L, nMax = 1000, ratio = 1, lowN = 3L, parameter = NULL, seed = NULL, wantEValuesAtNMax = FALSE, pb = TRUE )
deltaTrue |
numeric, the value of the true standardised effect size (test-relevant parameter). This argument is used by 'designSafeT()' with 'deltaTrue <- deltaMin' |
alpha |
numeric in (0, 1) that specifies the tolerable type I error control –independent of n– that the designed test has to adhere to. Note that it also defines the rejection rule e10 > 1/alpha. |
alternative |
a character string specifying the alternative hypothesis must be one of "twoSided" (default), "greater" or "less". |
testType |
either one of "oneSample", "paired", "twoSample". |
nSim |
integer > 0, the number of simulations needed to compute power or the number of samples paths for the safe z test under continuous monitoring. |
nMax |
integer > 0, maximum sample size of the (first) sample in each sample path. |
ratio |
numeric > 0 representing the randomisation ratio of condition 2 over condition 1. If testType is not equal to "twoSample", or if nPlan is of length(1) then ratio=1. |
lowN |
integer minimal sample size of the (first) sample when computing the power due to optional stopping. Default lowN is set 1. |
parameter |
optional test defining parameter. Default set to |
seed |
integer, seed number. |
wantEValuesAtNMax |
logical. If |
pb |
logical, if |
a list with stoppingTimes and breakVector. Entries of breakVector are 0, 1. A 1 represents stopping due to exceeding nMax, and 0 due to 1/alpha threshold crossing, which implies that in corresponding stopping time is Inf.
sampleStoppingTimesSafeT(0.7, nSim=10)
sampleStoppingTimesSafeT(0.7, nSim=10)
Simulate stopping times for the safe z-test
sampleStoppingTimesSafeZ( meanDiffMin, alpha = 0.05, alternative = c("twoSided", "less", "greater"), sigma = 1, kappa = sigma, nSim = 1000L, nMax = 1000, ratio = 1, testType = c("oneSample", "paired", "twoSample"), parameter = NULL, wantEValuesAtNMax = FALSE, pb = TRUE )
sampleStoppingTimesSafeZ( meanDiffMin, alpha = 0.05, alternative = c("twoSided", "less", "greater"), sigma = 1, kappa = sigma, nSim = 1000L, nMax = 1000, ratio = 1, testType = c("oneSample", "paired", "twoSample"), parameter = NULL, wantEValuesAtNMax = FALSE, pb = TRUE )
meanDiffMin |
numeric that defines the minimal relevant mean difference, the smallest population mean that we would like to detect. |
alpha |
numeric in (0, 1) that specifies the tolerable type I error control –independent on n– that the designed test has to adhere to. Note that it also defines the rejection rule e10 > 1/alpha. |
alternative |
a character string specifying the alternative hypothesis must be one of "twoSided" (default), "greater" or "less". |
sigma |
numeric > 0 representing the assumed population standard deviation used for the test. |
kappa |
the true population standard deviation. Default kappa=sigma. |
nSim |
integer > 0, the number of simulations needed to compute power or the number of samples paths for the safe z test under continuous monitoring. |
nMax |
integer > 0, maximum sample size of the (first) sample in each sample path. |
ratio |
numeric > 0 representing the randomisation ratio of condition 2 over condition 1. If testType is not equal to "twoSample", or if nPlan is of length(1) then ratio=1. |
testType |
either one of "oneSample", "paired", "twoSample". |
parameter |
optional test defining parameter. Default set to |
wantEValuesAtNMax |
logical. If |
pb |
logical, if |
a list with stoppingTimes and breakVector. Entries of breakVector are 0, 1. A 1 represents stopping due to exceeding nMax, and 0 due to 1/alpha threshold crossing, which implies that in corresponding stopping time is Inf.
sampleStoppingTimesSafeZ(0.7, nSim=10)
sampleStoppingTimesSafeZ(0.7, nSim=10)
Helper function used in the vignette.
selectivelyContinueTTestCombineData( oldValues, valuesType = c("eValues", "pValues"), designObj = NULL, alternative = c("twoSided", "greater", "less"), oldData, deltaTrue, alpha = NULL, n1Extra = NULL, n2Extra = NULL, seed = NULL, paired = FALSE, muGlobal = 0, sigmaTrue = 1, moreMainText = "" )
selectivelyContinueTTestCombineData( oldValues, valuesType = c("eValues", "pValues"), designObj = NULL, alternative = c("twoSided", "greater", "less"), oldData, deltaTrue, alpha = NULL, n1Extra = NULL, n2Extra = NULL, seed = NULL, paired = FALSE, muGlobal = 0, sigmaTrue = 1, moreMainText = "" )
oldValues |
vector of e-values or p-values. |
valuesType |
character string either "eValues" or "pValues". |
designObj |
a safeDesign object obtained from |
alternative |
a character string specifying the alternative hypothesis must be one of "twoSided" (default), "greater" or "less". |
oldData |
a list of matrices with names "dataGroup1" and "dataGroup2". |
deltaTrue |
numeric, the value of the true standardised effect size (test-relevant parameter). |
alpha |
numeric in (0, 1) that specifies the tolerable type I error control –independent of n– that the designed test has to adhere to. Note that it also defines the rejection rule e10 > 1/alpha. |
n1Extra |
integer, that defines the additional number of samples of the first group. If
|
n2Extra |
optional integer, that defines the additional number of samples of the second group.
If |
seed |
To set the seed for the simulated data. |
paired |
logical, if |
muGlobal |
numeric, the true global mean of a paired or two-sample t-test. Its value should not matter for the test. This parameter is treated as a nuisance. |
sigmaTrue |
numeric > 0,the true standard deviation of the data. Its value should not matter for the test.This parameter treated is treated as a nuisance. |
moreMainText |
character, additional remarks in the title of the histogram. |
a list that includes the continued s or p-values based on the combined data, and a list of the combined data.
alpha <- 0.05 mIter <- 1000L designObj <- designSafeT(deltaMin=1, alpha=alpha, beta=0.2, nSim=100) oldData <- generateNormalData(nPlan=designObj$nPlan, deltaTrue=0, nSim=mIter, seed=1) eValues <- vector("numeric", length=mIter) for (i in seq_along(eValues)) { eValues[i] <- safeTTest(x=oldData$dataGroup1[i, ], designObj=designObj)$eValue } # First run: 8 false null rejections sum(eValues > 1/alpha) continuedSafe <- selectivelyContinueTTestCombineData( oldValues=eValues, designObj=designObj, oldData=oldData, deltaTrue=0, seed=2) # Second run: 1 false null rejections sum(continuedSafe$newValues > 1/alpha) # Third run: 0 false null rejections eValues <- continuedSafe$newValues oldData <- continuedSafe$combinedData continuedSafe <- selectivelyContinueTTestCombineData( oldValues=eValues, designObj=designObj, oldData=oldData, deltaTrue=0, seed=3) sum(continuedSafe$newValues > 1/alpha)
alpha <- 0.05 mIter <- 1000L designObj <- designSafeT(deltaMin=1, alpha=alpha, beta=0.2, nSim=100) oldData <- generateNormalData(nPlan=designObj$nPlan, deltaTrue=0, nSim=mIter, seed=1) eValues <- vector("numeric", length=mIter) for (i in seq_along(eValues)) { eValues[i] <- safeTTest(x=oldData$dataGroup1[i, ], designObj=designObj)$eValue } # First run: 8 false null rejections sum(eValues > 1/alpha) continuedSafe <- selectivelyContinueTTestCombineData( oldValues=eValues, designObj=designObj, oldData=oldData, deltaTrue=0, seed=2) # Second run: 1 false null rejections sum(continuedSafe$newValues > 1/alpha) # Third run: 0 false null rejections eValues <- continuedSafe$newValues oldData <- continuedSafe$combinedData continuedSafe <- selectivelyContinueTTestCombineData( oldValues=eValues, designObj=designObj, oldData=oldData, deltaTrue=0, seed=3) sum(continuedSafe$newValues > 1/alpha)
Sets 'safestats' Plot Options and Returns the Current Plot Options.
setSafeStatsPlotOptionsAndReturnOldOnes(...)
setSafeStatsPlotOptionsAndReturnOldOnes(...)
... |
further arguments to be passed to or from methods. |
Returns a list with the user specified plot options.
oldPar <- setSafeStatsPlotOptionsAndReturnOldOnes() graphics::plot(1:10, 1:10) setPar <- graphics::par(oldPar)
oldPar <- setSafeStatsPlotOptionsAndReturnOldOnes() graphics::plot(1:10, 1:10) setPar <- graphics::par(oldPar)
Applied to a 'safeDesign' object this function empirically shows the performance of safe experiments under optional stopping.
## S3 method for class 'safeDesign' simulate( object, nsim = nSim, seed = NULL, deltaTrue = NULL, muGlobal = 0, sigmaTrue = 1, lowN = 3, safeOptioStop = TRUE, freqOptioStop = FALSE, nPlanFreq = NULL, logging = TRUE, pb = TRUE, nSim = 1, ... )
## S3 method for class 'safeDesign' simulate( object, nsim = nSim, seed = NULL, deltaTrue = NULL, muGlobal = 0, sigmaTrue = 1, lowN = 3, safeOptioStop = TRUE, freqOptioStop = FALSE, nPlanFreq = NULL, logging = TRUE, pb = TRUE, nSim = 1, ... )
object |
A safeDesign obtained obtained from |
nsim |
integer, formally the number of iterations, but by default nsim=nSim |
seed |
integer, seed number. |
deltaTrue |
numeric, if NULL, then the minimally clinically relevant standardised effect size is used as the true data generating effect size deltaTrue. |
muGlobal |
numeric, the true global mean of a paired or two-sample t-test. Its value should not matter for the test. This parameter is treated as a nuisance. |
sigmaTrue |
numeric > 0,the true standard deviation of the data. Its value should not matter for the test.This parameter treated is treated as a nuisance. |
lowN |
integer that defines the smallest n of our search space for n. |
safeOptioStop |
logical, |
freqOptioStop |
logical, |
nPlanFreq |
the frequentist sample size(s) to plan for. Acquired from |
logging |
logical, if |
pb |
logical, if |
nSim |
integer, number of iterations. |
... |
further arguments to be passed to or from methods. |
Returns an object of class "safeTSim". An object of class "safeTSim" is a list containing at least the following components:
the planned sample size(s).
the value of the true standardised effect size (test-relevant parameter) provided by the user.
the true global mean of a paired or two-sample t-test (nuisance parameter) provided by the user.
if TRUE
then paired t-test.
any of "twoSided", "greater", "less" provided by the user.
the smallest number of samples (first group) at which monitoring of the tests begins.
the number of replications of the experiment.
the tolerable type I error provided by the user.
the tolerable type II error provided by the user.
any of "oneSample", "paired", "twoSample" provided by the user.
the parameter (point prior) used in the safe test derived from the design.
Acquired from designSafeT()
.
the frequentist planned sample size(s). Acquired from designFreqT
()
list with the simulation results of the safe test under optional stopping.
list with the simulation results of the frequentist test under optional stopping.
# Design safe test alpha <- 0.05 beta <- 0.20 deltaMin <- 1 designObj <- designSafeT(deltaMin, alpha=alpha, beta=beta, nSim=100) # Design frequentist test freqObj <- designFreqT(deltaMin, alpha=alpha, beta=beta) # Simulate based on deltaTrue=deltaMin simResultsDeltaTrueIsDeltaMin <- simulate(object=designObj, nSim=100) # Simulate based on deltaTrue > deltaMin simResultsDeltaTrueIsLargerThanDeltaMin <- simulate( object=designObj, nSim=100, deltaTrue=2) # Simulate under the null deltaTrue = 0 simResultsDeltaTrueIsNull <- simulate( object=designObj, nSim=100, deltaTrue=0) simulate(object=designObj, deltraTrue=0, nSim=100, freqOptioStop=TRUE, nPlanFreq=freqObj$nPlan)
# Design safe test alpha <- 0.05 beta <- 0.20 deltaMin <- 1 designObj <- designSafeT(deltaMin, alpha=alpha, beta=beta, nSim=100) # Design frequentist test freqObj <- designFreqT(deltaMin, alpha=alpha, beta=beta) # Simulate based on deltaTrue=deltaMin simResultsDeltaTrueIsDeltaMin <- simulate(object=designObj, nSim=100) # Simulate based on deltaTrue > deltaMin simResultsDeltaTrueIsLargerThanDeltaMin <- simulate( object=designObj, nSim=100, deltaTrue=2) # Simulate under the null deltaTrue = 0 simResultsDeltaTrueIsNull <- simulate( object=designObj, nSim=100, deltaTrue=0) simulate(object=designObj, deltraTrue=0, nSim=100, freqOptioStop=TRUE, nPlanFreq=freqObj$nPlan)
Simulate the coverage of a safe confidence sequence for differences between proportions for a given distribution and safe design.
simulateCoverageDifferenceTwoProportions( successProbabilityA, trueDelta, safeDesign, precision = 100, M = 1000, numberForSeed = NA )
simulateCoverageDifferenceTwoProportions( successProbabilityA, trueDelta, safeDesign, precision = 100, M = 1000, numberForSeed = NA )
successProbabilityA |
probability of observing a success in group A. |
trueDelta |
difference in probability between group A and B. |
safeDesign |
a safe test design for two proportions retrieved through |
precision |
precision of the grid to search over for the confidence sequence bounds. Default 100. |
M |
number of simulations to carry out. Default 1000. |
numberForSeed |
number for seed to set, default NA. |
the proportion of simulations where the trueDelta was included in the confidence sequence.
balancedSafeDesign <- designSafeTwoProportions(na = 1, nb = 1, nBlocksPlan = 20) simulateCoverageDifferenceTwoProportions(successProbabilityA = 0.2, trueDelta = 0, safeDesign = balancedSafeDesign, M = 100, precision = 20, numberForSeed = 1082021)
balancedSafeDesign <- designSafeTwoProportions(na = 1, nb = 1, nBlocksPlan = 20) simulateCoverageDifferenceTwoProportions(successProbabilityA = 0.2, trueDelta = 0, safeDesign = balancedSafeDesign, M = 100, precision = 20, numberForSeed = 1082021)
Simulate incorrect optional stopping with fisher's exact test's p-value as the stopping rule.
simulateIncorrectStoppingTimesFisher( thetaA, thetaB, alpha, na, nb, maxSimStoptime = 10000, M = 1000, numberForSeed = NULL )
simulateIncorrectStoppingTimesFisher( thetaA, thetaB, alpha, na, nb, maxSimStoptime = 10000, M = 1000, numberForSeed = NULL )
thetaA |
Bernoulli distribution parameter in group A |
thetaB |
Bernoulli distribution parameter in group B |
alpha |
Significance level |
na |
number of observations in group a per data block |
nb |
number of observations in group b per data block |
maxSimStoptime |
maximal number of blocks to sample in each experiment |
M |
Number of simulations to carry out, default 1e3. |
numberForSeed |
number for seed to set, default NULL. |
list with stopping times and rejection decisions.
simulateIncorrectStoppingTimesFisher(thetaA = 0.3, thetaB = 0.3, alpha = 0.05, na = 1, nb = 1, M = 10, maxSimStoptime = 100, numberForSeed = 251)
simulateIncorrectStoppingTimesFisher(thetaA = 0.3, thetaB = 0.3, alpha = 0.05, na = 1, nb = 1, M = 10, maxSimStoptime = 100, numberForSeed = 251)
Simulate an optional stopping scenario according to a safe design for two proportions
simulateOptionalStoppingScenarioTwoProportions(safeDesign, M, thetaA, thetaB)
simulateOptionalStoppingScenarioTwoProportions(safeDesign, M, thetaA, thetaB)
safeDesign |
a 'safeDesign' object obtained through |
M |
integer, the number of data streams to sample. |
thetaA |
Bernoulli distribution parameter in group A |
thetaB |
Bernoulli distribution parameter in group B |
list with the simulation results of the safe test under optional stopping with the following components:
Proportion of sequences where H0 was rejected
Mean stopping time
Proportion of experiments stopped before nBlocksPlan was reached
Minimum stopping time
All achieved E values
All stopping times
Decisions on rejecting H0 for each M
Stopping times of experiments where H0 was rejected
balancedSafeDesign <- designSafeTwoProportions(na = 1, nb = 1, nBlocksPlan = 30) optionalStoppingSimulationResult <- simulateOptionalStoppingScenarioTwoProportions( safeDesign = balancedSafeDesign, M = 1e2, thetaA = 0.2, thetaB = 0.5 )
balancedSafeDesign <- designSafeTwoProportions(na = 1, nb = 1, nBlocksPlan = 30) optionalStoppingSimulationResult <- simulateOptionalStoppingScenarioTwoProportions( safeDesign = balancedSafeDesign, M = 1e2, thetaA = 0.2, thetaB = 0.5 )
Simulates for a range of divergence parameter values (differences or log odds ratios) the worst-case stopping times (i.e., number of data blocks collected) and expected stopping times needed to achieve the desired power for each hyperparameter setting provided.
simulateTwoProportions( hyperparameterList, alternativeRestriction = c("none", "difference", "logOddsRatio"), deltaDesign = NULL, alpha, beta, na, nb, deltamax = 0.9, deltamin = 0.1, deltaGridSize = 8, M = 100, maxSimStoptime = 10000, thetaAgridSize = 8 )
simulateTwoProportions( hyperparameterList, alternativeRestriction = c("none", "difference", "logOddsRatio"), deltaDesign = NULL, alpha, beta, na, nb, deltamax = 0.9, deltamin = 0.1, deltaGridSize = 8, M = 100, maxSimStoptime = 10000, thetaAgridSize = 8 )
hyperparameterList |
list object, its components hyperparameter lists with a format as described in |
alternativeRestriction |
a character string specifying an optional restriction on the alternative hypothesis; must be one of "none" (default), "difference" (difference group mean b minus group b) or "logOddsRatio" (the log odds ratio between group means b and a). |
deltaDesign |
optional; when using a restricted alternative, the value of the divergence measure used. Either a numeric between -1 and 1 for a restriction on difference, or a real for a restriction on the log odds ratio. |
alpha |
numeric in (0, 1) that specifies the tolerable type I error control –independent on n– that the designed test has to adhere to. Note that it also defines the rejection rule e10 > 1/alpha. |
beta |
numeric in (0, 1) that specifies the tolerable type II error control in the study. Necessary to calculate the worst case stopping time. |
na |
number of observations in group a per data block |
nb |
number of observations in group b per data block |
deltamax |
maximal effect size to calculate power for; between -1 and 1 for designs without restriction or a restriction on difference;
real number for a restriction on the log odds ratio. Default |
deltamin |
minimal effect size to calculate power for; between -1 and 1 for designs without restriction or a restriction on difference;
real number for a restriction on the log odds ratio. Default |
deltaGridSize |
numeric, positive integer: size of grid of delta values worst case and expected sample sizes are simulated for. |
M |
number of simulations used to estimate sample sizes. Default |
maxSimStoptime |
maximal stream length in simulations; when the e value does not reach the rejection threshold before the end of the stream,
the maximal stream length is returned as the stopping time. Default |
thetaAgridSize |
numeric, positive integer: size of the grid of probability distributions examined for each delta value to find the worst case sample size over. |
Returns an object of class "safe2x2Sim". An object of class "safe2x2Sim" is a list containing at least the following components:
A data frame containing simulation results with worst case and expected stopping times for each hyperparameter setting, for the specified or default range of effect sizes.
the significance threshold used in the simulations
the type-II error control used in the simulations
the value of restriction on the alternative hypothesis parameter space used for the E variables in the simulations
the type of restriction used for the E variables in the simulation
list of the hyperparameters tested in the simulation
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)
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)
NA
The evaluation fails with NA
by default, but it is also able to fail with other values.
tryOrFailWithNA(expr, value = NA_real_)
tryOrFailWithNA(expr, value = NA_real_)
expr |
Expression to be evaluated. |
value |
Return value if there is an error, default is |
Returns the evaluation of the expression, or value
if it doesn't work out.