-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
81 lines (63 loc) · 2.08 KB
/
README.Rmd
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# zap
<!-- badges: start -->
<!-- badges: end -->
The goal of zap is to perform z-value based covariate-adaptive testing, as described in [our zap paper](https://academic.oup.com/jrsssb/article/84/5/1886/7072884).
## Installation
You can install the development version of zap from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("dmhleung/zap")
```
## Example
This is a basic example which shows you how to use `zap_asymp()`, taken from Setup 1 in Section 4.1 of the [paper](https://academic.oup.com/jrsssb/article/84/5/1886/7072884), for the simulation parameters $\zeta = 0.5$, $\epsilon = 1.9$ and $\eta = -2$:
```{r zap example}
set.seed(123)
RNGkind("L'Ecuyer-CMRG") # make sure we can reproduce the result even using parallel computing
library(zap)
## basic example code
dens = -2
inform = 0.5
esize = 1.9
symm = 1 # symm = 1 # if setup is S1
altvar = 1
m = 5000
P=2
ep = 1
alpha = 0.05
X = matrix(rnorm(m*P, 0, sqrt(1/2)), m,P)
direction = sample(x = c(-1, 1),
size = m,
replace = TRUE,
prob = c(1 - symm, symm)
)
coeff_reg = c(dens,rep(inform, P)) # change how asymmetrically X influence the probabilities
psi = as.numeric(crossprod(t(cbind(1, X)), coeff_reg ))
prior_mean = 2*esize*direction/(1 + exp(- inform*rowSums(X)))
wsuccess = 1/(1+exp(-psi))
gammatrue = rbinom(m,1,wsuccess)
thetatrue = prior_mean
thetatrue[!gammatrue] = 0
nbr_true_sig = sum(gammatrue )
sd = rep(1, m)
sd[gammatrue==1] = sqrt(altvar)
z = rnorm(m, mean = thetatrue, sd = sd)
pvals = 2*pnorm(abs(z), lower.tail = FALSE)
sgn = sign(z)
# apply the zap asymp function
zap_asymp_obj <- zap_asymp(z = z, X = X)
names(zap_asymp_obj)
zap_asymp_obj$rej_index
```
This package and its documentation is a work in progress. My apologies for any inconvenience at the moment!