Learn R Programming

MSPRT (version 2.1)

implement.MSPRT: Implementing a MSPRT

Description

Once we have designed the MSPRT (that is, obtained the termination threshold, \(\gamma\)) using design.MSPRT(), this function implements the MSPRT algorithm for a given data. This is done by sequentially calculating the likelihood ratio(s) or bayes factor(s) (\(L_n\)), and then comparing them with the acceptance and rejection thresholds.

This function implements the MSPRT in one-sample proportion tests, and one & two-sample Z & T-tests.

Usage

implement.MSPRT(test.type, obs, obs1, obs2, side, 
                batch.seq, batch1.seq, batch2.seq,
                type1 = 0.005, type2 = 0.2, null, sigma0, term.thresh, 
                N.max, N1.max, N2.max, plot.it = T, verbose = T)

Arguments

test.type

a character; denotes the type of test.

``oneProp'' for a one-sample binomial proportion test.

``oneZ'' for a one-sample Z-test.

``oneT'' for a one-sample T-test.

``twoZ'' for a two-sample Z-test.

``twoT'' for a two-sample T-test.

obs

a numeric vector; required only in one-sample tests.

Denotes the sequentially observed data based on which we want to carry out the null hypothesis significance testing (NHST) using a one-sample test.

obs1

a numeric vector; required only in two-sample tests.

Denotes the sequentially observed data from Group-1 based on which we want to carry out the NHST using a two-sample test.

obs2

a numeric vector; required only in two-sample tests.

Denotes the sequentially observed data from Group-2 based on which we want to carry out the NHST using a two-sample test.

side

a character; direction of the alternative hypothesis H1.

Has to be one of "right" or "left".

Default: "right".

batch.seq

a numeric vector; required only in one-sample tests. Sizes of sequentially observed batches in a group sequential design.

Required only if the design is group sequential, that is when data are observed in batches. Otherwise, only need to provide N.max.

batch1.seq

a numeric vector; required only in two-sample tests. Sizes of sequentially observed batches from Group-1 in a group sequential design.

Required only if the design is group sequential, that is when data from Group-1 are observed in batches. Otherwise, only need to provide N1.max.

batch2.seq

a numeric vector; required only in two-sample tests. Sizes of sequentially observed batches from Group-2 in a group sequential design.

Required only if the design is group sequential, that is when data from Group-2 are observed in batches. Otherwise, only need to provide N2.max.

type1

a numeric in (0,1); the probability at which we want to control the Type 1 error of the MSPRT.

Default: 0.005.

type2

a numeric in (0,1); the probability at which we want to control the Type 2 error of the MSPRT.

Default: 0.2.

null

a numeric; required only in one-sample tests. the hypothesized value of parameter under the null hypothesis.

The hypothesized parameters are proportion in one-sample proportion tests, population mean in one & two-sample Z & T-tests, and difference between the population mean of Group-2 and Group-1 in two-sample Z & T-tests.

In two-sample tests, only null=0 is allowed. This is done automatically. This argument is ignored in these cases.

Default: 0.5 in one-sample binomial proportion test, and 0 in one-sample Z and T-tests.

sigma0

a positive numeric; required only in one & two-sample Z-tests. Known population standard deviation in one-sample tests and known common population standard deviation in two-sample tests.

Default: 1.

term.thresh

a positive numeric; denotes the termination threshold of a MSPRT.

This is determined at the designing step of a MSPRT using design.MSPRT().

N.max

a positive numeric (integer); required only in one-sample tests. Maximum number of samples that we can afford in the one-sample test.

In a group sequential design, this should be equal to sum(batch.seq). So in that case, it's enough to provide only batch.seq and not N.max.

N1.max

a positive numeric (integer); required only in two-sample tests. Maximum number of samples from Group-1 that we can afford in the two-sample test.

In a group sequential design, this should be equal to sum(batch1.seq). So in that case, it's enough to provide only batch1.seq and not N1.max.

N2.max

a positive numeric (integer); required only in two-sample tests. Maximum number of samples from Group-2 that we can afford in the two-sample test.

In a group sequential design, this should be equal to sum(batch2.seq). So in that case, it's enough to provide only batch2.seq and not N2.max.

plot.it

logical vector; if TRUE (Default), a comparison plot is returned. Otherwise it's not.

verbose

a logical; if TRUE, returns messages of the current proceedings; otherwise it doesn't.

