Abstract
Micro-randomized Trials (MRTs) are a novel experimental design for developing mobile health interventions. Participants are repeatedly randomized in an MRT, resulting in longitudinal data with time-varying treatments. Causal excursion effects are the main quantities of interest in MRT primary and secondary analyses. We consider MRTs where the proximal outcome is binary and the randomization probability is constant or time-varying but not data-dependent. We develop a sample size formula for detecting a nonzero marginal excursion effect. We prove that the formula guarantees power under a set of working assumptions. We demonstrate via simulation that violations of certain working assumptions do not affect the power, and for those that do, we point out the direction in which the power changes. We then propose practical guidelines for using the sample size formula. As an illustration, the formula is used to size an MRT on interventions for excessive drinking. The sample size calculator is implemented in R package MRTSampleSizeBinary and an interactive R Shiny app. This work can be used in trial planning for a wide range of MRTs with binary proximal outcomes.
Keywords: Causal excursion effect, Causal inference, Longitudinal data analysis, Mobile health, Sample size calculation
1. Introduction
Mobile health interventions target healthy behavior change and are delivered through mobile devices such as smartphones and wearable trackers. They are usually delivered in the form of push notifications, text messages, or audible pings. They have the potential to be delivered to each individual at the time and in the context they are most likely to benefit. To realize this potential, it is important to gather empirical evidence to inform when and under what context the interventions are the most beneficial in order to improve and optimize them.
The micro-randomized trial (MRT) is an optimization trial design that provides data to answer such questions1–4. In an MRT, each participant is repeatedly randomized among multiple options of an intervention, usually hundreds or thousands of times throughout the trial. Each of such times is referred to as a decision point. After each decision point, a near-term, proximal outcome is measured, which is typically an outcome that the intervention is directly targeting. Data from MRTs allow researchers to investigate whether the intervention is effective on average and whether/how the intervention effect is moderated by contextual information5,6. This can lead to further optimization of the intervention through techniques such as reinforcement learning7.
We consider MRTs where the proximal outcome following each decision point is binary. This is common because a natural proximal outcome for many mobile health interventions measures whether the participant adheres to the notification or message. For example, in the Substance Abuse Research Assistant (SARA) MRT for developing non-monetary incentives to improve self-report completion rate8, one intervention is an inspirational quote whose delivery is micro-randomized every day at 4pm, and the proximal outcome is whether the participant completes the self-report that evening. In the BariFit MRT for developing smartphone-based support for weight maintenance post-bariatric surgery9, one intervention is a message reminder for completing the daily food log, and the proximal outcome is whether the participant completes the food log on that day.
An MRT is typically sized to ensure adequate power for detecting a clinically meaningful average effect of the intervention (i.e., a marginal causal effect). Due to the lack of readily-available methodology and software to determine the sample size for MRTs with binary proximal outcomes, researchers currently rely on simulation-based sample size calculation or the sample size formula for MRTs with continuous outcomes1. The former can be time-consuming and the latter is inappropriate for binary outcomes.
We develop a sample size formula for MRTs with binary proximal outcomes where the randomization probability is constant or time-varying but not data-dependent. We prove that under a set of working assumptions, the sample size formula guarantees desired power to detect a pre-specified marginal causal effect with type I error control. We demonstrate via simulation that violations of certain working assumptions do not affect the power, and for those that do, we point out the direction in which the power changes. We provide practical guidelines for using the sample size formula. A sample size calculator is implemented in R package MRTSampleSizeBinary10 and an interactive web app (https://tqian.shinyapps.io/mrt_ss_binary/). This work can be used in trial planning for a wide range of MRTs with binary proximal outcomes.
The rest of the paper is organized as follows. In Section 2 we present notation and review the marginal excursion effect, a key quantity in MRT primary analysis. In Section 3 we list the working assumptions and derive the sample size formula. In Section 4 we provide a summary of the simulation findings and a list of practical guidelines for using the sample size formula. In Section 5 we illustrate the use of the sample size formula by applying it to sizing a real trial. Section 6 presents details of the simulation study. Section 7 concludes with a discussion.
2. Preliminaries
2.1. Notation
We focus on settings where (i) each participant is in the MRT for the same number of decision points, (ii) the treatment option at each decision point is binary (e.g., delivering or not delivering a message), (iii) the timing of decision points are pre-determined (e.g., at fixed calendar times determined before the study), and (iv) the randomization probability at each decision point is constant, or dependent on the decision point index solely and not dependent on other time-varying information such as the outcomes at previous decision points.
Let denote the number of participants in an MRT and the total number of decision points for each participant. For the i-th participant, denote by their randomized treatment assignment at decision point . For example, if a treatment is delivered to participant at decision point , and 0 if not. Let denote the randomization probability at . Let denote the binary proximal outcome measured following decision point . Without loss of generality, suppose is the desired outcome. For example, if participant adheres to the push notification at decision point , and 0 if not.
In an MRT, there may be decision points when it is inappropriate or unethical to deliver a treatment. For example, for safety reasons a mobile health app is usually designed so that a treatment is never delivered when the participant is detected to be driving. At such decision points, a participant is considered “unavailable” or “ineligible for randomization,” randomization does not occur, and the only possible treatment option is “no treatment.” Let denote the availability indicator: if participant is available at decision point , and if not. is always 0 if . Taking availability into account, the randomization probability is defined as .
MRT data usually also include participants’ baseline and time-varying covariates. Appropriately adjusting for them can increase estimation precision in the primary and secondary analyses4. We do not consider covariates in the sample size calculation to avoid the need to specify the covariate-outcome relationship during trial planning; this often makes the sample size formula conservative. We consider the following longitudinal observations for participant . We assume that are independent and identically distributed (i.i.d.) draws from an unknown distribution . We use letters without subscript to denote variables from a generic participant. We use to denote the -dimensional Euclidean space.
2.2. Marginal Excursion Effect
The marginal excursion effect (MEE)6 is the main quantity of interest in MRT primary analysis and one of the parameters in the sample size formula. We use potential outcomes notation11,12 to define the effect. Let denote the vector of treatment assignments up to and a realization of . Let denote the potential proximal outcome that would have been observed if the participant were assigned , a treatment sequence up to and including decision point . Similarly, denotes the potential availability at time under treatment sequence . MEE for binary proximal outcomes is defined as6
| (1) |
An value greater than 0 indicates that the treatment is effective at decision point . The two probabilities in (1) are conditional on the decision point being available , because scientifically the treatment effect is of interest only at available decision points, and statistically the treatment effect at unavailable decision points cannot be identified without further assumptions.
Each treatment is randomly assigned according to the randomization probability . We refer to this assignment mechanism as the treatment protocol. is called an excursion effect because it is a contrast between what would happen to the proximal outcome under two excursions from the treatment protocol: following the treatment protocol until then always assigning treatment at (the corresponding potential outcome being ), and following the treatment protocol until then always assigning no treatment at (the corresponding potential outcome being ).
is a marginal effect because it is not conditional on any history information (such as past treatment assignments and covariate values). It is possible that treatments assigned at earlier decision points, such as and , have an impact on the current proximal outcome, . Such delayed effects may be attributed to habit formation (a positive delayed effect) or user-burden/habituation (a negative delayed effect). It is also likely that the effect of the treatment would vary according to certain baseline or time-varying covariate values (i.e., the existence of effect modification). We are not ruling out such possibilities by focusing on . Rather, as a marginal quantity averages over any such delayed effects or effect modification. The focus on marginal quantities in the primary analysis is consistent with other optimization trials such as the factorial design13. Delayed effects and effect modification may be further explored in secondary and exploratory analyses.
Because the randomization probability may only depend on the decision point index but not other history information, can be expressed in terms of observed data distribution under standard causal assumptions (consistency, positivity, ignorability):
| (2) |
The exact formulation of the causal assumptions and the justification of this result is in Section 3 of Qian et al.6.
3. Methods
3.1. A Test Statistic That Guarantees Type I Error Control
We develop the sample size formula based on a test statistic for testing the null hypothesis
against the alternative hypothesis
An omnibus test that aims to detect every possible under will have low power to detect nonzero in specific trends in 14. Instead, we propose a test statistic that will have high power against some target alternative with a small number of degrees of freedom. The rationale is to trade off bias and variance in order to achieve high power to detect alternatives close to the target alternative. Here variance is roughly characterized by the degrees of freedom in a -statistic, and bias is how different the true function is from the target alternative.
We consider the setting where in the target alternative is a linear function of a vector parameter :
Here is a pre-specified -dimensional vector-valued function of and . The choice of the target alternative is usually determined in conversation with the scientific team. For example, if the scientific team does not expect the effect of the intervention to vary greatly over time, a constant-in-time with would be a good choice for the target alternative. If, however, the scientific team conjectures that the effect of the intervention might be close to zero and gradually increase with time early in the study and possibly decrease later in the study, a quadratic target alternative with might be a good choice.
We construct the test statistic as follows. Let be a working model for , where is a -dimensional feature vector and . We require that is a subset of 1. Let denote the solution to the following estimating equation:
| (3) |
Equation (3) is a modified version of equation (10) in Qian et al.6, in that we replaced their by ; this modification is to enable the derivation of an analytic sample size formula in Section 3.2. Suppose the data generating distribution satisfies for some . We show in Section A of the Supplementary Materials that with large approximately follows a normal distribution:
| (4) |
where
| (5) |
We consider the Wald-type test statistic
| (6) |
Setting in (4) implies that under the large sample distribution of is , a chi-squared distribution with degrees of freedom. Thus, a hypothesis test that uses the critical value of the chi-squared distribution will have nominal type I error control asymptotically. To correct the downward bias of the sandwich estimator when the sample size is small, we use the critical value from a scaled -distribution because approximately follows , an -distribution with degrees of freedom 1,15. In particular, the rejection region of a test with significance level is
| (7) |
where is the quantile function of . We further incorporated the small sample correction in Mancl and DeRouen16 by replacing in (6) with an adjusted version using the “hat” matrix, which improves type I error control for small sample sizes.
3.2. A Sample Size Formula That Guarantees Power Under Working Assumptions
Equation (4) implies that when the data generating distribution satisfies the target alternative for all , the test statistic approximately follows ), a non-central chi-squared distribution with degrees of freedom and non-centrality parameter , where and are the probability limits of and as , respectively. To improve small sample performance, we use the -distribution approximation instead. In particular, the scaled test statistic approximately follows , a non-central -distribution with degrees of freedom and non-centrality parameter 1,15. In order to have at least power to detect the target alternative, the sample size must satisfy
Therefore, the required sample size is the smallest integer such that
| (8) |
The sample size formula (8) relies on , which depends on the data generating distribution that is typically unknown during trial planning. To make it feasible to compute from (8), we make the following working assumptions about .
(WA-a) (Known MEE.) Suppose for , where both and are known.
(WA-b) (Known success probability under no treatment.) Suppose for , where both and are known.
(WA-c) (Known availability probability.) Suppose for , where is known.
(WA-d) (No serial correlation in the outcome.) Suppose that, for every pair with does not depend on .
(WA-e) (Exogenous availability process.) Suppose is independent of prior treatments or prior outcomes; i.e., for .
Under the working assumptions, the sample size formula is summarized in the following theorem, and all the inputs to the formula are listed in Table 1.
Table 1:
Input to the sample size formula.
| Input | Interpretation |
|---|---|
|
| |
| desired power | |
| desired type I error | |
| total number of decision points per participant | |
| randomization probability at a decision point | |
| probability of a participant being availability at a decision point | |
| marginal excursion effect for the target alternative: | |
| success probability null curve: | |
Theorem 1.
(Sample size formula under working assumptions.) Suppose the data generating distribution satisfies (WA-a)-(WA-e), and . Suppose is a subset of . Then the probability limits of and as are
| (9) |
Furthermore, let , and let be the smallest integer that satisfies the sample size formula (8). Then for i.i.d. samples from , the testing procedure (7) has at least power.
We prove Theorem 1 under a set of weaker but less interpretable working assumptions in Section B of the Supplementary Materials.
(WA-a)-(WA-c) assume the knowledge of certain parameter values about , and (WA-d)-(WA-e) assume specific independence properties about . In particular, (WA-a) specifies , , for the target alternative. We treat it as a working assumption to assess the performance of the sample size formula when it is violated, i.e., when the true under is different than the target alternative.
(WA-b) states that the researcher knows , the success probability of the binary outcome under no treatment at , and how it changes over time. We use “success probability null curve” to refer to
| (10) |
One caveat is that averages over the past treatments and past outcomes , and thus depends on the magnitude of potential delayed effect and serial correlation.
(WA-c) states that for each decision point, the researcher knows the probability of a participant being available. Note that if (WA-e) is violated, would incorporate how depends on previous and .
(WA-d) states that the outcome does not depend on previous outcomes given previous treatments. This assumption is made to facilitate an analytic sample size formula. This assumption is implausible in most mobile health applications because for the same participant, outcomes measured closer in time are likely correlated. In the simulation studies we will see that the sample size formula still performs well when (WA-d) is violated.
(WA-e) states that the availability indicator, , does not depend on prior treatments and prior outcomes. This assumption may or may not be plausible depending on the particular study. For example, (WA-e) is plausible if a decision point is unavailable due to a technical glitch unrelated to the participant’s behavior or treatment. (WA-e) will be violated if availability reflects burden considerations in that a decision point is unavailable when treatment is delivered at a recent decision point. Note that (WA-e) holds for MRTs with no availability considerations because will always be 1.
4. Performance of the Sample Size Formula under Working Assumption Violations and Practical Guidelines
We conducted extensive simulation studies to evaluate the performance of the sample size formula when all working assumptions hold and when certain working assumptions are violated. Here we summarize the performance of the formula and provide practical guidelines. Detailed simulation results are in Section 6.
We start with definitions necessary for summarizing the simulation findings. Define the average treatment effect () as
| (11) |
the average success probability under the null () as
| (12) |
and the average availability () as
| (13) |
ATE is the multiplicative causal excursion effect averaged over time and weighted by availability (Remark 5 of Qian et al.6). ASPN is averaged over time and weighted by availability. AA is averaged over time. ATE, ASPN, and AA summarize the magnitude of , , and , respectively. In addition, we will use “pattern” to refer to how , , and vary over time independently of their magnitude. As we will see, the magnitude and the pattern of , , and impact the performance of the sample size formula in different ways.
We distinguish two versions of each of the quantities: one corresponding to the true data generating distribution (denoted by superscript ∗) and the other corresponding to the input to the sample size formula (denoted by superscript “w”, meaning “working”). For example, is (11) with the expectations calculated according to the true data generating distribution (which is unknown unless in simulations), and is (11) with the expectations calculated using the input to the sample size formula assuming all working assumptions hold. Using this notation, (WA-a) is equivalent to , (WA-b) is equivalent to , and (WA-c) is equivalent to .
The simulation findings are as follows. Regardless of whether the working assumptions hold, the type I error rate is always controlled at the desired 0.05 level. So we will focus on power next. When all the working assumptions hold, the MRT is adequately powered. When certain working assumptions are violated, the performance of the sample size formula depends on the discrepancy between the ∗-quantities and the w-quantities (Table 2). In general, correctly specifying the magnitudes of , , and is critical for adequate power. The performance is robust to the patterns of , , and in that as long as one uses constant and the power will be adequate. When there is a delayed effect or when the outcome is serially correlated, the MRT is adequately powered if accounts for the delayed effect / serial correlation so that ; otherwise, the power will depend on the sign of the delayed effect / serial correlation. When availability depends on past treatments and outcomes, the MRT can be slightly under-powered for some generative models.
Table 2:
Performance of the sample size formula when working assumptions are violated.
| WA violated | Details about the setting | Power | Setting | |
|---|---|---|---|---|
| (WA-a) | MEE(t) magnitude incorrect | ATEw > ATE* | ↓ | 1 |
| ATEw < ATE* | ↑ | 2 | ||
| MEE(t) pattern incorrect | MEEw (t) constant | → | 3 | |
| MEEw (t) non-constant | ↓* | 4 | ||
| (WA-b) | SPNC(t) magnitude incorrect | ASPNw > ASPN* | ↓ | 5 |
| ASPNw < ASPN* | ↑ | 6 | ||
| SPNC(t) pattern incorrect | SPNCw (t) constant | → | 7 | |
| SPNCw (t) non-constant | ↓* | 8 | ||
| delayed effect but is accounted for (ASPNw = ASPN*) | → | 9 | ||
| delayed effect not accounted for (ASPNw ≠ ASPN*) | positive delayed effect | ↑ | 10 | |
| negative delayed effect | ↓ | 11 | ||
| (WA-c) | τ(t) magnitude incorrect | AAw > AA* | ↓ | 12 |
| AAw < AA* | ↑ | 13 | ||
| τ(t) pattern incorrect | τw(t) constant | → | 14 | |
| τw(t) non-constant | → | 15 | ||
| (WA-d) & (WA-b) | serial corr. but is accounted for (ASPNw = ASPN*) | → | 16 | |
| serial corr. not accounted for (ASPNw ≠ ASPN*) | positive serial corr. | ↑ | 17 | |
| negative serial corr. | ↓ | 18 | ||
| (WA-e) | endogenous availability process | ↓* | 19 | |
↓ under-powered; ↑ over-powered; → adequately powered (precisely at the desired level); ↓* under-powered for some generative models. In settings 1–8 and 12–15, we considered two ways to violate each of (WA-a), (WA-b), and (WA-c): MEE(t), SPNC(t), or τ(t) has an incorrect magnitude or has a correct magnitude but an incorrect pattern. In settings 9–11, we considered a delayed effect of past treatments on the outcome, which violates (WA-b) because SPNC*(t) would depend on the delayed effect in a complicated way and we do not expect SPNCw(t) = SPNC*(t). In settings 16–18, we considered a serial correlation in the outcome, which violates (WA-b) in addition to (WA-d) because SPNC*(t) would depend on the serial correlation in a complicated way and we do not expect SPNCw(t) = SPNC*(t). In setting 19, we allow the availability to depend on past treatments and outcomes.
The practical guidelines for specifying the inputs to the sample size formula are listed in Table 3.
Table 3:
Practical guidelines for specifying the inputs to the sample size formula. : marginal excursion effect at time , defined in (2). ATE: treatment effect averaged over time on the multiplicative scale, defined in (11). SPNC(t): success probability under the null at time t, defined in (10). ASPN: success probability under the null averaged over time, defined in (12). : expected availability at time . AA: expected availability averaged over time, defined in (13).
| For |
| • Specify according to the MRT design. |
|
|
| For |
| • Use a constant pattern unless strong prior knowledge about the specific non-linear form. |
| • Calculate ATE ( if constant ). |
| • Be conservative in ATE; e.g., use the lower end of the conjectured range. |
|
|
| For |
| • Use a constant pattern unless strong prior knowledge about the specific non-linear form. |
| • Calculate ASPN ( if constant ). |
| • Be conservative in ASPN; e.g., use the lower end of the conjectured range. |
| • Use an even lower ASPN if a negative delayed effect or negative serial correlation is expected. |
|
|
| For (for MRT with availability considerations) |
| • Use a constant pattern unless strong prior knowledge about the specific non-linear form. |
| • Calculate AA. |
| • Be conservative in AA; e.g., use the lower end of the conjectured range. |
|
|
| • If availability may depend on prior treatments or outcomes, slightly increase the sample size. |
| • Try out multiple sets of inputs (formed based on domain knowledge and prior data) to the sample size formula to understand the sensitivity of the output sample size to the inputs. Be conservative and use the larger sample size among the calculated results if budget permits. |
5. Application
We illustrate the use of the sample size formula by determining the sample size of the Drink Less MRT. The Drink Less MRT was conducted in 2021, aimed at optimizing the Drink Less smartphone app to help people reduce harmful alcohol consumption17. Participants were randomized every day at 8 pm for 30 days, each time with probability 0.6 to receive an engagement push notification and with probability 0.4 to receive nothing. The protocol of the study can be found in Bell et al.18. The considerations presented here are simplified for the purpose of illustrating the use of the sample size formula. Participants were always considered available during the Drink Less MRT, but we will later consider a hypothetical situation where participants can sometimes be unavailable to illustrate this aspect of the sample size formula.
According to the MRT design we set and , and we set the desired power at 0.8 and the type I error level at 0.05. Following the recommendations in Section 4, for the remaining inputs to the sample size formula (Table 1) we set both and as constant. Thus, , and and are completely determined by ATE and ASPN, respectively. Figure 1 shows how varies with ATE and ASPN under this set of inputs. The sample size of the MRT should then be determined based on the conjectured values of ATE and ASPN through conversations with domain experts. For this illustration, suppose we choose and . Then the resulting sample size is .
Figure 1:

