# Functions for continuous monitoring harm boundary
# --------------------------------------------------
# Functions intended to be used directly:
#  1. getHarmBounds
#  2. getAlphaPerTest
#
# Brief Description of functions
#  'getHarmBounds' is the function that creates the 'potential harm' stopping bounds.
#     It takes as input values for: 
#      'nevents' = the total number of events at which a bound should be created
#      'alpha_test' = the nominal alpha level to use for each test
#      'p0' = proportions of events in experimental group under the null
			(the randomization ratio in an RCT). 0.5 by default.
#   The output is a  data frame with a row for each interim analysis and with columns for
#	number of events (n),
#	number of events in control and experimental group that would lead to a stop (n_treat, n_control),
#	risk ratio (RR) at that level,
#	sopping probability (stopProb),
#	cumulative stopping probability (cumStopProb).
#	and the nominal alpha for each test (alphaVal)
      
#       'n' - the event total that the row provides the bounds for
#       'n_treat' - the stopping boundary for the number of events in the treatment group.
#       'n_control' - the number of events in the control group at the boundary
#       'RR' - the estimated relative risk at the boundary
#       'stopProb' - the probability of stopping at the given row's boundary
#       'cumStopProb' - the probability of stopping at or before the given row's boundary
#       'alphaVal' - the value of per.test passed to the function
#  
#  'getAlphaPerTest' is a function to use prior to running 'getHarmBounds' to find a 
#       per-test alpha level that will control the sequence-wise type-I error rate 
#       (i.e. the type-I error over the entire sequence of tests), at a particular level.
#
#     Inputs are:
#       'nevents' - <same as above> 
#       'p0'  - <same as above>
#       'totalAlpha' - desired total type-I error rate over the sequence of tests
#       'alpha.interval' - the interval over which the function searches for the 
#                          per-test alpha level.  The default should generally suffice.
#
#     Output: numeric vector of length 1
#
#     The function outputs a single numeric value - a 'per test alpha level' which, if
#     passed to 'getHarmBounds' along with the harmBoundRange and null.p will provide 
#     bounds that have a sequence-wise type-I error rate as given by 'totalAlpha'.



