SPRT-package: The SPRT package

Description Details Author(s) References Examples

Description

Perform Wald's Sequential Probability Ratio Test on variables with a Normal, Bernoulli, Exponential and Poisson distribution. Plot acceptance and continuation regions, or create your own with the help of closures.

Details

Package: SPRT
Type: Package
Version: 1.0
Date: 2015-04-13
License: BSD_3_clause + file LICENSE

Author(s)

Stephane Mikael Bottine

References

Ghosh, B.K. and Sen, P.K. (1991). Handbook of Sequential Analysis, Marcel Dekker, New York. Wald, A. (1947). Sequential Analysis, Dover, New York.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# SPRT on a normally distributed random variable
set.seed(123)
test <- SPRT(distribution = "normal", type1 = 0.05, type2 = 0.20,
	h0 = 0, h1 = 1, values = rnorm(10))

# Test outcome
test

# Cum. sum of the random variable vs H0 and H1 boundaries
test$data.sum
plot(test)

# Log-likelihood ratio vs Wald's A and B boundaries
test$data.llr
plot(test, log = "y")

# Log-likelihood ratio across scalars or vectors
set.seed(123)
test$llr.fn(n = 10, sum(rnorm(10)))

set.seed(123)
test$llr.fn(n = seq(1,10,1), k = cumsum(rnorm(10)))

# H0 and H1 boundaries
test$h0.fn(n = seq(1,10,1))
test$h1.fn(n = seq(1,10,1))

Example output

Wald's Sequential Probability Ratio Test (SPRT)

Decision:
Accept H0

Distribution: normal 
n: 10, k: 0.7462564
h0: 0, h1: 1

Wald boundaries (log):
> B boundary:       -1.558 
> A boundary:        2.773 
> Likelihood ratio:  -4.254 

Preview k boundaries:
 n  values      k      h0   h1
 1 -0.5605 -0.560 -1.0581 3.27
 2 -0.2302 -0.791 -0.5581 3.77
 3  1.5587  0.768 -0.0581 4.27
 4  0.0705  0.839  0.4419 4.77
 5  0.1293  0.968  0.9419 5.27
    n      values          k          h0       h1
1   1 -0.56047565 -0.5604756 -1.05814462 3.272589
2   2 -0.23017749 -0.7906531 -0.55814462 3.772589
3   3  1.55870831  0.7680552 -0.05814462 4.272589
4   4  0.07050839  0.8385636  0.44185538 4.772589
5   5  0.12928774  0.9678513  0.94185538 5.272589
6   6  1.71506499  2.6829163  1.44185538 5.772589
7   7  0.46091621  3.1438325  1.94185538 6.272589
8   8 -1.26506123  1.8787713  2.44185538 6.772589
9   9 -0.68685285  1.1919184  2.94185538 7.272589
10 10 -0.44566197  0.7462564  3.44185538 7.772589
    n      values          k    wald.B   wald.A        llr
1   1 -0.56047565 -0.5604756 -1.558145 2.772589 -1.0604756
2   2 -0.23017749 -0.7906531 -1.558145 2.772589 -1.7906531
3   3  1.55870831  0.7680552 -1.558145 2.772589 -0.7319448
4   4  0.07050839  0.8385636 -1.558145 2.772589 -1.1614364
5   5  0.12928774  0.9678513 -1.558145 2.772589 -1.5321487
6   6  1.71506499  2.6829163 -1.558145 2.772589 -0.3170837
7   7  0.46091621  3.1438325 -1.558145 2.772589 -0.3561675
8   8 -1.26506123  1.8787713 -1.558145 2.772589 -2.1212287
9   9 -0.68685285  1.1919184 -1.558145 2.772589 -3.3080816
10 10 -0.44566197  0.7462564 -1.558145 2.772589 -4.2537436
[1] -4.253744
 [1] -1.0604756 -1.7906531 -0.7319448 -1.1614364 -1.5321487 -0.3170837
 [7] -0.3561675 -2.1212287 -3.3080816 -4.2537436
 [1] -1.05814462 -0.55814462 -0.05814462  0.44185538  0.94185538  1.44185538
 [7]  1.94185538  2.44185538  2.94185538  3.44185538
 [1] 3.272589 3.772589 4.272589 4.772589 5.272589 5.772589 6.272589 6.772589
 [9] 7.272589 7.772589

SPRT documentation built on May 2, 2019, 6:35 a.m.