Learn R Programming

stcpR6 (version 0.9.7)

Stcp: Stcp Class

Description

Stcp class supports a unified framework for sequential tests and change detection algorithms for streams of univariate (sub-)Gaussian, binary, and bounded random variables.

Arguments

Methods


Method new()

Create a new Stcp object.

Usage

Stcp$new(
  method = c("ST", "SR", "CU", "GLRCU"),
  family = c("Normal", "Ber", "Bounded"),
  alternative = c("two.sided", "greater", "less"),
  threshold = log(1/0.05),
  m_pre = 0,
  delta_lower = 0.1,
  delta_upper = NULL,
  weights = NULL,
  lambdas = NULL,
  k_max = 1000
)

Arguments

method

Method of the sequential procedure.

  • ST: Sequential test based on a mixture of E-values.

  • SR: Sequential change detection based on e-SR procedure.

  • CU: Sequential change detection based on e-CUSUM procedure.

  • GLRCU: Sequential change detection based on GLR-CUSUM procedure.

family

Distribution of underlying univariate observations.

  • Normal: (sub-)Gaussian with sigma = 1.

  • Ber: Bernoulli distribution on {0,1}.

  • Bounded: General bounded distribution on [0,1]

alternative

Alternative / post-change mean space

  • two.sided: Two-sided test / change detection

  • greater: Alternative /post-change mean is greater than null / pre-change one

  • less: Alternative /post-change mean is less than null / pre-change one

threshold

Stopping threshold. We recommend to use log(1/alpha) for "ST" and "SR" methods where alpha is a testing level or 1/ARL. for "CU" and "GRLCU", we recommend to tune the threshold by using domain-specific sampler to hit the target ARL.

m_pre

The boundary of mean parameter in null / pre-change space

delta_lower

Minimum gap between null / pre-change space and alternative / post-change one. It must be strictly positive for ST, SR and CU. Currently, GLRCU does not support the minimum gap, and this param will be ignored.

delta_upper

Maximum gap between null / pre-change space and alternative / post-change one. It must be strictly positive for ST, SR and CU. Currently, GLRCU does not support the maximum gap, and this param will be ignored.

weights

If not null, the input weights will be used to initialize Stcp object.

lambdas

If not null, the input lambdas will be used to initialize Stcp object.

k_max

Positive integer to determine the maximum number of baselines. For GLRCU method, it is used as the lookup window size for GLRCU statistics.

Returns

A new Stcp object.


Method print()

Print summary of Stcp object.

Usage

Stcp$print()


Method getWeights()

Return weights of mixture of e-values / e-detectors.

Usage

Stcp$getWeights()


Method getLambdas()

Return lambda parameters of mixture of e-values / e-detectors.

Usage

Stcp$getLambdas()


Method getLogValue()

Return the log value of mixture of e-values / e-detectors.

Usage

Stcp$getLogValue()


Method getThreshold()

Return the threshold of the sequential test / change detection

Usage

Stcp$getThreshold()


Method isStopped()

Return TRUE if the sequential test / change detection was stopped by crossing the threshold.

Usage

Stcp$isStopped()


Method getTime()

Return the number of observations having been passed.

Usage

Stcp$getTime()


Method getStoppedTime()

Return the stopped time. If it has been never stopped, return zero.

Usage

Stcp$getStoppedTime()


Method reset()

Reset the stcp object to the initial setup.

Usage

Stcp$reset()


Method updateLogValues()

Update the log value and related fields by passing a vector of observations.

Usage

Stcp$updateLogValues(xs)

Arguments

xs

A numeric vector of observations.


Method updateLogValuesUntilStop()

Update the log value and related fields until the log value is crossing the boundary.

Usage

Stcp$updateLogValuesUntilStop(xs)

Arguments

xs

A numeric vector of observations.


Method updateAndReturnHistories()

Update the log value and related fields then return updated log values by passing a vector of observations.

Usage

Stcp$updateAndReturnHistories(xs)

Arguments

xs

A numeric vector of observations.


Method updateLogValuesByAvgs()

Update the log value and related fields by passing a vector of averages and number of corresponding samples.

Usage

Stcp$updateLogValuesByAvgs(x_bars, ns)

Arguments

x_bars

A numeric vector of averages.

ns

A numeric vector of sample sizes.


Method updateLogValuesUntilStopByAvgs()

Update the log value and related fields by passing a vector of averages and number of corresponding samples until the log value is crossing the boundary.

Usage

Stcp$updateLogValuesUntilStopByAvgs(x_bars, ns)

Arguments

x_bars

A numeric vector of averages.

ns

A numeric vector of sample sizes.


Method updateAndReturnHistoriesByAvgs()

Update the log value and related fields then return updated log values a vector of averages and number of corresponding samples.

Usage

Stcp$updateAndReturnHistoriesByAvgs(x_bars, ns)

Arguments

x_bars

A numeric vector of averages.

ns

A numeric vector of sample sizes.

Examples

Run this code
# Sequential Normal mean test H0: mu <= 0
# Initialize stcp object for this test.
stcp <- Stcp$new(method = "ST",
                 family = "Normal",
                 alternative = "greater",
                 threshold = log(1 / 0.05),
                 m_pre = 0)

# Update the observations
obs <- c(1.0, 3.0, 2.0)
stcp$updateLogValuesUntilStop(obs)

# Check whether the sequential test is stopped
stcp$isStopped() # TRUE

# Check when the test was stopped
stcp$getStoppedTime() # 3

# Although the number of obervaions was 4, the test was stopped at 3.
stcp$getTime() # 3

# Get the log value of the mixutre of e-values at the current time (3)
stcp$getLogValue() # 4.425555

# ...which is higher than the threshold log(1 / 0.05) ~ 2.996
stcp$getThreshold() # 2.995732

# Reset the test object
stcp$reset()

# Rerun the test but, at this time, we track updated log values
log_values <- stcp$updateAndReturnHistories(obs)
print(log_values) # 0.1159777 2.7002207 4.4255551 1.9746508

# Again, the test was stopped at 3rd observation
stcp$getStoppedTime() # 3

# But, at this time, log values were evaluated until the 4th observation.
stcp$getTime() # 4

# Print overall summary
stcp # or stcp$print() or print(stcp)
# stcp Model:
#   - Method:  ST
# - Family:  Normal
# - Alternative:  greater
# - Alpha:  0.05
# - m_pre:  0
# - Num. of mixing components:  55
# - Obs. have been passed:  4
# - Current log value:  1.974651
# - Is stopped before:  TRUE
# - Stopped time:  3

Run the code above in your browser using DataLab