Title: | Exact Confidence Limits after a Sequential Trial |
---|---|
Description: | The user first provides design vectors n, a and b as well as null (p0) and alternative (p1) benchmark values for the probability of success. The key function "mv.plots.SM()" calculates mean values of exact upper and lower limits based on four different rank ordering methods. These plots form the basis of selecting a rank ordering. The function "inference()" calculates exact limits from a provided realisation and ordering choice. For more information, see "Exact confidence limits after a group sequential single arm binary trial" by Lloyd, C.J. (2020), Statistics in Medicine, Volume 38, 2389-2399, <doi:10.1002/sim.8909>. |
Authors: | Chris J. Lloyd |
Maintainer: | Chris J. Lloyd <[email protected]> |
License: | GPL-2 |
Version: | 1.0.1 |
Built: | 2025-02-14 03:55:17 UTC |
Source: | https://github.com/cran/CLAST |
The user first provides design vectors n, a and b as well as null (p0) and alternative (p1) benchmark values for the probability of success. The key function "mv.plots.SM()" calculates mean values of exact upper and lower limits based on four different rank ordering methods. These plots form the basis of selecting a rank ordering. The function "inference()" calculates exact limits from a provided realisation and ordering choice. For more information, see "Exact confidence limits after a group sequential single arm binary trial" by Lloyd, C.J. (2020), Statistics in Medicine, Volume 38, 2389-2399, <doi:10.1002/sim.8909>.
This package allows the user to compare different methods of calculating exact upper and lower limits for a probability after a group sequential trial.
Chris J. Lloyd Maintainer: Chris J. Lloyd <[email protected]>
Lloyd, C.J. (2020) Exact confidence limits after a group sequential single arm binary trial. Statistics in Medicine, Volume 38, 2389-2399. doi:10.1002/sim.8909
# Example 1 in table 1 of Lloyd (2020) n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) plt.sample.space.SM(n,a,b) # Produces figure 1 in reference # p0=.4 p1=.75 errors.SM(n,a,b,p0,p1) # Gives type 1 and type 2 errors plt.sample.space.SM(n,a,b,p0,p1) # Add error rates into plot title # # Selection of type of limits is based on the diagnostic plots # from the next command, which produces three panel graphic # identical to Figure 2 in the main reference. The results here # support method LR mv.plots.SM(n,a,b,p0=p0,p1=p1) # Once we have an actual outcome we can calculate the limits. y=c(4,2,5) # Trial terminates on trial 2 since total successes is 11. inference(n,a,b,y,type="LR") # Produces exact limits for specific outcome y.
# Example 1 in table 1 of Lloyd (2020) n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) plt.sample.space.SM(n,a,b) # Produces figure 1 in reference # p0=.4 p1=.75 errors.SM(n,a,b,p0,p1) # Gives type 1 and type 2 errors plt.sample.space.SM(n,a,b,p0,p1) # Add error rates into plot title # # Selection of type of limits is based on the diagnostic plots # from the next command, which produces three panel graphic # identical to Figure 2 in the main reference. The results here # support method LR mv.plots.SM(n,a,b,p0=p0,p1=p1) # Once we have an actual outcome we can calculate the limits. y=c(4,2,5) # Trial terminates on trial 2 since total successes is 11. inference(n,a,b,y,type="LR") # Produces exact limits for specific outcome y.
Calculates the exact Clopper-Pearson lower limit for a binomial probability based on x successes from n trials
CP.lower(x, n, a = 0.05)
CP.lower(x, n, a = 0.05)
x |
number of successes (integer between 0 and n inclusive) |
n |
number of binary trials |
a |
coverage error of limit |
A numeric value between 0 and 1
Chris J. Lloyd
Clopper, C. and Pearson, E. S. (1934). The use of confidence or fiducial limits illustrated in the case of the binomial. Biometrika, 26 (4): 404-413. doi:10.2307/2331986
# Find exact 99% lower limit for probability based on 20 successes from 55 trials. CP.lower(20,55,a=0.01) # Find exact (95%) lower limit for probability based on all failures. CP.lower(0,5)
# Find exact 99% lower limit for probability based on 20 successes from 55 trials. CP.lower(20,55,a=0.01) # Find exact (95%) lower limit for probability based on all failures. CP.lower(0,5)
Calculates all possible Clopper-Pearson limits for p from an object that contains all possible data sets from a group sequential trial.
CP.stats.SM(obj, alpha = 0.05, type = "upper")
CP.stats.SM(obj, alpha = 0.05, type = "upper")
obj |
a list with elements S, M and design, containing all possible values of total successes S and stopping stage M based on the given design. Typically this is the output of function sample.space or sample.space.2 and will also have elements Y and decision. |
alpha |
coverage error of exact limits |
type |
character, either "upper" or "lower" |
a list with element "lims" as well as all elements of argument obj. The extra element contains the CP limit for each possible outcome.
Chris J. LLoyd
Clopper, C. and Pearson, E. S. (1934). The use of confidence or fiducial limits illustrated in the case of the binomial. Biometrika, 26 (4): 404-413. doi:10.2307/2331986
n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) # There are 364 possible outcomes from this design which are # listed in a natural systematic order by function sample.space. all.samples=sample.space(n,a,b) attributes(all.samples) # Y contains the 364 possible sequential binary outcomes; # M contains how many stages before the decision; # S contains the total number of success that produces the decision; # decision the final binary test result of H0 or H1. CP.stats.SM(obj=all.samples)
n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) # There are 364 possible outcomes from this design which are # listed in a natural systematic order by function sample.space. all.samples=sample.space(n,a,b) attributes(all.samples) # Y contains the 364 possible sequential binary outcomes; # M contains how many stages before the decision; # S contains the total number of success that produces the decision; # decision the final binary test result of H0 or H1. CP.stats.SM(obj=all.samples)
Calculates the exact Clopper-Pearson upper limit for a binomial probability based on x successes from n trials
CP.upper(x, n, a = 0.05)
CP.upper(x, n, a = 0.05)
x |
number of successes (integer between 0 and n inclusive) |
n |
number of binary trials |
a |
coverage error of limit |
A numeric value between 0 and 1
Chris J. Lloyd
Clopper, C. and Pearson, E. S. (1934). The use of confidence or fiducial limits illustrated in the case of the binomial. Biometrika, 26 (4): 404-413. doi:10.2307/2331986
# Find exact 99% upper limit for probability based on 20 successes from 55 trials. CP.upper(20,55,a=0.01) # Find exact (95%) upper limit for probability from all successes. CP.lower(5,5)
# Find exact 99% upper limit for probability based on 20 successes from 55 trials. CP.upper(20,55,a=0.01) # Find exact (95%) upper limit for probability from all successes. CP.lower(5,5)
This operation is useful in recursively generating all the possible path histories of a sequential design.
cross(A, v)
cross(A, v)
A |
An arbitrary matrix |
v |
An arbitrary vector |
For each component of v, the matrix A is duplicated with an extra right column equal to v[i]. This is added to the current output until the components of v are exhausted.
A matrix with dim(A)[2]+1 columns and dim(A)[1]*length(v) rows.
Chris J. Lloyd
A=cbind(c(1,2),c(3,4)) v=c(5,6) cross(A,v) # [,1] [,2] [,3] #[1,] 1 3 5 #[2,] 2 4 5 #[3,] 1 3 6 #[4,] 2 4 6
A=cbind(c(1,2),c(3,4)) v=c(5,6) cross(A,v) # [,1] [,2] [,3] #[1,] 1 3 5 #[2,] 2 4 5 #[3,] 1 3 6 #[4,] 2 4 6
For a given sequential design defined by vectors a, b and n, calculate the probability of a type 1 error (assuming p=p0) and type 2 error (assuming p=p1)
errors.SM(n, a, b, p0, p1)
errors.SM(n, a, b, p0, p1)
n |
Design vector of planned sample sizes |
a |
Design vector of lower futility boundaries |
b |
Design vector of upper superiority boundaries |
p0 |
Lower benchnmark for success probability |
p1 |
Upper benchnmark for success probability |
list with attributes type1 and type 2
Chris J. Lloyd
# Example 1 in table 1 of Lloyd (2020) n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) p0=.4 p1=.75 errors.SM(n,a,b,p0,p1) # $type1 # [1] 0.09590162 # $type2 # [1] 0.1060701
# Example 1 in table 1 of Lloyd (2020) n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) p0=.4 p1=.75 errors.SM(n,a,b,p0,p1) # $type1 # [1] 0.09590162 # $type2 # [1] 0.1060701
Calculates Buehler lower limit for all possible data sets based on a provided ranking function.
exact.lower.limits.SM(obj, lims = NULL, alpha = 0.05, set = FALSE)
exact.lower.limits.SM(obj, lims = NULL, alpha = 0.05, set = FALSE)
obj |
list with components $count, $S, $N, typically the output of LR.stats.SM, CP.stats.SM, JT.rank.SM or ML.rank.SM. In this case, it will also have element $lims. |
lims |
a vector of same length as obj$count, most often an approximate lower limits. If this is missing, then it should be an element of obj$lims. |
alpha |
exact coverage error |
set |
If true, exact limits of 1 are replaced by the largest limit less than 1. This will never be chosen by the user and is there for certain numerical investigations. |
A numeric vector of same length as obj$lims, giving the exact lower limit for each possible outcome as listed in components obj$M and obj$S.
Chris J. Lloyd
Lloyd, C.J. (2020) Exact confidence limits after a group sequential single arm binary trial. Statistics in Medicine, Volume 38, 2389-2399.
# Example 1 in table 1 of Lloyd (2020) n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) # There are 364 possible outcomes from this design which are # listed in a natural systematic order by function sample.space. all.samples=sample.space.SM(n,a,b) attributes(all.samples) # Y contains the 364 possible sequential binary outcomes; # M contains how many stages before the decision; # S contains the total number of success that produces the decision; # decision the final binary test result of H0 or H1. all.CP=CP.stats.SM(all.samples,type="lower") all.CP$lims # These limits are based on fixed sample size so are not edxact. all.exact=exact.lower.limits.SM(all.CP) plot(all.CP$lims,all.exact)
# Example 1 in table 1 of Lloyd (2020) n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) # There are 364 possible outcomes from this design which are # listed in a natural systematic order by function sample.space. all.samples=sample.space.SM(n,a,b) attributes(all.samples) # Y contains the 364 possible sequential binary outcomes; # M contains how many stages before the decision; # S contains the total number of success that produces the decision; # decision the final binary test result of H0 or H1. all.CP=CP.stats.SM(all.samples,type="lower") all.CP$lims # These limits are based on fixed sample size so are not edxact. all.exact=exact.lower.limits.SM(all.CP) plot(all.CP$lims,all.exact)
Calculates Buehler upper limit for all possible data sets based on ranking function provided in obj$lims.
exact.upper.limits.SM(obj, lims = NULL, alpha = 0.05, set = FALSE)
exact.upper.limits.SM(obj, lims = NULL, alpha = 0.05, set = FALSE)
obj |
list with components $count, $S, $N, typically the output of LR.stats.SM, CP.stats.SM, JT.rank.SM or ML.rank.SM. In this case, it will also have element $lims. |
lims |
a vector of same length as obj$count, most often an approximate lower limits. If this is missing, then it should be an element of obj$lims. |
alpha |
exact coverage error |
set |
If true, exact limits of 0 are replaced by the smallest limit greater than 1. This will never be chosen by the user and is there for certain numerical investigations. |
A numeric vector of same length as obj$lims, giving the exact lower limit for each possible outcome as listed in components obj$M and obj$S.
Chris J. Lloyd
Lloyd, C.J. (2020) Exact confidence limits after a group sequential single arm binary trial. Statistics in Medicine, Volume 38, 2389-2399.
# Example 1 in table 1 of Lloyd (2020) n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) # There are 364 possible outcomes from this design which are # listed in a natural systematic order by function sample.space. all.samples=sample.space.SM(n,a,b) attributes(all.samples) # Y contains the 364 possible sequential binary outcomes; # M contains how many stages before the decision; # S contains the total number of success that produces the decision; # decision the final binary test result of H0 or H1. all.CP=CP.stats.SM(all.samples,type="upper") all.CP$lims # These limits are based on fixed sample size so are not edxact. all.exact=exact.upper.limits.SM(all.CP) plot(all.CP$lims,all.exact)
# Example 1 in table 1 of Lloyd (2020) n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) # There are 364 possible outcomes from this design which are # listed in a natural systematic order by function sample.space. all.samples=sample.space.SM(n,a,b) attributes(all.samples) # Y contains the 364 possible sequential binary outcomes; # M contains how many stages before the decision; # S contains the total number of success that produces the decision; # decision the final binary test result of H0 or H1. all.CP=CP.stats.SM(all.samples,type="upper") all.CP$lims # These limits are based on fixed sample size so are not edxact. all.exact=exact.upper.limits.SM(all.CP) plot(all.CP$lims,all.exact)
Calculates exact upper and lower confidence limits from the outcome of a multi-stage group sequential trial.
inference(n, a, b, y, alpha, type)
inference(n, a, b, y, alpha, type)
n |
Design vector of planned sample sizes |
a |
Design vector of lower futility boundaries |
b |
Design vector of upper superiority boundaries |
y |
Actual outcome of experiment |
alpha |
exact coverage error |
type |
character, either "LR", "CP", "JT" or "ML" |
list with components
lower |
exact lower limit, type dependent |
upper |
exact lower limit, type dependent |
est |
ML estimate |
type |
selected ordering function "LR", "CP", "JT" or "ML" |
Chris J. Lloyd
Lloyd, C.J. (2020) Exact confidence limits after a group sequential single arm binary trial. Statistics in Medicine, Volume 38, 2389-2399.
# Example from table 1 of Lloyd (2020) n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) y=c(4,2,5) # This is the actual outcome. The trial stopped for # superiority at stage m=3 with s=11 successes. inference(n,a,b,y,type="CP") # Results happen to be identical for type="LR" but different # for the alternative ordering functions "JT" and "ML"
# Example from table 1 of Lloyd (2020) n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) y=c(4,2,5) # This is the actual outcome. The trial stopped for # superiority at stage m=3 with s=11 successes. inference(n,a,b,y,type="CP") # Results happen to be identical for type="LR" but different # for the alternative ordering functions "JT" and "ML"
Calculates the Jennison & Turnbull (1983) ranking of each possible outcome of the sample space generated from a sequential design.
JT.rank.SM(obj)
JT.rank.SM(obj)
obj |
a list with elements S, M and design, containing all possible values of total successes S and stopping stage M based on the given design. Typically this is the output of function sample.space or sample.space.2 and will also have elements Y and decision. |
a list with element "lims" as well as all elements of argument obj. The extra element contains the JT rank of each possible the outcome.
Chris J. Lloyd
Jennison C, Turnbull BW. Confidence intervals for a binomial parameter following a multistage test with application to MIL-STD 105D and medical trials. Technometrics. 1983(25), 49-58. doi:10.1080/00401706.1983.10487819
n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) # There are 364 possible outcomes from this design which are # listed in a natural systematic order by function sample.space. all.samples=sample.space(n,a,b) attributes(all.samples) # Y contains the 364 possible sequential binary outcomes; # M contains how many stages before the decision; # S contains the total number of success that produces the decision; # decision the final binary test result of H0 or H1. JT.rank.SM(obj=all.samples) # Component "lims" contains the rank of each sequential binary # outcome. The same rank is assigned to outcomes with the same # values of (S,M).
n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) # There are 364 possible outcomes from this design which are # listed in a natural systematic order by function sample.space. all.samples=sample.space(n,a,b) attributes(all.samples) # Y contains the 364 possible sequential binary outcomes; # M contains how many stages before the decision; # S contains the total number of success that produces the decision; # decision the final binary test result of H0 or H1. JT.rank.SM(obj=all.samples) # Component "lims" contains the rank of each sequential binary # outcome. The same rank is assigned to outcomes with the same # values of (S,M).
Calculates approximate lower limit for a probability from x successes out of n binary trials based on the signed root likelihood ratio.
LR.lower(x, n, a = 0.05, epsilon = 1e-18)
LR.lower(x, n, a = 0.05, epsilon = 1e-18)
x |
number of successes (integer between 0 and n inclusive) |
n |
number of binary trials |
a |
coverage error of limit |
epsilon |
Tolerance supplied to uniroot. |
A numeric values between 0 and 1
Chris J. Lloyd
# Find approximate 99% lower limit for probability based on 20 successes from 55 trials. LR.lower(20,55,a=0.01) # Find exact (95%) lower limit for probability based on all failures. LR.lower(0,5)
# Find approximate 99% lower limit for probability based on 20 successes from 55 trials. LR.lower(20,55,a=0.01) # Find exact (95%) lower limit for probability based on all failures. LR.lower(0,5)
Calculates all possible LR based limits for p from an object that contains all possible data sets from a group sequential trial.
LR.stats.SM(obj, alpha = 0.05, type = "upper")
LR.stats.SM(obj, alpha = 0.05, type = "upper")
obj |
a list with elements S, M and design, containing all possible values of total successes S and stopping stage M based on the given design. Typically this is the output of function sample.space or sample.space.2 and will also have elements Y and decision. |
alpha |
nominal coverage error of approximate LR based limits |
type |
character, either "upper" or "lower" |
a list with element "lims" as well as all elements of argument obj. The extra element contains the LR exact limit for each possible outcome.
Chris J. Lloyd
n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) # There are 364 possible outcomes from this design which are # listed in a natural systematic order by function sample.space. all.samples=sample.space(n,a,b) attributes(all.samples) # Y contains the 364 possible sequential binary outcomes; # M contains how many stages before the decision; # S contains the total number of success that produces the decision; # decision the final binary test result of H0 or H1. LR.stats.SM(obj=all.samples)
n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) # There are 364 possible outcomes from this design which are # listed in a natural systematic order by function sample.space. all.samples=sample.space(n,a,b) attributes(all.samples) # Y contains the 364 possible sequential binary outcomes; # M contains how many stages before the decision; # S contains the total number of success that produces the decision; # decision the final binary test result of H0 or H1. LR.stats.SM(obj=all.samples)
Calculates approximate upper limit for a probability from x successes out of n binary trials based on the signed root likelihood ratio.
LR.upper(x, n, a = 0.05, epsilon = 1e-18)
LR.upper(x, n, a = 0.05, epsilon = 1e-18)
x |
number of successes (integer between 0 and n inclusive) |
n |
number of binary trials |
a |
coverage error of limit |
epsilon |
Tolerance supplied to uniroot. |
A numeric values between 0 and 1
Chris J. Lloyd
# Find approximate 99% upper limit for probability based on 20 successes from 55 trials. LR.upper(20,55,a=0.01) # Find exact (95%) upper limit for probability from all successes. LR.upper(5,5)
# Find approximate 99% upper limit for probability based on 20 successes from 55 trials. LR.upper(20,55,a=0.01) # Find exact (95%) upper limit for probability from all successes. LR.upper(5,5)
Calculates the ML estimator for each possible outcome of the sample space generated from a sequential design.
ML.rank.SM(obj)
ML.rank.SM(obj)
obj |
a list with elements S, M and design, containing all possible values of total successes S and stopping stage M based on the given design. Typically this is the output of function sample.space or sample.space.2 and will also have elements Y and decision. |
a list with element "lims" as well as all elements of argument obj. The extra element contains the ML estimator of p for each possible outcome.
Chris J. Lloyd
n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) # There are 364 possible outcomes from this design which are # listed in a natural systematic order by function sample.space. all.samples=sample.space(n,a,b) attributes(all.samples) # Y contains the 364 possible sequential binary outcomes; # M contains how many stages before the decision; # S contains the total number of success that produces the decision; # decision the final binary test result of H0 or H1. ML.rank.SM(obj=all.samples)$lims # Component "lims" contains the value of the ML estimate i.e. # total successes S divided by total trials N. The same ML # estimator occurs for outcomes with the same values of (S,M).
n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) # There are 364 possible outcomes from this design which are # listed in a natural systematic order by function sample.space. all.samples=sample.space(n,a,b) attributes(all.samples) # Y contains the 364 possible sequential binary outcomes; # M contains how many stages before the decision; # S contains the total number of success that produces the decision; # decision the final binary test result of H0 or H1. ML.rank.SM(obj=all.samples)$lims # Component "lims" contains the value of the ML estimate i.e. # total successes S divided by total trials N. The same ML # estimator occurs for outcomes with the same values of (S,M).
Plots mean value of upper limit, lower limit and interval width for four different ranking methods. This function is basically a wrapper for mv.plot.
mv.plots.SM(n, a, b, type = "interval", B = 100, offset = TRUE, plt = c(1, 1, 1), p0 = NULL, p1 = NULL, focus = FALSE)
mv.plots.SM(n, a, b, type = "interval", B = 100, offset = TRUE, plt = c(1, 1, 1), p0 = NULL, p1 = NULL, focus = FALSE)
n |
Design vector of planned sample sizes |
a |
Design vector of lower futility boundaries |
b |
Design vector of upper superiority boundaries |
type |
Either "upper", "lower" or "interval" (default) |
B |
Integer controlling fineness of plot (default=100) |
offset |
if TRUE then ML mean value is subtracted |
plt |
Logical vector indicating output plots of upper, lower and interval (default=c(1,1,1)) |
p0 |
Lower (null) benchmark for success probability |
p1 |
Upper (alternative) benchmark for success probability |
focus |
Logical. If true, plots are restricted to p between p0 and p1. (default=FALSE) |
NULL
Chris J. Lloyd
Lloyd, C.J. (2021) Exact confidence limits after a group sequential single arm binary trial. Statistics in Medicine, Volume 38, 2389-2399. doi:10.1002/sim.8909
# Figure 2 in Lloyd (2020) n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) p0=.4 p1=.75 mv.plots.SM(n,a,b,p0=p0,p1=p1) # Produces three panel graphic identical to Figure 2 in reference mv.plots.SM(n,a,b,p0=p0,p1=p1,focus=TRUE) # Produces alternative graphic focussed on relevant values of p. # In both cases LR (in blue) appears best. CP can perform poorly # for values of p outside the range of interest.
# Figure 2 in Lloyd (2020) n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) p0=.4 p1=.75 mv.plots.SM(n,a,b,p0=p0,p1=p1) # Produces three panel graphic identical to Figure 2 in reference mv.plots.SM(n,a,b,p0=p0,p1=p1,focus=TRUE) # Produces alternative graphic focussed on relevant values of p. # In both cases LR (in blue) appears best. CP can perform poorly # for values of p outside the range of interest.
Calculates mean value of a provided vector of upper limits as a function of p
mv.SM(obj, lims = NULL, p = NULL, B = 99, offset = TRUE, wgt = TRUE)
mv.SM(obj, lims = NULL, p = NULL, B = 99, offset = TRUE, wgt = TRUE)
obj |
list with components $S, $N, $count and optionally $lims, typically the output of sample.space.SM |
lims |
if not a component of obj |
p |
vector of values of p at which to calculate mean value |
B |
number of evenly spaced values of p if not provided |
offset |
if TRUE then ML mean value is subtracted |
wgt |
if TRUE than assign zero probability weight to extreme limits of 1 or 0. |
list with elements $x (containing grid of B values of probability) and $y (containing corresponding mean values)
Chris J. Lloyd
n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) # Enumerate all possible elements of the sufficiency reduced samples # space i.e. all values of S and M. Also listed are the counts and # subcounts of these outcomes, the test decision and the vector # n, a, and b in $design data.SM=sample.space.SM(n,a,b) # There are 26 elements. # Calculate all approximate LR upper limits for these 26 outcomes. all.LR.high=LR.stats.SM(data.SM,type="upper")$lims # Calculate all approximate LR upper limits for these 26 outcomes. all.LR.low=LR.stats.SM(data.SM,type="lower")$lims # Calculate the mean values of these lims as a function of p mv.high=mv.SM(data.SM,all.LR.high,p=(1:99)/100,offset=FALSE) mv.low=mv.SM(data.SM,all.LR.low,p=(1:99)/100,offset=FALSE) plot(c(0,1),c(0,1),ylab="mean value",xlab="p",type="n") lines(mv.high) lines(mv.low) abline(0,1,lty=3) title(main="Mean value of upper and lower limits by p")
n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) # Enumerate all possible elements of the sufficiency reduced samples # space i.e. all values of S and M. Also listed are the counts and # subcounts of these outcomes, the test decision and the vector # n, a, and b in $design data.SM=sample.space.SM(n,a,b) # There are 26 elements. # Calculate all approximate LR upper limits for these 26 outcomes. all.LR.high=LR.stats.SM(data.SM,type="upper")$lims # Calculate all approximate LR upper limits for these 26 outcomes. all.LR.low=LR.stats.SM(data.SM,type="lower")$lims # Calculate the mean values of these lims as a function of p mv.high=mv.SM(data.SM,all.LR.high,p=(1:99)/100,offset=FALSE) mv.low=mv.SM(data.SM,all.LR.low,p=(1:99)/100,offset=FALSE) plot(c(0,1),c(0,1),ylab="mean value",xlab="p",type="n") lines(mv.high) lines(mv.low) abline(0,1,lty=3) title(main="Mean value of upper and lower limits by p")
Plots decision function in S-M space with boundary vectors "a" and "b". If p0 and p1 are provided then the type 1 and type 2 error are displayed in the main graphic title
plt.sample.space.SM(n, a, b, p0 = NULL, p1 = NULL)
plt.sample.space.SM(n, a, b, p0 = NULL, p1 = NULL)
n |
Design vector of sample sizes |
a |
Design vector of lower boundaries |
b |
Design vector of upper boundaries |
p0 |
Lower benchnmark for success probability |
p1 |
Upper benchnmark for success probability |
NULL
Chris J. Lloyd
Lloyd, C.J. (2020) Exact confidence limits after a group sequential single arm binary trial. Statistics in Medicine, Volume 38, 2389-2399. doi:10.1002/sim.8909
# Figure 1 of Lloyd (2020) n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) plt.sample.space.SM(n,a,b) # produces plots in Figure 1 or reference.
# Figure 1 of Lloyd (2020) n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) plt.sample.space.SM(n,a,b) # produces plots in Figure 1 or reference.
Calculates probability distribution of sufficient statistics (S,M) from sample space object.
prob.SM(data, p, m = NULL, s = NULL)
prob.SM(data, p, m = NULL, s = NULL)
data |
list with components $Y, $S, $M, $design, $count. Thsi will typically be the output of sample.space or sample.space.2. |
p |
value of binary probability |
m |
number of stages at end of sequential trial |
s |
number of successes at end of sequential trial |
list with component $prob, $count, $subcount and matrix $data giving the $subcount different binary sequential outcomes that lead to $prob.
Chris J. Lloyd
Lloyd, C.J. (2020) Exact confidence limits after a group sequential single arm binary trial. Statistics in Medicine, Volume 38, 2389-2399. doi:10.1002/sim.8909
n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) # There are 364 possible outcomes from this design which are # listed in a natural systematic order by function sample.space. all.samples=sample.space(n,a,b) attributes(all.samples) # Y contains the 364 possible sequential binary outcomes; # M contains how many stages before the decision; # S contains the total number of success that produces the decision; # decision the final binary test result of H0 or H1. prob.SM(all.samples,p=.5,m=3,s=11)
n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) # There are 364 possible outcomes from this design which are # listed in a natural systematic order by function sample.space. all.samples=sample.space(n,a,b) attributes(all.samples) # Y contains the 364 possible sequential binary outcomes; # M contains how many stages before the decision; # S contains the total number of success that produces the decision; # decision the final binary test result of H0 or H1. prob.SM(all.samples,p=.5,m=3,s=11)
An alternative to the function rank (which replaces ties by average rank). This function instead gives each tied value the same rank. The output will have the same length as x but contain integer values from 1 to length(unique(x)).
RANK(x)
RANK(x)
x |
a numeric vector |
Vector of integer ranks of the same length as x.
Chris J. Lloyd
x=c(5,4,4,7,6) rank(x) # 3.0 1.5 1.5 5.0 4.0 RANK(x) # 2 1 1 4 3
x=c(5,4,4,7,6) rank(x) # 3.0 1.5 1.5 5.0 4.0 RANK(x) # 2 1 1 4 3
Creates all possible samples from a multi-stage group sequential trial with K>2. If K=2, use the function sample.space.2 instead.
sample.space(n, a, b)
sample.space(n, a, b)
n |
Design vector of planned sample sizes |
a |
Design vector of lower futility boundaries |
b |
Design vector of upper superiority boundaries |
list with components $Y, $M, $S, $decision and $design
Chris J. Lloyd
Lloyd, C.J. (2020) Exact confidence limits after a group sequential single arm binary trial. Statistics in Medicine, Volume 38, 2389-2399. doi:10.1002/sim.8909
n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) # There are 364 possible outcomes from this design which are # listed in a natural systematic order by function sample.space. all.samples=sample.space(n,a,b) attributes(all.samples) # Y contains the 364 possible sequential binary outcomes; # M contains how many stages before the decision; # S contains the total number of success that produces the decision; # decision the final binary test result of H0 or H1.
n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) # There are 364 possible outcomes from this design which are # listed in a natural systematic order by function sample.space. all.samples=sample.space(n,a,b) attributes(all.samples) # Y contains the 364 possible sequential binary outcomes; # M contains how many stages before the decision; # S contains the total number of success that produces the decision; # decision the final binary test result of H0 or H1.
Creates all possible samples from a multi-stage group sequential trial with K=2. If K>2, use the function sample.space instead.
sample.space.2(n, a, b)
sample.space.2(n, a, b)
n |
Design vector of planned sample sizes |
a |
Design vector of lower futility boundaries |
b |
Design vector of upper superiority boundaries |
list with components $Y, $M, $S, $decision and $design
Chris J. Lloyd
Lloyd, C.J. (2020) Exact confidence limits after a group sequential single arm binary trial. Statistics in Medicine, Volume 38, 2389-2399. doi:10.1002/sim.8909
n=c(5,6) a=c(2,6) b=c(5,7) # There are 18 possible outcomes from this design which are # listed in a natural systematic order by function sample.space. all.samples=sample.space.2(n,a,b) attributes(all.samples) # Y contains the 18 possible sequential binary outcomes; # M contains how many stages before the decision; # S contains the total number of success that produces the decision; # decision the final binary test result of H0 or H1.
n=c(5,6) a=c(2,6) b=c(5,7) # There are 18 possible outcomes from this design which are # listed in a natural systematic order by function sample.space. all.samples=sample.space.2(n,a,b) attributes(all.samples) # Y contains the 18 possible sequential binary outcomes; # M contains how many stages before the decision; # S contains the total number of success that produces the decision; # decision the final binary test result of H0 or H1.
Creates all possible samples from a multi-stage group sequential trial for K>=2 by calling sample.space or sample.space.2.
sample.space.SM(n,a,b)
sample.space.SM(n,a,b)
n |
Design vector of planned sample sizes |
a |
Design vector of lower futility boundaries |
b |
Design vector of upper superiority boundaries |
list with components
M |
number of trials for each possible trial outcome |
S |
number of responses for each possible trial outcome |
N |
number of patients for each possible trial outcome |
count |
combinatoric multiplier for probability distribution |
subcountM |
combinatoric components for probability distribution |
decision |
test decision for each possible trial outcome |
design |
list giving design vectors |
Chris J. Lloyd
Lloyd, C.J. (2020) Exact confidence limits after a group sequential single arm binary trial. Statistics in Medicine, Volume 38, 2389-2399. doi:10.1002/sim.8909
# Example 1 in table 1 of Lloyd (2020) n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) sample.space.SM(n,a,b) # Object describing all 26 possible outcomes for (s,m).
# Example 1 in table 1 of Lloyd (2020) n=c(5,6,5,9) a=c(2,4,5,12) b=c(5,9,11,13) sample.space.SM(n,a,b) # Object describing all 26 possible outcomes for (s,m).