Description Usage Arguments Value Author(s) References Examples
Wrapper function for convenient use of the sequential implementation of the Monte Carlo test.
1 | simctest(gensample, level=0.05, epsilon=1e-3, maxsteps=1e4)
|
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 |
epsilon |
error bound epsilon passed to |
maxsteps |
maximal number of steps to take |
An object of class sampalgres
.
Axel Gandy
Gandy, A. (2009) Sequential Implementation of Monte Carlo Tests with Uniformly Bounded Resampling Risk. JASA 104(488):1504-1511.
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.