simctest: Sequential implementation of Monte Carlo tests

Description Usage Arguments Value Author(s) References Examples

View source: R/simctest.R

Description

Wrapper function for convenient use of the sequential implementation of the Monte Carlo test.

Usage

1
simctest(gensample, level=0.05, epsilon=1e-3, maxsteps=1e4)

Arguments

gensample

function that performs one sampling step. Returns 0 (sampled test statistic does not exceed the observation) or 1 (sampled test static exceeds the observation).

level

level passed to getalgonthefly

epsilon

error bound epsilon passed to getalgonthefly

maxsteps

maximal number of steps to take

Value

An object of class sampalgres.

Author(s)

Axel Gandy

References

Gandy, A. (2009) Sequential Implementation of Monte Carlo Tests with Uniformly Bounded Resampling Risk. JASA 104(488):1504-1511.

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
27
28
29
  #Example used in the above paper
  dat <- matrix(nrow=5,ncol=7,byrow=TRUE,
                c(1,2,2,1,1,0,1, 2,0,0,2,3,0,0, 0,1,1,1,2,7,3, 1,1,2,0,0,0,1, 0,1,1,1,1,0,0))
  loglikrat <- function(data){
    cs <- colSums(data)
    rs <- rowSums(data)
    mu <- outer(rs,cs)/sum(rs)
    2*sum(ifelse(data<=0.5, 0,data*log(data/mu)))
  }
  resample <- function(data){
    cs <- colSums(data)
    rs <- rowSums(data)
    n <- sum(rs)
    mu <- outer(rs,cs)/n/n
    matrix(rmultinom(1,n,c(mu)),nrow=dim(data)[1],ncol=dim(data)[2])
  }
  t <- loglikrat(dat);

  # function to generate samples
  gen <- function(){loglikrat(resample(dat))>=t}

  #using simctest
  simctest(gen,maxsteps=10000)

  #now trying simctest.cont
  res <- simctest(gen,maxsteps=500)
  res

  cont(res,20000)

simctest documentation built on Nov. 4, 2019, 5:08 p.m.