Skip to contents

Scores each observation by its log-likelihood ratio between a named in-control and out-of-control density and returns the reflected cumulative sum \(S_n - \min_{0 \le i \le n} S_i\), the statistic of Page's CUSUM scheme. Mirrors Python morie.fn.glm.

Usage

morie_glrtest(x, p0, p1, threshold = NULL, family = "bernoulli", sd = 1)

Arguments

x

Observed sequence, in time order.

p0, p1

In-control and out-of-control parameters, read according to family.

threshold

Optional stopping boundary \(c\); when supplied the first crossing is reported.

family

One of "bernoulli" (default; p0/p1 are success probabilities), "normal" (means, known sd) or "poisson" (rates).

sd

Known standard deviation, family = "normal" only.

Value

A list with the running estimate, terminal statistic, per-observation scores, the maximum likelihood changepoint and Lorden's information number kl.

References

Lai, T. L. (1995). Sequential changepoint detection in quality control and dynamical systems. Journal of the Royal Statistical Society B, 57(4), 613-658.

Examples

set.seed(1)
morie_glrtest(x = rbinom(50, 1, 0.5), p0 = 0.3, p1 = 0.6)
#> $estimate
#>  [1] 0.0000000 0.0000000 0.6931472 1.3862944 0.8266786 1.5198258 2.2129729
#>  [8] 2.9061201 3.5992673 3.0396515 2.4800357 1.9204199 2.6135671 2.0539513
#> [15] 2.7470985 2.1874827 2.8806299 3.5737771 3.0141613 3.7073085 4.4004557
#> [22] 3.8408399 4.5339870 3.9743713 3.4147555 2.8551397 2.2955239 1.7359081
#> [29] 2.4290553 1.8694395 1.3098237 2.0029709 1.4433551 0.8837393 1.5768865
#> [36] 2.2700337 2.9631809 2.4035651 3.0967122 2.5370965 3.2302436 3.9233908
#> [43] 4.6165380 5.3096852 6.0028324 6.6959795 6.1363638 5.5767480 6.2698951
#> [50] 6.9630423
#> 
#> $statistic
#> [1] 6.963042
#> 
#> $max_statistic
#> [1] 6.963042
#> 
#> $scores
#>  [1] -0.5596158 -0.5596158  0.6931472  0.6931472 -0.5596158  0.6931472
#>  [7]  0.6931472  0.6931472  0.6931472 -0.5596158 -0.5596158 -0.5596158
#> [13]  0.6931472 -0.5596158  0.6931472 -0.5596158  0.6931472  0.6931472
#> [19] -0.5596158  0.6931472  0.6931472 -0.5596158  0.6931472 -0.5596158
#> [25] -0.5596158 -0.5596158 -0.5596158 -0.5596158  0.6931472 -0.5596158
#> [31] -0.5596158  0.6931472 -0.5596158 -0.5596158  0.6931472  0.6931472
#> [37]  0.6931472 -0.5596158  0.6931472 -0.5596158  0.6931472  0.6931472
#> [43]  0.6931472  0.6931472  0.6931472  0.6931472 -0.5596158 -0.5596158
#> [49]  0.6931472  0.6931472
#> 
#> $changepoint
#> [1] 2
#> 
#> $kl
#> [1] 0.192042
#> 
#> $n
#> [1] 50
#> 
#> $family
#> [1] "bernoulli"
#> 
#> $p0
#> [1] 0.3
#> 
#> $p1
#> [1] 0.6
#> 
#> $method
#> [1] "Page likelihood-ratio CUSUM (Lai 1995, eq. 2.3)"
#>