The dependence of the sample size formula output on ATE and ASPN, where , and so that both MEE(t) and SPNC(t) are constant.
Based on the performance of the sample size formula when working assumptions are violated (Section 4), as long as one is conservative in specifying ATE and ASPN for constant and , the output sample size should guarantee the desired power even if the true and are not constant. Nonetheless, it is always helpful to explore how sensitive is to the inputs. Suppose we keep and , and consider as inputs a variety of linear or quadratic and parameterized by and (see Figure 4 and Section 6.1 for the parameterization). Figure 2 shows how depends the pattern of the input and . When the input is linear or quadratic, is mostly larger than when is constant (Figure 2a). It is true even when so that the linear or quadratic becomes a flat line. This is because the extra degrees of freedom used by when is linear or quadratic lead to a larger (see (8)). When the input is linear or quadratic, is smaller than when is constant (Figure 2b). This implies that one may choose a nonlinear to achieve a smaller if they are confident in the prior knowledge about how the success probability of the outcome may change over time.
Figure 4:

(a-c) Illustration of parameterized by for . (d-f) Illustration of parameterized by for . (g) Illustration of parameterized by for . The figures serve to illustrate the various patterns considered. In the simulation, we also vary , and (not shown here).
Figure 2:

The dependence of the sample size formula output on the pattern of (parametrized by ) and the pattern of (parameterized by ), where and . The corresponding to constant and constant is 123, which is marked with a dashed line.
Last, we consider the hypothetical situation where participants can be unavailable so that at least for some , and examine how should be adjusted accordingly. According to the simulation results, one should consider a constant as input to the sample size formula if the true is not known, and the average availability (AA) determines the input . In this case, the required increases as AA decreases, and approximately doubles when AA decreases from 1 to 0.5 (Figure 3a). Now suppose we fix but vary the pattern of the input (parameterized by ; see Figure 4 and Section 6.1 for the parameterization). Figure 3b shows that different patterns of have minimal impact on . Therefore, it is safe to set a constant and choose based on a conjectured AA value.
Figure 3:

The dependence of the sample size formula output on the average availability (AA) and the pattern of (parametrized by ), where for both panels . For the left panel, so that both and are constant. For the right panel, takes a few different patterns and is still constant.
6. Detailed Simulation Results
6.1. Generative Models
Throughout, we set the desired type I error to be and the desired power to be . We set the total number of decision points per individual as . We used 2000 repetitions for each simulation. We consider a simple generative model (GM-0) and three generative models with more complicated features: one where the treatments have a delayed effect on the outcomes (GM-DE), one where the outcomes are serially correlated (GM-SC), and one with an endogenous availability process where depends on previous outcomes and previous treatments (GM-EA). We first describe GM-0, then describe how the other three GMs differ from GM-0. Details about the generative models are in Section C of the Supplementary Materials.
Recall we use superscript * to denote quantities about the true data generating distribution and use superscript “w” to denote inputs to the sample size formula. GM-0 is characterized by the following parameters: , and , , for is the randomization probability, and dictate the success probability null curve, and dictate the marginal excursion effect, and is the probability of being available. Each individual’s data is generated independently as follows: for individual , for if and if , and . This implies that and
For GM-DE, the generation of and is the same as GM-0, and the success probability for is . We generated from with to make the above display well-defined for . Under GM-DE, we have and .
For GM-SC, the generation of and is the same as GM-0, and the success probability for is . We only consider the case where individuals are always available for all and the causal effect is a constant. Under GM-SC, we have , and the analytic form of is in Section C.4.1 of the Supplementary Materials.
For GM-EA, the generation of and is the same as GM-0, and the success probability for is . We only consider the case where both and are constant. Under GM-EA, we have , and the analytic form of is in Section C.5.1 of the Supplementary Materials.
To clearly present the simulation results especially when certain working assumptions are violated, we parameterized , and (as well as , and ) as follows. (either or ) can be constant, linear, or quadratic in . If linear or quadratic, is parameterized in a way that it is determined by ATE and a . For example, if linear, correspond to an increasing/constant/decreasing , respectively (Figure 4b). If quadratic, different values correspond to different quadratic patterns (Figure 4c). If constant, ATE alone determines and no is needed (Figure 4a). For , we used a similar parameterization with parameter to characterize various patterns of its log-transformation, (Figure 4d–4f). The range of is narrower than [−1, 1] to ensure that the success probability is always within [0, 1]. For , we considered a linear and a periodic pattern, both parameterized by , along with a constant pattern (Figure 4g). Details about the parameterization are presented in Sections C.2.1–C.2.3 of the Supplementary Materials.
6.2. Simulation Results When All Working Assumptions Hold
Using GM-0, we conducted simulations under a variety of settings with various patterns and magnitudes of , , and when all working assumptions hold, that is, when , , and . ((WA-d) and (WA-e) automatically hold under GM-0.) We considered 1,372 simulation settings consisting of a combination of constant/linear , constant/linear/quadratic with various values, constant/log-linear/log-quadratic with various values (subject to the constraint that is a subset of ), constant/linear/periodic with various values, and a variety of values for ATE, ASPN, and AA. Details for the simulation settings are listed in Section E of the Supplementary Materials. In all settings, the power is always about the desired level (Figure 5). The power is slightly lower than the desired 0.8 (around 0.78) for settings where the output sample size is small (close to 20), likely due to the hat-matrix-based small sample correction16 employed in the estimator.
Figure 5:

Power when all working assumptions hold. The left panel shows the histogram of the power under 1,372 settings. The right panel shows the power under each setting against the output from the sample size formula.
6.3. Simulation Results When (WA-a) Is Violated
Suppose that (WA-a) is violated and the remaining working assumptions are satisfied.
Under GM-0, we considered two ways (WA-a) can be violated: the magnitude of is misspecified , or the pattern of is incorrect. The pattern of being incorrect means that either the polynomial degree of is different from (for example, one is constant and the other is non-constant linear), or that the two are of the same polynomial degree but .
When the pattern of is correct but its magnitude is misspecified, if then the MRT is under-powered; if then the MRT is over-powered (Figure 6). This is expected because, with a fixed power, a larger effect size would correspond to a smaller sample size. In addition, the power curves against are all clustered together for a variety of and a variety of patterns of . This indicates that the impact of misspecifying ATE is so substantial that it overwhelms the other aspects of the generative model.
Figure 6:

Power when (WA-a) is violated in that . Here, are both quadratic, the patterns of and are the same, and .
When the magnitude of is correct but its pattern is misspecified, whether the MRT is adequately powered depends on the type of misspecification. If the input is constant but the truth is linear or quadratic, the MRT is adequately powered (Figure 7a). On the contrary, if the input is linear or quadratic but the truth is constant, the MRT is under-powered unless is chosen close to 0 so that is nearly constant (Figure 7b). The same result was observed over a range of patterns and ATE and ASPN values, shown by the clustered curves. Section D.1 of the Supplementary Materials includes additional simulation results where one of and is linear and the other is quadratic, or the two are of the same polynomial shape but . The conclusion is that when the pattern of is misspecified, the desired power is guaranteed only if the input is constant; when is linear or quadratic and is different from , the MRT can be severely under-powered.
Figure 7:

