bayesassurance: An R package for calculating sample size and Bayesian assurance

We present a bayesassurance R package that computes the Bayesian assurance under various settings characterized by different assumptions and objectives. The package offers a constructive set of simulation-based functions suitable for addressing a wide range of clinical trial study design problems. We provide a detailed description of the underlying framework embedded within each of the power and assurance functions and demonstrate their usage through a series of worked-out examples. Through these examples, we hope to corroborate the advantages that come with using a two-stage generalized structure. We also illustrate scenarios where the Bayesian assurance and frequentist power overlap, allowing the user to address both Bayesian and classical inference problems provided that the parameters are properly defined. All assurance-related functions included in this R package rely on a two-stage Bayesian method that assigns two distinct priors to evaluate the unconditional probability of observing a positive outcome, which in turn addresses subtle limitations that take place when using the standard single-prior approach.


Introduction
Power and sample size analysis is an essential component for developing well-structured study designs.In the classical setting, identifying an appropriate sample size to achieve a desired statistical power offers valuable insight when making decisions.Power curves serve as a useful tool in quantifying the degree of assurance held towards meeting a study's analysis objective across a range of sample sizes.Formulating sample size determination as a decision problem so that power is an increasing function of sample size, offers the investigator a visual aid in helping deduce the minimum sample size needed to achieve a desired power.
The overarching idea of Bayesian assurance relies on measuring the probability of meeting a arXiv:2203.15154v1[stat.ME] 29 Mar 2022 desired objective.The Bayesian setting has allocated a decent amount of attention towards sample size determination, accumulating a diverse collection of methods stemming from different perspectives over the last few decades.Within this vast collection of methodologies contains a class of approaches that determine sample size based upon some criteria of analysis or model performance (Rahme, Lawrence, and Gyorkos (2000); Gelfand and Wang (2002); O' Hagan and Stevens (2001)).Other proposed solutions of the sample size problem take on a more tailored approach and introduce frameworks that prioritize conditions specific to the problem at hand, e.g. the use of Bayesian average errors to simultaneously control for Type I and Type II errors (Reyes and Ghosh 2013), the use of posterior credible interval lengths to gauge sample size estimates (Joseph, Berger, and Belisle 1997), and the use of survival regression models to target Bayesian meta-experimental designs (Reyes and Ghosh 2013).
There are currently several R packages pertaining to Bayesian sample size calculations, each targeting a different set of study design approaches.The SampleSizeMeans package produced by Lawrence Joseph and Patrick Belisle contains a series of functions used for determining appropriate sample sizes based on various Bayesian criteria for estimating means or differences between means within a normal setting (Joseph and Belisle 2012).Criteria considered include the Average Length Criterion, the Average coverage criterion, and the Modified Worst Outcome Criterion (Joseph, Wolfson, and du Berger 1995;Joseph and Belisle 1997).A supplementary package, SampleSizeProportions, addresses study designs for estimation of binomial proportions using the same set of criteria listed (Joseph and Belisle 2009).Our package, also addresses the application of criteria based within the normal and binomial setting, places strong emphasis on a two-stage framework primarily within the context of conjugate Bayesian linear regression models, where we consider the situation with known and unknown variances.Our R package also offers the flexibility of considering unequal sample sizes for two samples as well as longitudinal study designs.
The bayesassurance package contains a collection of functions that can be divided into three categories based on design and usage.These include closed-form solutions, simulation-based solutions, and visualization and/or design purposes.All available functions are categorized and briefly described in Table 1.The manuscript is organized as follows.Section 2 introduces one of the more basic features included in the package that is linked to the fundamental closed-form solution of assurance.This section also introduces the notion of overlapping behaviors exhibited between the Bayesian and frequentist settings, a concept that is frequently brought up and discussed throughout the paper.Sections 3 and 4 explore simulation-based assurance methods, outlining the statistical framework associated with each method followed by examples worked out in R that users could replicate.Section 5 discusses a related topic similar to the assurance that determines sample size in relation to the rate of correct classification.Here we discuss how a Bayesian goal function is formulated and applied in the context of sample size determination.Section 6 offers some useful graphical features and design matrix generators embedded within the assurance-based functions.In the following sections, we provide a detailed overview for each of the functions available grouped by category followed with worked out examples in R.

Closed-form Solution of Assurance
The Bayesian assurance evaluates the tenability of attaining a specified outcome through the implementation of prior and posterior distributions.computes the exact assurance using a closed-form solution.
The setup of the assurance framework is comparable to that of the classical power setting but avoids the hypothesis testing structure and refrains from the use of absolute phrases such as "rejecting" or "failing to reject the null hypothesis".Instead, the Bayesian paradigm defines an objective that users wish to measure the probability of attaining.Suppose we seek to evaluate the tenability of θ > θ 0 given data from a Gaussian population with mean θ and known variance σ 2 .We assign two sets of priors for θ, one at the design stage and the other at the analysis stage.These two stages are the primary components that make up the skeleton of our generalized solution in the Bayesian setting and will be revisited in later sections.The analysis objective specifies the condition that needs to be satisfied.It defines a positive outcome, which serves as an overarching criteria that characterizes the study.In this setting, the analysis objective is to observe P (θ > θ 0 |ȳ) > 1 − α.The design objective seeks a sample size that is needed to ensure that the analysis objective is met 100δ% of the time, where δ denotes the assurance.
Let θ ∼ N θ 1 , σ 2 na be our analysis stage prior and θ ∼ N θ 1 , σ 2 n d be our design stage prior, where n a and n d are precision parameters that quantify the degree of belief towards parameter θ and the population from which we are drawing samples from to evaluate θ.Then given the likelihood ȳ ∼ N θ, σ 2 n , we can obtain the posterior distribution of θ by multiplying the analysis prior and likelihood: This posterior distribution gives us P (θ > θ 0 |ȳ) and the assurance is then defined as The assurance expression can be expanded out further by using the marginal distribution of ȳ, which is obtained by Since the assurance definition is conditioned on ȳ, we use this to standardize the assurance expression to obtain the following closed-form solution: The assurance_nd_na() function requires the following specified parameters: 1. n: sample size (either scalar or vector) 2. n_a: precision parameter within the analysis stage that quantifies the degree of belief carried towards parameter θ 3. n_d: precision parameter within the design stage that quantifies the degree of belief of the population from which we are generating samples from 4. theta_0: initial parameter value provided by the client 5. theta_1: prior mean of θ assigned in the analysis and design stage 6. sigsq: known variance 7. alt: specifies alternative test case, where alt = "greater" tests if θ 1 > θ 0 ,alt = "less" tests if θ 1 < θ 0 , and alt = "two.sided"performs a two-sided test for θ 1 = θ 0 .By default, alt = "greater".

alpha: significance level
Consider the following code that loads in the bayesassurance package and assigns arbitrary parameters to assurance_nd_na() prior to executing the function.
There are a few points worth noting from the above code block as they are pertinent to the vast majority of functions contained within bayesassurance.First, we are passing a vector of sample sizes for n and saving the results as an arbitrary variable out.The list of objects returned by the function is contingent on whether the user passes in a scalar or vector for n.If n is a scalar, this notifies the program that we only want to determine the assurance for one particular sample size.When this is the case, out will only report a single assurance value with no plot.On the other hand, if a vector of sample sizes is passed in to n, as is the case for the code sample above, this suggests the user wants to determine the assurance for an array of sample sizes, and the function will produce both a table and an assurance curve showcasing the results.As long as n holds a length of at least two, assurance_nd_na will create a graphical display of the assurance values for an array of sample sizes surrounding those values of n that were passed in, with specific points of interest labeled in red. Figure 1 shows the resulting assurance curve corresponding to the code segment above.The graph is created using ggplot2 which is imported into bayesassurance.Simply typing out$assurance_table and out$assurance_plot will display the table and plot respectively in this particular set of examples.

Special Case: Convergence with the Frequentist Setting
Depending on how we define the parameters in assurance_nd_na(), we could demonstrate the direct relationship held between the Bayesian and classical settings, in which the frequentist power is no more than a special case of the generalized Bayesian solution.This can easily be seen when letting n d → ∞ and setting n a = 0 in Equation (1), i.e. defining a weak analysis stage prior and a strong design stage prior, resulting in which is equivalent to the frequentist power expression that takes the form The following code chunk demonstrates this special case in R using the assurance_nd_na() function: R> library(bayesassurance) R> n <-seq(10, 250, 5) The bayesassurance package includes a pwr_freq() function that determines the statistical power of a study design given a set of fixed parameter values that adhere to the closed-form solution of power and sample size.Continuing with the one-sided case, the solution is given by where ∆ = θ 1 − θ 0 denotes the critical difference and Φ denotes the cumulative distribution function of the standard normal.Note this formula is equivalent to the special case of the assurance definition expressed in Equation (2).
To execute pwr_freq(), the following set of parameters need to be specified: 1. n: sample size (either scalar or vector) 2. theta_0: initial value specified in the null hypothesis; typically provided by the client 3. theta_1: alternative value to test against the initial value; serves as a threshold in determining whether the null is to be rejected or not 4. alt: specifies alternative test case, where alt = "greater" tests if θ 1 > θ 0 ,alt = "less" tests if θ 1 < θ 0 , and alt = "two.sided"performs a two-sided test for θ 1 = θ 0 .By default, alt = "greater".This above code produces the exact same results as the previous assurance_nd_na() example where we assigned a weak analysis prior and a strong design prior to demonstrate the overlapping behaviors that occur between the two frameworks.

Simulation-Based Functions Using Conjugate Linear Models
Hence forth, we focus on computing assurance through simulation-based means and highlight the commonplace scenario in sample size analysis where closed-form solutions are unavailable.
In Sections 3 and 4, we extend upon the two-stage design structure briefly mentioned in Section 2 and discuss how the design and analysis objectives are constructed based on the sample size criteria.Section 3, in particular, draws attention to simulations set within the conjugate Bayesian linear model framework, while Section 4 addresses conditions delineated in other settings.Each simulation-based function is characterized by a well-defined objective that we seek to evaluate the tenability of.This takes place in the analysis stage.The functions take an iterative approach that alternates between generating a dataset in the design stage and evaluating whether or not the dataset satisfies the analysis stage criteria.The assurance equates to the proportion of datasets that meet the objective.
To elaborate on this idea in greater detail, we start in the analysis stage.Consider a set of n observations denoted by y = (y 1 , y 2 , • • • , y n ) that are to be collected in the presence of p controlled explanatory variables, x 1 , x 2 , • • • , x p .Specifically, where X n is an n×p design matrix with the i-th row corresponding to x i , and n ∼ N (0, σ 2 V n ), where V n is a known n × n correlation matrix.A conjugate Bayesian linear regression model specifies the joint distribution of parameters {β, σ 2 } and y as , where superscripts (a) indicate parameters in the analysis stage.The overarching objective is finding the assurance of the realized data favoring H : u β > C, where u is a p × 1 vector of fixed contrasts and C is a known constant.Inference proceeds from the posterior distribution given by p(β, where The posterior distribution helps shape our analysis objective. If σ 2 is known and fixed, then the posterior distribution of β is p(β|σ 2 , y) = N (β|M n m n , σ 2 M n ) shown in the Equation (4).We use the posterior components of β to evaluate H : u β > C, where standardization leads to Hence, to assess the tenability of H : u β > C, we decide in favor of H if the observed data belongs in the set This defines our analysis objective, which we will monitor within each sample iteration.Sample generation is taken to account for in the design stage discussed in the next section.
In the design stage, the goal is to seek a sample size n such that the analysis objective is met 100δ% of the time, where δ is the assurance.This step requires determining the marginal distribution of y, which is assigned a separate set of priors to quantify our belief about the population from which the sample will be taken.Hence, the marginal of y under the design priors will be derived from where β ∼ N (µ β ) is the design prior on β and (d) denotes parameters in the design stage.Substituting the equation for β into the equation for y gives y = Xµ β X + V n .To summarize our simulation strategy for estimating the Bayesian assurance, we fix sample size n and generate a sequence of J datasets y (1) , y (2) , ..., y (J) .A Monte Carlo estimate of the Bayesian assurance is computationally determined as where I(•) is the indicator function of the event in its argument, M (j) n and m n are the values of M n and m n computed from y (j) .

Assurance Computation with Known Variance
The simulation-based function, bayes_sim(), determines the assurance within the context of conjugate Bayesian linear regression models assuming known variance, σ 2 .The execution of bayes_sim() is straightforward.An important attribute is that users are not required to provide their own design matrix, X n , when executing bayes_sim().The algorithm automatically accommodates for the case, Xn = NULL, using the built-in function, gen_Xn(), which constructs appropriate design matrices based on entered sample size(s).Section 6 discusses design matrix generators in greater detail.Setting Xn = NULL facilitates calculation of assurances across a vector of sample sizes, where the function sequentially updates the design matrix for each unique sample size undergoing evaluation.
Implementing bayes_sim() requires defining the following set of parameters: 1. n: Sample size (either vector or scalar).If vector, each value corresponds to a separate study design.
3. u: a scalar or vector included in the expression to be evaluated, e.g.u β > C, where β is an unknown parameter that is to be estimated.
4. C: constant to be compared to 5. Xn: design matrix characterizing the observations given by the normal linear regression model y n = X n β + n , where n ∼ N (0, σ 2 V n ).See above description for details.Default Xn is an np × p matrix comprised of n × 1 ones vectors that run across the diagonal of the matrix.
6. Vbeta_d: correlation matrix that characterizes prior information on β in the design stage, i.e. β ∼ N (µ 7. Vbeta_a_inv: inverse-correlation matrix that characterizes prior information on β in the analysis stage, i.e. β ∼ N (µ β ).The inverse is passed in for computation efficiency, i.e.V −1(a) β .8. Vn: an n × n correlation matrix for the marginal distribution of the sample data y n .
Takes on an identity matrix when set to NULL.
9. sigsq: a known and fixed constant preceding all correlation matrices Vn, Vbeta_d and Vbeta_a_inv.
10. mu_beta_d: design stage mean, µ 13. alpha: significance level 14. mc_iter: number of MC samples evaluated under the analysis objective Example 1: Scalar Parameter The first example evaluates the tenability of H : u β > C in the case when β is a scalar.The following code segment assigns a set of arbitrary values for the parameters of bayes_sim() and saves the outputs as assur_vals.The first ten rows of the table is shown.
R> n <-seq(100, 300, 10) R> assur_vals <-bayesassurance::bayes_sim(n, p = 1, u = 1, C = 0.15, Xn = NULL, Vbeta_d = 0, Vbeta_a_inv = 0, Vn = NULL, sigsq = 0.265, mu_beta_d = 0.25, mu_beta_a = 0, alt = "greater", alpha = 0. We emphasize a few important points in this rudimentary example.Assigning a vector of values for n indicates we are interested in assessing the assurance for multiple study designs. Each unique value passed into n corresponds to a separate balanced study design containing that particular sample size for each of the p groups undergoing assessment.In this example, setting p = 1, u = 1 and C = 0.15 implies we are evaluating the tenability of H : β > 0.15, where β is a scalar.Furthermore, Vbeta_d and Vbeta_a_inv are scalars to align with the dimension of β.A weak analysis prior (Vbeta_a_inv = 0) and a strong design prior (Vbeta_d = 0) are assigned to demonstrate the overlapping scenario taking place between the Bayesian and frequentist settings.Section 6 revisits this example when reviewing features that allow users to simultaneously visualize the Bayesian and frequentist settings in a single window.Finally, Xn and Vn are set to NULL which means they will take on the default settings specified in the parameter descriptions above.

Example 2: Linear Contrasts
In this example, we assume β is a vector of unknown components rather than a scalar.We refer to the cost-effectiveness application discussed in O' Hagan and Stevens (2001) to demonstrate a real-world setting.The application considers a randomized clinical trial that compares the cost-effectiveness of two treatments.The cost-effectiveness is evaluated using a net monetary benefit measure expressed as where µ 1 and µ 2 respectively denote the efficacy of treatments 1 and 2, and γ 1 and γ 2 denote the costs.Hence, µ 2 − µ 1 and γ 2 − γ 1 correspond to the true differences in treatment efficacy and costs, respectively, between Treatments 1 and 2. The threshold unit cost, K, represents the maximum price that a health care provider is willing to pay for a unit increase in efficacy.
In this setting,we seek the tenability of H : ξ > 0, which if true, indicates that Treatment 2 is more cost-effective than Treatment 1.To comply with the conjugate linear model framework outlined in Equation ( 4), we set u = (−K, 1, K, −1) , β = (µ 1 , γ 1 , µ 2 , γ 2 ) , and C = 0, giving us an equivalent form of ξ > 0 expressed as u β > 0. All other inputs of this application were directly pulled from the paper.The following code sets up the inputs to be passed into bayes_sim().

Assurance Computation in the Longitudinal Setting
We demonstrate an additional feature embedded in the function tailored to longitudinal data.In this setting, n no longer refers to the number of subjects but rather the number of repeated measures reported for each subject assuming a balanced study design.Referring back to the linear regression model discussed in the general framework, we can construct a longitudinal model that utilizes this same linear regression form, where Consider a group of subjects in a balanced longitudinal study with the same number of repeated measures at equally-spaced time points.In the base case, in which time is treated as a linear term, subjects can be characterized by where y ij denotes the j th observation of subject i at time t ij , α i and β i respectively denote the intercept and slope terms for subject i, and i is an error term characterized by i ∼ N (0, σ 2 i ).In a simple case with two subjects, we can individually express the observations as . . .
assuming that each subject contains n observations.The model can also be expressed cohesively using matrices, bringing us back to the linear model structure.If higher degrees are to be considered for the time variable, such as the inclusion of a quadratic term, the model would be altered to include additional covariate terms that can accommodate for these changes.In the two-subject case, incorporating a quadratic term for the time variable in Equation ( 7) will result in the model being modified as follows: In general, for m subjects who each have n repeated measures, a one-unit increase in the degree of the time-based covariate will result in m additional columns being added to the design matrix X n and m additional rows added to the β vector.
When working in the longitudinal setting, additional parameters need to be specified in the bayes_sim() function.These include 1. longitudinal: logical that indicates the simulation will be based in a longitudinal setting.If Xn = NULL, the function will construct a design matrix using inputs that correspond to a balanced longitudinal study design.
2. ids: vector of unique subject ids 3. from: start time of repeated measures for each subject 4. to: end time of repeated measures for each subject 5. num_repeated_measures: desired length of the repeated measures sequence.This should be a non-negative number, will be rounded up otherwise if fractional.
6. poly_degree: degree of polynomial in longitudinal model, set to 1 by default.
By default, longitudinal = FALSE and ids, from, and to are set to NULL when working within the standard conjugate linear model.When longitudinal = TRUE, n takes on a different meaning as its value(s) correspond to the number of repeated measures for each subject rather than the total number of subjects in each group.When longitudinal = TRUE and Xn = NULL, bayes_sim() implicitly relies on a design matrix generator, gen_Xn_longitudinal(), that is specific to the longitudinal setting to construct appropriate design matrices.Section 6 discusses this in greater detail.

Example 3: Longitudinal Example
The following example uses similar parameter settings as the cost-effectiveness example we had previously discussed in Section 3.1.2,now with longitudinal specifications.We assume two subjects and want to test whether the growth rate of subject 1 is different in comparison to subject 2. This could have either positive or negative implications depending on the measurement scale.Figure 3 displays the estimated assurance points given the specifications.
Assigning an appropriate linear contrast lets us evaluate the tenability of an outcome.Let us consider the tenability of u β = C in this next example, where u = (1, −1, 1, −1) and C = 0.The timepoints are arbitrarily chosen to be 0 through 120-this could be days, months, or years depending on the context of the problem.The number of repeated measurements per subject to be tested includes values 10 through 100 in increments of 5.This indicates that we are evaluating the assurance for 19 study designs in total.n = 10 divides the specified time interval into 10 evenly-spaced timepoints between 0 and 120.
For a more complicated study design comprised of more than two subjects that are divided into two treatment groups, consider testing if the mean growth rate is higher in the first treatment group than that of the second, e.g. if we have three subjects per treatment group, the linear contrast would be set as u = (0, 0, 0, 0, 0, 0, 1/3, 1/3, 1/3, −1/3, −1/3, −1/3) .

Assurance Computation with Unknown Variance
The bayes_sim_unknownvar() function operates similarly to bayes_sim() but is used when the variance, σ 2 , is unknown.In the unknown variance setting, priors are assigned to both β and σ 2 in the analysis stage such that β|σ 2 ∼ N (µ β ) and σ 2 ∼ IG(a (a) , b (a) ), where superscripts (a) indicate analysis priors.Determining the posterior distribution of σ 2 requires integrating out β from the joint posterior distribution of {β, σ 2 }, yielding Recall the design stage aims to identify a minimum sample size that is needed to attain the assurance level specified by the investigator.We will need the marginal distribution of y n with priors placed on both β and σ 2 .We denote these design priors as β (d) and σ 2(d) .With σ 2(d) now treated as an unknown parameter, the marginal distribution of y n , given σ 2(d) , under the design prior is derived from Equation ( 9) specifies our data generation model for ascertaining sample size.
To summarize, in the design stage, we draw σ 2(d) from IG(a σ ) and generate the data from our sampling distribution from Equation (9).For each data set,we perform Bayesian inference for β and σ 2 .Here, we draw J samples of β and σ 2 from their respective posterior distributions and compute the proportion of these J samples that satisfy u β j > C. If the proportion exceeds a certain threshold 1 − α, then the analysis objective is met for that dataset.The above steps for the design and analysis stage are repeated for R datasets and the proportion of the R datasets that meet the analysis objective corresponds to the Bayesian assurance.
The bayes_sim_unknownvar() function requires the same set of parameters as bayes_sim() in addition to the following: 1. R: number of datasets generated used to check if the analysis objective is met.The proportion of those R datasets meeting the analysis objective corresponds to the estimated assurance.
2. a_sig_d,b_sig_d: shape and scale parameters of the inverse gamma distribution where variance σ 2 is sampled from in the design stage.
3. a_sig_a,b_sig_a: shape and scale parameters of the inverse gamma distribution where variance σ 2 is sampled from in the analysis stage.

Example 4: Unknown Variance
Referring back to the cost-effectiveness application presented in Inoue, Berry, and Parmigiani (2005), we modify the inputs from bayes_sim() and perform the simulation assuming un-known variance σ 2 using bayes_sim_unknownvar().We implement the following code for a single sample size n = 285 with assigned correlation matrices mentioned in the paper.

Assurance Computation for Unbalanced Study Designs
The bayes_sim_unbalanced() function operates similarly to bayes_sim() in Section 3.1 but estimates the assurance of attaining u β > C specifically in an unbalanced design setting.Users provide two sets of sample sizes of equal length, whose corresponding pairs are considered for each study design case.The sample sizes need not be equal to one another, allowing for unbalanced designs.This is unlike bayes_sim() that strictly determines assurance for balanced cases, where users specify a single set of sample sizes whose individual entries correspond to a distinct trial comprised of an equal number of observations across all explanatory variables.The bayes_sim_unbalanced() function provides a higher degree of flexibility for designing unbalanced studies and offers a more advanced visualization feature.Users have the option of viewing assurance as a 3-D contour plot and assess how the assurance behaves across varying combinations of the two sets of sample sizes that run along the x and y axes.
The bayes_sim_unbalanced() function is similar to bayes_sim() in terms of parameter specifications with a few exceptions.Parameters unique to bayes_sim_unbalanced() are summarized below: 1. n1: first sample size (either vector or scalar).
3. repeats: an integer value denoting the number of times c(n1, n2) is accounted for; applicable for study designs that consider an even number of explanatory variables greater than two and whose sample sizes correspond to those specified in n1 and n2.By default, repeats = 1.See Example 6 below.
4. surface_plot: logical parameter that indicates whether a contour plot is to be constructed.When set to TRUE, and n1 and n2 are vectors, a contour plot (i.e.heat map) showcasing assurances obtained for unique combinations of n1 and n2 is produced.
As in bayes_sim, it is recommended that users set Xn = NULL to facilitate the automatic construction of appropriate design matrices that best aligns with the conjugate linear model described in beginning of Section 3. Recall that every unique sample size (or sample size pair) passed in corresponds to a separate study that requires a separate design matrix.Should users choose to provide their own design matrix, it is advised that they evaluate the assurance for one study design at a time, in which a single design matrix is passed into Xn along with scalar values assigned for the sample size parameter(s).
Saved outputs from executing the function include The following code provides a basic example of how bayes_sim_unbalanced() is executed.
It is important to check that the parameters passed in are appropriate in dimensions, e.g.mu_beta_a and mu_beta_d should each contain the same length as that of u, and the length of u should be equal to the row and column dimensions of Vbeta_d and Vbeta_a_inv.
A table of assurance values is printed simply by calling assur_out$assurance_table, which contains the exact assurance values corresponding to each sample size pair.The contour plot, shown in Figure 5, is displayed using assur_out$contourplot, and offers a visual depiction of how the assurance varies across unique combinations of n1 and n2.Areas with lighter shades denote higher assurance levels.No discernible patterns or trends are observed based on the random behavior of the plot and the proximity of values reported in the table as the inputs were arbitrarily chosen with no context.The next example implements the function in a real-world setting that offers more sensible results.

Example 6: Cost-effectiveness Application
We revisit the cost-effectiveness problem discussed in Example 2 of Section 3.1.In addition to providing a 3-D graphical display of the assurance, this example also serves to demonstrate a setting where the repeats parameter becomes relevant.
Recall from Example 2 that two distinct sets of efficacy and cost measures are used to compare the cost-effectiveness of treatments 1 and 2. The efficacy and costs are denoted by µ i and γ i for i = 1, 2 treatments.Hence, the parameter we want to estimate contains four elements tied to the unknown efficacy and costs of treatments 1 and 2, i.e. β = (µ 1 , γ 1 , µ 2 , γ 2 ) .It was previously assumed that the treatments contain an equal number of observations, suggesting that the sample sizes across each of the four explanatory variables are also equal.Using bayes_sim_unbalanced() offers the added flexibility of constructing an unbalanced study design between treatments 1 and 2. Since the two treatments each contain two components to be measured, we use the repeats parameter to indicate that we want two sets of sample sizes, c(n1, n2), passed in, i.e. c(n1, n2, n1, n2).It then becomes clear that our study design consists of n 1 observations for the efficacy and cost of treatment 1, and n 2 observations for those of treatment 2. Figure 5 displays a contour plot with a noticeable increasing trend of assurance values across larger sets of sample sizes.

Bayesian Assurance with Precision-Based Conditions
The bayes_adcock() function determines the assurance under conditions discussed in Adcock (1997).In the frequentist setting, if X i ∼ N (µ, σ 2 ) for i = 1, ..., n observations and variance σ 2 is known, the precision can be determined using d = z 1−α/2 σ √ n , where z 1−α/2 is the critical value for the 100(1 − α/2)% quartile of the standard normal distribution.In this setting, precision refers to the allotted margin of difference allotted between the true and estimated parameter values.Simple rearranging leads to the following expression for sample size, Given a random sample with mean x, suppose the goal is to estimate population mean µ.To construct this problem in the Bayesian setting, suppose x 1 , • • • , x n is a random sample from N (µ, σ 2 ) and the sample mean is distributed as x|µ, σ 2 ∼ N (µ, σ 2 /n).The analysis objective is to observe that the absolute difference between x and µ falls within a margin of error no greater than d.Given data x and a pre-specified confidence level α, the assurance can be formally expressed as We assign µ ∼ N (µ β , σ 2 /n a ) as the analysis stage prior, where n a quantifies the amount of prior information we have for µ.The posterior of µ is obtained by taking the product of the prior and likelihood, resulting in na+n .We can further evaluate the condition using parameters from the posterior of µ to obtain a more explicit version of the analysis stage objective.Starting from the condition expressed in Equation ( 11), where we can standardize all components of the inequality using the posterior distribution of µ, eventually leading to where Φ denotes the cumulative density function of the standard normal distribution.
We now assign a separate design stage prior on µ such that µ ∼ N (µ , where n d quantifies our degree of belief towards the population from which the sample will be drawn.Given that x|µ, σ 2 ∼ N (µ, σ 2 /n), the marginal distribution of x can be computed using straightforward substitution based on x = µ + ; ∼ N (0, σ 2 /n) and µ = µ β , σ 2 /p), denoting the distribution in which we will iteratively generate samples from to check if they satisfy the condition outlined in the analysis stage and the assurance is computed as The bayes_adcock() function takes in the following set of parameters: 1. n: sample size (either vector or scalar) 6. n_d: sample size at design stage; quantifies the amount of prior information we have for where the data is being generated from.
8. alpha: significance level 9. mc_iter: number of MC samples evaluated under the analysis objective.

Example 7: Precision-Based Condition
As a preliminary example, consider passing in the following set of arbitrary inputs into bayes_adcock(), with the outputs saved as out.Since we are assigning a vector of values to n, we should therefore expect a vector of assurance values being returned.The first six rows of the assurance table is shown below and the plotted assurance points are displayed in Figure 6.

Example 8: Overlap Between Classical and Bayesian Setting
To demonstrate how the frequentist setting is perceived as a special case of the Bayesian setting under the precision-based conditions discussed above, we refer to the sample size formula in Equation ( 10) and apply rudimentary rearrangements to obtain 2Φ √ n σ d − 1 ≥ 1 − α, which we denote as the frequentist condition.Comparing this to the assurance formula expressed in Equation ( 12), where we notice that both expressions have 1 − α isolated on the right hand side.Setting n a = 0 in the assurance formula leads to The resulting term on the left hand side is now equivalent to that of the frequentist condition, suggesting that if we let θ take on a weak analysis prior, i.e. n a = 0,our analysis objective simplifies to an expression that directly aligns with the frequentist formulation of sample size.
A visual portrayal of this special case is shown in Figure 7, which plots the left-hand-side expressions being compared to 1 − α in both settings.Note that these expressions do not correspond to the actual assurance values, but rather, the probability of meeting the specified analysis objective within a single iteration.The assurance takes the average of the indicatorbased outcomes across all iterations, as shown in Equation ( 12).Red curves correspond to values obtained from the frequentist expression, 2Φ √ n σ d − 1, while blue points denote results determined from the Bayesian expression, Φ , which uses samples generated from the marginal of x and assumes a weak analysis prior.This is considered for multiple precision levels, d.

Bayesian Assurance Using Credible Interval Based Conditions
The bayes_sim_betabin() function determines assurance in the context of estimating differences between two proportions.The analysis objective in the Bayesian setting relies on credible interval based conditions discussed in Pham-Gia (1997) that outlines steps for determining exact sample sizes needed in this particular setting.
Starting with the classical setting, let p i , i = 1, 2 denote two independent proportions pulled from distinct samples of size n.Suppose we want to execute the hypothesis test, H 0 : p 1 −p 2 = 0 vs. H a : p 1 − p 2 = 0.The outcome of interest involves involves detecting if a significant difference exists between the two proportions.One way to check is to see if 0 is contained within the confidence bands of the difference in proportions given by 0 where z 1−α/2 denotes the critical region, and SE( pi ) denotes the standard error of n .An interval without 0 included in the confidence interval suggests there exists a significant difference between the two proportions.
The Bayesian setting uses posterior credible intervals as an analog to the frequentist confidence interval approach.Two distinct priors are assigned to p 1 and p 2 such that p i ∼ Beta(α i , β i ) for i = 1, 2. Let X be a random variable taking on values x = 0, 1, ..., n denoting the number of favorable outcomes out of n trials.The proportion of favorable outcomes is therefore p = x/n.Suppose a Beta prior is assigned to p such that p ∼ Beta(α, β).The prior mean and variance are respectively µ prior = α α+β and σ 2 prior = αβ (α+β) 2 (α+β+1) .Conveniently, given that p is assigned a Beta prior, the posterior of p also takes on a Beta distribution with mean and variance In the analysis stage, we assign priors for p 1 and p 2 such that p i ∼ Beta(α i , β i ), i = 1, 2.
Letting p d = p 1 − p 2 and having p post and var(p) post respectively denote the posterior mean and variance of p d , it is straightforward to deduce from Equation ( 14) that ) .The resulting 100(1 − α)% credible interval therefore equates to p post ± z 1−α/2 var(p) post , which, similar to the frequentist setting, is used to check if 0 is contained within the credible interval bands as part of our inference procedure.Our analysis objective becomes where x 1 and x 2 are the counts observed in the two samples generated in the design stage.
In the design stage, counts x 1 and x 2 are observed from samples of size n 1 and n 2 based on given probabilities, p 1 and p 2 , provided in the analysis stage.Once p 1 and p 2 are assigned, x 1 and x 2 are randomly generated from their corresponding binomial distributions, where The posterior credible intervals are subsequently computed to undergo assessment in the analysis stage.These steps are repeated iteratively starting from the generated values of x 1 and x 2 .The proportion of samples that meet the criterion in Equation ( 15) equates to the assurance.It follows that the corresponding assurance for assessing a significant difference in proportions is given by The bayes_sim_betabin() function takes the following set of inputs: 1. n1: sample size of first group (scalar) 2. n2: sample size of second group (scalar) 3. p1: proportion of successes in first group; set to NULL by default 4. p2: proportion of successes in second group; set to NULL by default 5. alpha_1, beta_1: shape parameters for the distribution of p1 such that p1 ∼ Beta(α 1 , β 1 ); used when p1 is not provided or known 6. alpha_2, beta_2: shape parameters for the distribution of p2 such that p2 ∼ Beta(α 1 2β 2 ); used when p2 is not provided or known 7. sig_level: significance level 8. alt: a character string specifying the alternative hypothesis when comparing p1 and p2.The options are "two.sided"(default), "greater" and "less".
9. mc_iter: number of MC samples evaluated under the analysis objective; set to 5000 by default.Example 9: Simple Case In the following example, let n1 = n2 for simplicity and choose arbitrary values for the remaining parameters.Results are saved as out, containing corresponding plots and tables.The first six rows of the assurance table is shown below and Figure 8 plots estimated assurances for varying sample sizes.
Recall the sample size formula for assessing differences in proportions in the frequentist setting, where n = n 1 = n 2 .Simple rearrangements and also noting that Similar to Bayesian assurance, power is interpreted as the probability of correctly detecting a specified difference between the two proportions, p 1 and p 2 , in correspondence to sample size n.We translate this relationship in to a simple function that takes a set of fixed parameters and returns the power based on Equation ( 16): R> propdiffCI_classic <-function(n, p1, p2, sig_level){ p <-p1 -p2 power <-pnorm(sqrt(n / ((p1*(1-p1)+p2*(1-p2)) / (p)^2))qnorm(1-sig_level/2)) return(power) } The next code segment determines power and assurance for a fixed set of inputs across a vector of sample sizes.
Example 11: Special Case 2 The next example demonstrates overlapping behaviors of the frequentist and Bayesian settings when p 1 and p 2 are unknown.In an ideal situation, we could determine suitable parameters for α i , β i , i = 1, 2 to use as our Beta priors that would enable demonstration of convergence towards the frequentist setting.However, a key relationship to recognize is that the Beta distribution is a conjugate prior of the Binomial distribution.There is a subtle advantage offered given that the Bayesian credible interval bands are based upon posterior parameters of the Beta distribution (refer to Equation ( 15)) and the frequentist confidence interval bounds are based upon the Binomial distribution (refer to Equation ( 13)).Because of the conjugate relationship held by the Beta and Binomial distributions, we are assigning priors to parameters in the Bayesian setting that the Binomial density in the frequentist setting is conditioned upon.Since the normal distribution can be used to approximate binomial distributions for large sample sizes given that the Beta distribution is approximately normal when its parameters α and β are set to be equal and large, we manually choose such values to illustrate these parallels.First, we modify the frequentist power function from before to now include shape parameters: The following code sets parameters p 1 and p 2 to NULL and assigns equal sets of arbitrarily selected shape parameters to pass in to the assurance function, where α 1 = β 1 = 2 and α 2 = β 2 = 6.
other.The results are gathered into separate tables reporting sample sizes and corresponding power and assurance values for all the different cases.These tables are used to construct Figure 10, which simultaneously plots estimated assurance values, denoted by red points,laying along the respective power curves, marked in blue.
Notice that the power and assurance values approximately overlap each other in each of the four cases, which is particularly true for the case when Haldane priors are used.This again relies on the notion that the normal distribution can be used to approximate binomial distributions for large sample sizes given that the Beta distribution is approximately normal when its parameters α and β are set to be equal.

Bayesian Goal Function
Similar to the Bayesian assurance, goal functions seek to determine the minimum sample size needed to meet certain objectives.Discussed in Inoue et al. (2005), the goal function aggregates well-defined conditions that are dependent on sample size and other user-specified inputs relevant to the study.It is framed under a utility approach that enables the decision maker to choose an option that maximizes the expected value of the function.The goal function specifies an overarching condition that the study aims to observe, and in turn, assists users in making well-informed decisions regarding their analysis.Specification of goal functions comes in a variety of forms, including but not limited to, statistical power, information, confidence interval widths and rate of classification error (Inoue et al. 2005).The goal functions defined in our package are characterized by the use of the rate of correct classification, which we denote as r * .
Optimizing the value of r * occurs from either correctly rejecting the null hypothesis or correctly accepting the null hypothesis.Table 2 specifies the utility associated with all possible events.Specifically, a utility of K is associated with correctly failing to reject H 0 , a loss of 1 is associated with correctly rejecting H 0 , and incorrect decisions do not experience any benefit.A general expression of the goal function is given as where v denotes a vector of user-specified inputs in addition to sample size n.The value of G B (n, v) obtained once the inputs are processed is the overall r * value.
Consider the linear hypothesis test H 0 : u β = c 0 vs. H a : u β = c 1 under the general linear model y = Xβ + , where implying that c 0 and c 1 are scalars.Let us assume that u β is estimable.Then, by the fundamental principle of estimable functions, there exists a linear unbiased estimate b y such that E(b y) = u β.This suggests that u belongs in the column space of X since Hence, u can be expressed as u = X z for some z ∈ R n .Letting ỹ = z y, simple linear transformation leads to ỹ|H 0 ∼ N (c 0 , σ 2 z z) and ỹ|H a ∼ N (c 1 , σ 2 z z).Under this framework, we treat Equation ( 17) as a template and define specific thresholds that enable the function to objectively determine the rate of correct classification in the Bayesian setting.We assign a prior on u β such that P (H 0 ) = 1−P (H a ) = π and assume that the null hypothesis is not rejected if the posterior probability of H 0 is at least 1/(1 + K), where K is the amount of utility associated with H 0 being correctly accepted.Starting from the expression P (H 0 |ỹ) ≥ 1 1+K , we apply fundamental Bayesian principles on the left hand side of the inequality to obtain Substituting appropriate densities and assigned values results in Fundamental algebra leads to the following criteria, in which where δ = c 1 − c 0 .This condition can be expressed in a more cohesive way through standardization.Given that ỹ ∼ N (u β, σ 2 z z), it follows that Hence, the probability of correctly accepting H 0 is given by where Φ denotes the cumulative distribution function of the standard normal.Similar steps can be carried out to obtain the probability of correctly rejecting H 0 , resulting in a very similar expression: We now have all necessary components to obtain a full expression of the goal function based on the pre-specified cutoff, P (H 0 |y) ≥ 1 1+K .Referring to Equation ( 17), we can substitute all fixed assignments and cutoff criteria to obtain For further investigation, we repeat the same steps for two additional critical differences, displayed in Figure 12.The three intersections shown in the plot all correspond to the same r * threshold value, indicated by the horizontal dashed line.We deduce that detecting smaller
When analyzing this cost-effectiveness application in previous examples, our primary focus involved determining the assurance of attaining ξ = u β > 0, which would indicate that Treatment 2 is more cost-effective than Treatment 1.The objective of the goal function, in contrast, estimates the probability of correctly identifying the true outcome of a study.In this case, the underlying aim of our goal function is characterized by correctly identifying which treatment is more cost-effective than the other.We implement slight modifications to the original assurance framework above that lets us assess this from a goal function perspective.We separate the net monetary benefit formula into two components, ξ 1 and ξ 2 : It becomes clear how this modified framework of the cost-effectiveness problem aligns with our goal function setting delineated above.Our hypothesis test now takes on the linear form H 0 : u β = ξ 1 vs. H a : u β = ξ 2 .The user needs to pass in 2 × 1 vectors for u, beta_0, and beta_1 to run this assessment.The following code segment demonstrates how this setting is implemented in R. We use the same parameter specifications from the example showcased in Section 3.1.2.

Relationship to Frequentist Setting
We can also construct an analogous goal function using a classical-based approach by modifying the cutoff condition to one that adheres to measures pertaining to the frequentist setting.We continue working in a hypothesis testing framework within a general linear model setting outlined in Section 5, given as H 0 : u β = u β 0 vs. H a : u β = u β 1 .As previously discussed, the Bayesian method formulates its goal function using the posterior probabilities of H 0 and H a to determine appropriate sample sizes n B .In the frequentist setting, we rely on power to characterize the goal function.To achieve a power of 1 − β, the frequentist determines sample size n F using where α and β are respectively Type I and Type II error rates and δ = u β 1 − u β 0 , denoting the critical difference.between the two values when power is small.The gap becomes visually smaller as the power increases and the two lines coincide when both the frequentist power and rate of correct classification reach a value of 0.95, which corresponds to a sample size of 1083.This point is marked and labeled in the plot along with another point we had previously referenced in Example 12.

Overlapping Power and Assurance Plots
To facilitate the understanding of the relationship held between Bayesian and frequentist settings, the pwr_curves() function produces a single plot with the power curve and assurance points overlayed on top of one another.Recall the primary difference held between pwr_freq() and assurance_nd_na() is the need to specify additional precision parameters, n a and n d , in assurance_nd_na().Knowing that power and sample size analysis in the frequentist setting is essentially a special case to the Bayesian assurance with precision parameters tailored to weak analysis priors and strong design priors, the pwr_curves() function serves as a visualization tool in seeing how varying precision levels' affect assurance values and how these assurance values compare to those of strictly weak analysis and strong design priors, i.e. power values.
The pwr_curves() function takes the combined set of parameters presented in pwr_freq() and assurance_nd_na(), which includes n, n_a, n_d, theta_0, theta_1, sigsq, and alpha.For further customization, users have the option to include a third set of points in their plot along with the power and assurance curves.These additional points would correspond to the simulated assurance results obtained using bayes_sim().Optional parameters to implement this include 1. bayes_sim: logical that indicates whether the user wishes to include simulated assurance results obtained from bayes_sim().Default setting is FALSE.
2. mc_iter: specifies the number of MC samples to evaluate given bayes_sim = TRUE.
The following code segment runs the pwr_curves() function using a weak analysis stage prior (n_a is set to be small) and a strong design stage prior (n_d is set to be large).Implementing this produces a plot where the assurance points lay perfectly on top of the power curve as shown in Figure 14.The simulated assurance points obtained from bayes_sim() are also plotted as we set bayes_sim = TRUE.These points are highlighted in blue, which lie very close in proximity to those of the exact assurance points highlighted in red.We can also view individual tables of the three sets of points by directly calling them from the saved outputs, e.g.out$power_table shows the individual frequentist power values for each sample size.The output we provide shows the first ten rows.

R> library(bayesassurance)
R> out <-pwr_curve(n = seq(10, 200, 10), n_a = 1e-8, n_d = 1e+8, sigsq = 0.104, theta_0 = 0.15,theta_1 = 0.25, alt = "greater", alpha = 0.05, bayes_sim = TRUE, mc_iter = 5000) R> head(out$power_table) R> head(out$assurance_table) R> out$plot  The next code segment considers the scenario in which both analysis and design stage priors are weak (n_a and n_d are set to be small).This special case shows how the assurance behaves when vague priors are assigned.Substituting 0 in for both n a and n d in Equation ( 1) results in a constant assurance of Φ(0) = 0.5 regardless of the sample size and critical difference.Figure 15 illustrates these results, where we have the regular power curve and the flat set of assurance points at 0.5 for both exact and simulated cases.Note that some of these points appear purple due to the overlaps that occur between the exact and simulated assurance values.

Design Matrix Generators
The next sections go over design matrix generators that run in the background of selected functions within the bayesassurance package when the Xn parameter is set to NULL.We include these functions in case users wish to see how design matrices are constructed under this particular setting.

Standard Design Matrix Generator
The standard design matrix generator, gen_Xn(), is relevant to a majority of the simulationbased assurance functions discussed throughout the paper.It is first mentioned in Section 3 that the assurance function under known variance,bayes_sim(), does not require users to specify their own design matrix X n .Users have the option of setting Xn = NULL, which prompts the function to construct a default design matrix using gen_Xn() that complies with the general linear model y n = X n β + , ∼ N (0, σ 2 V n ).The function is automatically administered in the background while bayes_sim() is actively in use.
When directly executed in an R script or console, the gen_Xn() function takes in a single parameter, n, which can either be a scalar or vector.The length of n corresponds to the number of groups being assessed in the study design as well as the column dimension of the design matrix, denoted as p.Therefore, in general, the resulting design matrix is of dimension n × p.If a scalar value is specified for n, the resulting design matrix carries a dimension of n × 1.
In the following example, we pass in a vector of length p = 4, which outputs a design matrix of column dimension 4. Each column is comprised of ones vectors with lengths that align with the sample sizes passed in for n.The row dimension is therefore the sum of all the entries in n.In this case, since the values 1, 3, 5, and 8 are being passed in to n, the design matrix to be constructed carries a row dimension of 1 + 3 + 5 + 8 = 17 and a column dimension of 4. The bayes_sim() function and its related family of functions generate design matrices using gen_Xn() in a very particular way.Each unique value contained in n that is passed into bayes_sim() corresponds to a distinct study design and thus requires a distinct design matrix.The gen_Xn() function interprets each i th component of n as a separate balanced study design comprised of n i participants within each of the p groups, where p is a parameter specified in bayes_sim().For example, if we let Xn = NULL and pass in n <-2, p <-4 for bayes_sim(), gen_Xn() will process the vector n <-c(2, 2, 2, 2) in the background.Hence, we'd obtain an 8 × 4 matrix of the form 1 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 1 .

Design Matrix Generator in Longitudinal Setting
Section 3.2 describes how the linear model is extended to incorporate time-based covariates within the context of a longitudinal setting.For this special case, a separate function is used to generate design matrices that are appropriate for this setting.The genXn_longitudinal() constructs its design matrices differently than gen_Xn() and therefore requires a different set of parameter specifications.When the longitudinal parameter is set to TRUE in bayes_sim(), the user is required to specify the following set of parameters, which are directly passed into genXn_longitudinal(): 1. ids: vector of unique subject ids, usually of length 2 for study design purposes 2. from: start time of repeated measures for each subject 3. to: end time of repeated measures for each subject 4. num_repeated_measures: desired length of the repeated measures sequence.Should be a non-negative number, will be rounded up if fractional.
5. poly_degree: degree of polynomial in longitudinal model, set to 1 by default.
Referring back to the model that was constructed for the case involving two subjects, we observe in Equation ( 7) that the design matrix contains vectors of ones within the first half of its column dimension and lists the timepoints for each subject in the second half.Constructing this design matrix requires several components.The user needs to specify subject IDs that are capable of uniquely identifying each individual in the study.Next, the user needs to specify the start and end time as well as the number of repeated measures reported for each subject.
The number of repeated measures denotes the number of evenly-spaced timepoints that take place in between the start and end time.Since we are assuming a balanced longitudinal study design, each subject considers the same set of timepoints.Finally, if the user wishes to consider time covariates of higher degrees, such as a quadratic or cubic function, this can be altered using the poly_degree parameter, which takes on a default assignment of 1.
In the following code, we pass in a vector of subject IDs and specify the start and end timepoints along with the desired length of the sequence.The resulting design matrix contains vectors of ones with lengths that correspond to the number of repeated measures for each unique subject.
R> ids <-c(1,2,3,4) R> gen_Xn_longitudinal(ids, from = 1, to = 10, num_repeated_measures = 4) The next code block modifies the previous example to incorporate a quadratic term.Notice there are four additional columns being aggregated to the design matrix.These four columns are obtained from squaring the four columns that precede this set of columns.

Discussion
This article introduced bayesassurance, a new R package that determines the Bayesian assurance for various conditions using a two-stage framework.The goal of this package is to provide a convenient and user-friendly implementation accessible to a wide range of data analysts, and showcase the generalized aspect of the Bayesian assurance in relation to classical approaches to power and sample size analysis.We hope we have provided organized, well-documented open-source code that can be used to address a wide selection of clinical trial study designs and demonstrate the feasibility of applying Bayesian methods to such problems.

Figure 1 :
Figure 1: Resulting assurance plot with specific points passed in marked in red.

Figure 2 :
Figure 2: Resulting power and assurance curve when weak analysis priors and strong design priors and enforced.

Figure 3 :
Figure 3: Estimated assurance points for longitudinal example.

Figure 4 :
Figure 4: Contour map of assurance values with varying sample sizes n1 and n2.

Figure 5 :
Figure 5: Contour map of assurance values in cost-effectiveness application.

Figure 7 :
Figure 7: Left-hand-side expressions of frequentist and Bayesian cases under precision-based conditions for varying precision levels, d.

Figure 8 :
Figure 8: Simulated assurance points corresponding to Example 9 using credible interval based conditions.

Figure 9 :
Figure 9: Power curves and simulated assurance points corresponding to the case when p 1 and p 2 are known.

Figure 10 :
Figure 10: Power curves and simulated assurance points corresponding to the case when p 1 and p 2 are unknown. p1

Figure 11 :
Figure 11: Rate of classification curve.Red dashed lines indicate a sample size of n=857 is needed to ensure r * = 0.9283.

Figure 12 :
Figure 12: Goal function curves resulting from the same set of fixed parameters and different critical differences, δ.

Figure 13 :
Figure 13: Solid curve shows power and r * values that yield equal sample sizes in the Bayesian and frequentist settings assuming the critical difference is δ = 0.1.

Figure 14 :
Figure 14: Power curve with exact and simulated assurance points for weak analysis prior and strong design prior.

Figure 15 :
Figure 15: Power curve with exact and simulated assurance points for weak analysis and design priors.

Table 1 :
The assurance_nd_na() function Overview of the functions available for use within the package.
As a simple example, consider the following code chunk that directly runs pwr_freq() through specifying the above parameters and loading in bayesassurance: 5. sigsq: known variance 6. alpha: significance level of test 1. assurance_table: table of sample size and corresponding assurance values 2. contourplot: contour map of assurance values if surface.plot= TRUE 3. mc_samples: number of Monte Carlo samples that were generated for evaluation