Default: TRUE.

Value

Returns a list with the following components:

decision

a character; the decision reached based on the provided data.

Either "reject" (means `Reject H0') or "accept" (means `Don't reject H0') or "continue" (means `continue sampling').

n

a numeric (integer); number of samples required for reaching the decision.

lhood.ratio

a numeric vector; a vector of likelihood ratios (\(L_n\) 's) in favor of the UMPBT alternative.

This is computed at each element of batch.seq until the available data or the maximum available sample size.

rej.threshold

a numeric; Wald's rejection threshold.

acc.threshold

a numeric; Wald's acceptance threshold.

umpbt.alt

a numeric or numeric vector; denotes the UMPBT alternative(s).

At each stage, likelihood ratios (\(L_n\) 's) are computed in favor of this alternative.

psi.umpbt

a numeric; denotes the mixing probability for the UMPBT alternative in one-sample proportion tests.

Returned only in one-sample proportion tests.

Details

Suppose we want to carry out one of the above tests. To do that, we simply need to follow two steps:

Step 1: Designing the MSPRT: Determine the 'Termination threshold' using design.MSPRT().

Step 2: Implementing the MSPRT: Implement the MSPRT algorithm for a sequentially observed data using implement.MSPRT(). In Step 2, we need to use the termination threshold obtained from Step 1.

References

MSPRT: Main article and Supplemental file

Johnson, Valen E., Uniformly most powerful Bayesian tests., Ann. of Stat., 41, (4), 2013, pp. 1716-1741

Johnson, Valen E., Revised standards for statistical evidence., Proceedings of the National Academy of Sciences, 16, 1945.

Daniel J. Benjamin, James O. Berger, Magnus Johannesson, et al. Redefine statistical significance. Nature Human Behaviour, 2017.

Examples

Run this code
# NOT RUN {
# the termination thresholds are obtained from design.MSPRT()

## one-sample tests

### proportion test

x = c(0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0,
      0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0)

implement.MSPRT(obs = x, test.type = "oneProp", null = 0.2,
                term.thresh = 22.63, N.max = 30)


### Z-test

x = c(4.060319, 5.275465, 3.746557, 7.392921, 5.494262,
      3.769297, 5.731144, 6.107487, 5.863672)
      
implement.MSPRT(obs = x, test.type = "oneZ", null = 3,
                sigma0 = 1.5, term.thresh = 27.856, N.max = 30)


### T-test

x = c(1.738717, 5.076539, 1.116762, 3.105214, 5.567161, 2.095638,
      2.291750, 2.046943, 2.571340, 3.207162, 4.841446, 1.797331)

implement.MSPRT(obs = x, test.type = "oneT", null = 3,
                term.thresh = 33.152, N.max = 30)



## two-sample tests

### Z-test

x1 = c(0.6546282, 2.2772738, 4.3817680, 0.3044365, 1.8796224,
      2.1986304, 3.0619321, 1.6404530, 4.9767109)   # group-1

x2 = c(0.5570999, 1.5612114, 2.3881823, 0.2718022, 2.2936742,
       2.0451859, 2.1281266, 3.6749153, 0.1717139)   # group-2
      
implement.MSPRT(test.type = "twoZ", obs1 = x1, obs2 = x2,
                sigma0 = 1.5, term.thresh = 27.928,
                N1.max = 30, N2.max = 30)


### T-test

x1 = c(-0.93968072,  0.27546499, -1.25344292,  2.39292120,  0.49426166,
       -1.23070258,  0.73114358,  1.10748706,  0.86367203, -0.45808258,
        2.26767175,  0.58476485, -0.93186087, -3.32204983,  1.68739638,
        -0.06740041, -0.02428539,  1.41575432,  1.23183179)   # group-1

x2 = c( 0.6546282,  2.2772738,  4.3817680,  0.3044365,  1.8796224,
        2.1986304,  3.0619321,  1.6404530,  4.9767109,  1.7918195,
        2.6264761,  3.4726292,  1.4109570,  0.4404965,  4.6733434,
       -1.4666036,  3.3179069,  2.0537101,  3.5192430)   # group-2

implement.MSPRT(test.type = "twoT", obs1 = x1, obs2 = x2,
                term.thresh = 32.972, N1.max = 30, N2.max = 30)
# }

Run the code above in your browser using DataLab