Power when (WA-a) is violated in that the pattern of is incorrect: one of and is constant and the other is linear or quadratic. Here, , and .
6.4. Simulation Results When (WA-b) Is Violated
Suppose that (WA-b) is violated and the remaining working assumptions are satisfied.
Under GM-0, we considered two ways (WA-b) can be violated: the magnitude of is misspecified , or the pattern of is incorrect. The pattern of being incorrect means that either the polynomial degree of is different from , or that the two are of the same polynomial degree but .
When the pattern of is correct and its magnitude is misspecified, if then the MRT is under-powered; if then the MRT is over-powered (Figure 8). The amount of over-/under-power is moderated by the value of ASPN*, shown by the three clusters of curves. Therefore, if one is uncertain about the magnitude of the success probability under no treatment, one should specify a smaller .
Figure 8:

Power when (WA-b) is violated in that . Here, are both constant with and are of the same pattern, and .
When the magnitude of is correct but the pattern of is misspecified, whether the MRT is adequately powered depends on the type of misspecification. If the input is constant but the truth is linear or quadratic, the MRT is adequately powered (Figure 9a). On the contrary, if the input is linear or quadratic but the truth is constant, the MRT is under-powered unless is chosen close to 0 so that is nearly constant (Figure 9b). Section D.2 of the Supplementary Materials includes additional simulation results where one of and is linear and the other is quadratic, or the two are of the same polynomial shape but . The conclusion is that when the pattern of is misspecified, the desired power is guaranteed only if the input is constant; when is linear or quadratic and is different from , the MRT can be severely under-powered.
Figure 9:

Power when (WA-b) is violated in that the pattern of is incorrect: one of and is constant and the other is linear or quadratic. Here, are both constant, , and .
Under GM-DE, we simulated under a variety of values (recall captures the magnitude of delayed effect of on ). The violation of (WA-b) is such that the input takes a constant, log-linear, or log-quadratic form but the true does not take any of these three forms. When we choose the input so that , the is adequately powered regardless of the magnitude and direction of the delayed effect (Figure 10). However, when we ignored the delayed effect by setting and , a positive/negative would result in an over-/under-powered MRT. This is because a positive/negative would then correspond to a positive/negative delayed effect, which in turn would correspond to being less/greater than for all and thus will be less/greater than . The same result is observed over a range of patterns and patterns, shown by the clustered curves.
Figure 10:

Power when (WA-b) is violated in that has a delayed effect on so that . Here, with , and .
6.5. Simulation Results When (WA-c) Is Violated
Suppose that (WA-c) is violated and the remaining working assumptions are satisfied.
Under GM-0, we considered two ways (WA-c) can be violated: the magnitude of AA is misspecified, or the pattern of is incorrect. The pattern of being incorrect means that either one of and is linear and the other is periodic, or they are both linear or periodic but .
When the pattern of is correct and its magnitude is misspecified, if then the MRT is under-powered; if then the MRT is over-powered (Figure 11). This is expected as a larger availability probability corresponds to a larger proportion of decision points that are used in the analysis. Therefore, if one is uncertain about the magnitude of the availability probability, one should be conservative and specify a smaller one. The same result is observed over a range of patterns and patterns, shown by the clustered curves.
Figure 11:

Power when (WA-c) is violated in that but and are of the same pattern. Here, with with , and .
When the magnitude of is correct but the pattern of is misspecified, the MRT is adequately powered as long as the input is constant, regardless of whether the true is periodic or linear (Figure 12). Therefore, one can use a constant and focus on getting a good estimate of the average availability . The same result was observed over a range of patterns and patterns, shown by the clustered curves.
Figure 12:

Power when (WA-c) is violated in that the pattern of is incorrect. Here, with with ASPN , and .
6.6. Simulation Results When (WA-d) Is Violated
To simulate when (WA-d) is violated, we used GM-SC with a variety of values, where encodes the magnitude of serial correlation. depends on in a rather complicated way (see Section C.4.1 of the Supplementary Materials). We considered three ways to specify (thus but , and and . Figure 13 shows that as long as (the first two cases), the MRT will be adequately powered even if the pattern of is incorrect (thus (WA-b) is violated). When both and are incorrect, a larger results in a larger , which in turn results in a higher power (solid curves in Figure 13). In summary, when the outcome has serial correlation, as long as , the MRT will be adequately powered.
Figure 13:

Power when (WA-d) is violated in that there is serial correlation in the outcome. Here, with , and .
6.7. Simulation Result When (WA-e) Is Violated
To simulate when (WA-e) is violated, we used GM-EA with a variety of and values, where encodes the impact of on and encodes the impact of on depends on and in a rather complicated way (see Section C.5.1 of the Supplementary Materials). We considered two ways to specify (thus ), and and . Figure 14 shows that even when , the MRT can be slightly over- or under-powered depending on the direction of and , even though the power at most deviates from 0.8 by about 0.05. Thus, if (WA-e) might be violated in practice, the researcher can increase the output sample size slightly to be conservative.
Figure 14:

Power when (WA-e) is violated in that depends on and . Here, with , and with .
6.8. Simulation Results When Multiple Working Assumptions Are Violated
We consider simulation settings where multiple working assumptions are simultaneously violated in the following way, which results in a factorial design of 96 generative models:
(WA-a) is violated in that the pattern of is misspecified but its magnitude is correct. In particular, is constant and is linear or quadratic with , and . And
(WA-b) is violated in that the pattern of is misspecified but its magnitude is correct. In particular, is constant and is linear or quadratic with , and . And
(WA-c) is violated in that the pattern of is misspecified but its magnitude is correct. In particular, is constant and is linear or periodic with , and .
Sections 6.3–6.5 showed that each individual violations of the above does not affect the performance of the sample size formula. Figure 15 showed that when (WA-a), (WA-b), and (WA-c) are simultaneously violated in this way, the MRT is still adequately powered. This provides a stronger evidence for the practical guidelines in Table 3, that one should set , , and to constant values unless there is compelling evidence to the contrary.
Figure 15:

Power when (WA-a), (WA-b), and (WA-c) are simultaneously violated in that the patterns of , and are all misspecified but their magnitudes are all correct. The histogram shows power under 96 generative models, as detailed in Section 6.8.
7. Discussion
We considered the primary analysis of micro-randomized trials (MRT) with binary proximal outcomes and derived a sample size formula to guarantee desired power and type I error control under a set of working assumptions. The sample size formula is user-friendly with intuitive inputs. Extensive simulations showed that in order for the sample size formula to have good performance, one needs to have good knowledge about the following quantities (or be conservative when specifying them): the multiplicative average treatment effect (ATE), the average success probability of the outcome under no treatment (ASPN), and the average probability of availability (AA). The sample size formula is robust to the pattern of the marginal excursion effect over time , the pattern of the success probability null curve , and the expected availability over time , in that they can be incorrectly specified as constant and the desired power will still be achieved. We provided practical guidelines on how to use the formula and illustrated the formula by sizing the Drink Less MRT.
The sample size formula is applicable to MRTs where the treatment is binary. It is common for mobile health interventions to have more than two options. For example, an app may choose from multiple types of push notifications if randomized to receive treatment. To size such MRTs, one can combine all active treatments into one bucket and denote it by , and use the “any treatment vs. no treatment” comparison as the primary analysis. This way the sample size formula can still be used. Exploratory analysis can further assess the differential effect of different treatment types. If, however, one wishes to size the study for comparison across active treatments, the current method cannot be used, and we leave the sample size calculator for such settings for future research.
The sample size formula relies on knowledge of the magnitude of the treatment effect, the success probability of the outcome under no treatment, and the availability probability. When such knowledge is unavailable, an alternative is a two-stage adaptive design approach, where a pilot study is first conducted to obtain preliminary estimates of the inputs to the sample size formula, and then the sample size is re-estimated using the pilot information and additional subjects are enrolled to obtain the desired power. Such a strategy may be more efficient than a fixed-sample design, especially if uncertainty during the planning stage is high. It remains an open question of how to precisely operationalize this approach.
Another open question, as pointed out by a reviewer, is how to define a standardized effect size that combines the treatment effect and the success probability null curve. By employing such a standardized effect size, the sample size calculator may no longer depend on the the success probability null curve upon fixing the standardized effect size. However, given the potential need for new causal effect definitions and corresponding estimators, further research is necessary to fully explore this approach.
We assumed that the number of decision points, , is the same for all participants. This is usually a reasonable assumption when sizing the MRT. For MRTs where the actual number of decision points may differ by participant due to drop out, as a rule of thumb one may set a decreasing time trend for expected availability (i.e., treating those who dropped out as unavailable later in the study).
In deriving the sample size formula we did not consider time-varying covariates other than the decision point index. Therefore, in the sample size formula, the impact of the time-varying covariates on the outcome is marginalized and incorporated into how the causal effect and the success probability under the null change over time. In analyzing the MRT data, one should still adjust for time-fixed and time-varying covariates to improve precision, which can further increase power.
R code to reproduce the results in the paper can be downloaded at https://github.com/tqian/paper_MRTSampleSizeBinary.
Supplementary Material
8. Acknowledgement
The authors would like to thank Dr. Lauren Bell, Dr. Elizabeth Williamson, and Dr. Claire Garnett, as this project is partly motivated by collaborations with them. The authors would like to acknowledge grant support from National Institutes of Health (P50DA054039, P41EB028242, UH3DE028723).
Footnotes
Supplementary Materials
The following are included in the Supplementary Materials. Section A derives the large sample distribution of in Section 3.1. Section B lists a set of weaker working assumptions under which Theorem 1 holds and proves Theorem 1. Section C presents details of the generative models in the simulation. Section D includes additional simulation results.
In other words, we require that for each , the linear span of contains . For instance, if so that , and is a constant (say for all ), then must also contain at least . If and is a linear function in , then must contain at least .
Contributor Information
Eric R. Cohn, Department of Biostatistics, Harvard University.
Tianchen Qian, Department of Statistics, University of California, Irvine..
Susan A. Murphy, Department of Statistics, Harvard University.
References
- [1].Liao P, Klasnja P, Tewari A, Murphy SA. Sample size calculations for micro-randomized trials in mHealth. Statistics in medicine 2016; 35(12): 1944–1971. [DOI] [PMC free article] [PubMed] [Google Scholar]
- [2].Dempsey W, Liao P, Klasnja P, Nahum-Shani I, Murphy SA. Randomised trials for the Fitbit generation. Significance 2015; 12(6): 20–23. [DOI] [PMC free article] [PubMed] [Google Scholar]
- [3].Klasnja P, Hekler EB, Shiffman S, et al. Microrandomized trials: An experimental design for developing just-in-time adaptive interventions.. Health Psychology 2015; 34(S): 1220. [DOI] [PMC free article] [PubMed] [Google Scholar]
- [4].Qian T, Walton AE, Collins LM, et al. The microrandomized trial for developing digital interventions: Experimental design and data analysis considerations.. Psychological Methods 2022. [DOI] [PMC free article] [PubMed] [Google Scholar]
- [5].Boruvka A, Almirall D, Witkiewitz K, Murphy SA. Assessing time-varying causal effect moderation in mobile health. Journal of the American Statistical Association 2018; 113(523): 1112–1121. [DOI] [PMC free article] [PubMed] [Google Scholar]
- [6].Qian T, Yoo H, Klasnja P, Almirall D, Murphy SA. Estimating time-varying causal excursion effects in mobile health with binary outcomes. Biometrika 2021; 108(3): 507–527. [DOI] [PMC free article] [PubMed] [Google Scholar]
- [7].Liao P, Greenewald K, Klasnja P, Murphy S. Personalized heartsteps: A reinforcement learning algorithm for optimizing physical activity. Proceedings of the ACM on Interactive, Mobile, Wearable and Ubiquitous Technologies 2020; 4(1): 1–22. [DOI] [PMC free article] [PubMed] [Google Scholar]
- [8].Rabbi M, Kotov MP, Cunningham R, et al. Toward increasing engagement in substance use data collection: development of the Substance Abuse Research Assistant app and protocol for a microrandomized trial using adolescents and emerging adults. JMIR research protocols 2018; 7(7). [DOI] [PMC free article] [PubMed] [Google Scholar]
- [9].Klasnja P, Rosenberg DE, Zhou J, Anau J, Gupta A, Arterburn DE. A quality-improvement optimization pilot of BariFit, a mobile health intervention to promote physical activity after bariatric surgery. Translational Behavioral Medicine 2020. [DOI] [PubMed] [Google Scholar]
- [10].Wong-Toi E, Dahdoul T, Qian T. MRTSampleSizeBinary: Sample Size Calculator for MRT with Binary Outcomes. 2021. R package version 0.1.0. [Google Scholar]
- [11].Rubin DB. Estimating causal effects of treatments in randomized and nonrandomized studies.. Journal of educational Psychology 1974; 66(5): 688. [Google Scholar]
- [12].Robins J A new approach to causal inference in mortality studies with a sustained exposure periodapplication to control of the healthy worker survivor effect. Mathematical modelling 1986; 7(9–12): 1393–1512. [Google Scholar]
- [13].Collins LM, Dziak JJ, Kugler KC, Trail JB. Factorial experiments: efficient tools for evaluation of intervention components. American journal of preventive medicine 2014; 47(4): 498–504. [DOI] [PMC free article] [PubMed] [Google Scholar]
- [14].Fitzmaurice GM, Laird NM, Ware JH. Applied longitudinal analysis. John Wiley & Sons. 2012. [Google Scholar]
- [15].Pan W, Wall MM. Small-sample adjustments in using the sandwich variance estimator in generalized estimating equations. Statistics in medicine 2002; 21(10): 1429–1441. [DOI] [PubMed] [Google Scholar]
- [16].Mancl LA, DeRouen TA. A covariance estimator for GEE with improved small-sample properties. Biometrics 2001; 57(1): 126–134. [DOI] [PubMed] [Google Scholar]
- [17].Garnett C, Crane D, West R, Brown J, Michie S. The development of Drink Less: an alcohol reduction smartphone app for excessive drinkers. Translational behavioral medicine 2019; 9(2): 296–307. [DOI] [PMC free article] [PubMed] [Google Scholar]
- [18].Bell L, Garnett C, Qian T, Perski O, Potts HW, Williamson E. Notifications to Improve Engagement With an Alcohol Reduction App: Protocol for a Micro-Randomized Trial. JMIR research protocols 2020; 9(8): e18690. [DOI] [PMC free article] [PubMed] [Google Scholar]
Associated Data
This section collects any data citations, data availability statements, or supplementary materials included in this article.
