Skip to content

Commit

Permalink
version 0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ymabene authored and cran-robot committed Feb 22, 2024
1 parent c4d9f2d commit b556b1c
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 30 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
@@ -1,7 +1,7 @@
Package: Counternull
Type: Package
Title: Randomization-Based Inference
Version: 0.2.0
Version: 0.2.1
Authors@R: c(
person("Mabene", "Yasmine", email = "ymabene@stanford.edu",
role = c("aut", "cre")),
Expand All @@ -27,10 +27,10 @@ Suggests: knitr, rmarkdown, testthat (>= 3.0.0)
Config/testthat/edition: 3
VignetteBuilder: knitr
NeedsCompilation: no
Packaged: 2023-08-27 22:23:17 UTC; yasmi
Packaged: 2024-02-21 21:09:32 UTC; yasmi
Author: Mabene Yasmine [aut, cre],
Bind Marie [aut],
Harvard University [cph]
Maintainer: Mabene Yasmine <ymabene@stanford.edu>
Repository: CRAN
Date/Publication: 2023-08-27 22:50:15 UTC
Date/Publication: 2024-02-21 21:22:40 UTC
20 changes: 10 additions & 10 deletions MD5
@@ -1,15 +1,15 @@
0bf5b14f7c6a3b19d16a579c1b69d631 *DESCRIPTION
3f63b171b3fd3f3a2a0dc81d6fbc3e17 *DESCRIPTION
6c4ba1102ca1c174c5f97ed59f8b2c25 *LICENSE
21032c967f9967ffebe0d9084c7088f3 *NAMESPACE
052e67f88438bb237d1467bea0067dbd *NEWS.md
3f71bb93b2688a28a78a7d34618410b6 *NEWS.md
5ba21ea823a030cf48b025c0a5f59179 *R/adjust_pvalues.R
a024334833410d1dca8577deab85731b *R/count.R
bab5430e02509d87097ac635a99a714f *R/counternull_dist.R
677f20eefa5fb0bac9624852b35b6149 *R/create_fisher_interval.R
ff7026de5ee407d61989bb1be8d63a77 *R/create_fisher_interval.R
c61ad826e9d8713bcc5b497e991c309d *R/create_null_rand.R
5c6dd896095268a3f2cdd9b31355672e *R/create_randomization_matrix.R
3d893381082c420e4313e3fa93cfa665 *R/find_counternull_values.R
c7724ee30df7897eb8d491d689d69270 *R/find_counternull_values_int.R
f2ff013e0f18669ce8bad2140df6bac6 *R/find_counternull_values.R
303e3550ca652af0086838a85b2df2cd *R/find_counternull_values_int.R
898b4af2d69cd62ac3f2eed59b69271d *R/find_set.R
c75a908a47d9550584c9bdb8212c4e68 *R/find_test_stat.R
06861e8c7dd106c205b37c32226f3b6a *R/fisher_binary.R
Expand All @@ -26,23 +26,23 @@ a32d679bfae7d065e30f119daebe0075 *R/joint_p.R
ce83e567f086289c23403cc64bb97b06 *data/sample_matrix.rda
16110a211e3538ed2a7a5a0b788c4ff0 *inst/doc/counternull_vignette.R
d77d543d537246591f4c600c741be3fe *inst/doc/counternull_vignette.Rmd
dcb88274abd7caad21d7f8324c1071fc *inst/doc/counternull_vignette.html
fa8e659e2ab5148c2171a5a4705d5925 *inst/doc/counternull_vignette.html
3b40681c9988b2a8b56ced892f1573ce *inst/extdata/sample_data.csv
7abc83daf9fa24b663f73ca81a423882 *man/adjust_pvalues.Rd
525e25356bb59f2f46616e78a4e4cae5 *man/create_fisher_interval.Rd
d4869c97c16d836ae62b476b6f7f0fa1 *man/create_fisher_interval.Rd
1f175ccc23d188e419d20d0fc027027e *man/create_null_rand.Rd
b135c76c34525aa6f37623de248af7b0 *man/create_randomization_matrix.Rd
105fb9596a598efe33a8a1b8a98f2ef6 *man/figures/README-example-1.png
61208a593b81487d03611541dae002d1 *man/figures/README-example-2.png
ba8a79becb052f4a4932186874510f5f *man/figures/README-example-3.png
662d7e444a7559c846d36370e4de0e23 *man/find_counternull_values.Rd
179114a24badc670a130aeb79e69e304 *man/find_counternull_values.Rd
098e13e7484034fef2c6bffd774dda57 *man/find_test_stat.Rd
add8460edc8927258a210b9d8653ae27 *man/sample_data.Rd
ae0766960ff42ed4847b46b6154faf6d *man/sample_matrix.Rd
e4704ce9cd1f9135d74a92e1828581e3 *tests/testthat.R
053610e865096e024900ff40c9912db0 *tests/testthat/Rplots.pdf
4ef2d5b88d0ab855c0ff8132412b7afe *tests/testthat/test-adjust_pvalues.R
23d70e75f344ef97c25ef276bf09609a *tests/testthat/test-counternull_values.R
94ee9b58423d3f59f02b289da8a9a728 *tests/testthat/test-fisher.R
1bdad3ba3c8c2ac968038784c5d500b6 *tests/testthat/test-counternull_values.R
3ab67e7fb2bb610ca7be36ebd994edb7 *tests/testthat/test-fisher.R
529b137139bf3c4f400e926ea76dce31 *tests/testthat/test-rand_dist.R
d77d543d537246591f4c600c741be3fe *vignettes/counternull_vignette.Rmd
3 changes: 3 additions & 0 deletions NEWS.md
Expand Up @@ -11,3 +11,6 @@

* Added new examples to vignette

# Counternull 0.2.1 (2024-02-21)

* Added "width" parameter to increase accuracy in counternull set
16 changes: 14 additions & 2 deletions R/create_fisher_interval.R
Expand Up @@ -5,6 +5,9 @@
#' @param null_r "null_rand" object corresponding to data used for interval
#' @param alpha Significance level for Fisher Interval (default = .05
#' for 95\% confidence)
#' @param width Integer indicating the number of values to search for to construct
#' Fisher Interval. Default value = 10000. (Increasing this argument may result
#' in increased accuracy of interval.) (Optional)
#'
#' @examples
#' \donttest{
Expand Down Expand Up @@ -43,7 +46,7 @@
#' @references \doi{10.48550/arXiv.2105.03996}
#' @export

create_fisher_interval=function(null_r,alpha=NULL){
create_fisher_interval=function(null_r,alpha=NULL,width = NULL){

if(is.null(alpha)){
alpha = .05
Expand All @@ -57,15 +60,24 @@ create_fisher_interval=function(null_r,alpha=NULL){
stop('Argument "null_r" must be of "null_rand" class.' )
}

if(!is.null(width)){
if(!is.numeric(width) | length(width) != 1){
stop('Argument "width" must be an integer.')
}

}

bounds=vector(length=2)
low_c=(alpha/2)*length(null_r$null_dist)
high_c=(1-(alpha/2))*length(null_r$null_dist)

# initial bounds are 4 times the observed effect size
low = 1
high = 10000
if(!is.null(width)){
high = max(10000, width)
} else{
high = 10000
}
bounds_l = -4*abs(null_r$t_obs)
bounds_h = 4*abs(null_r$t_obs)
i = 0
Expand Down
28 changes: 22 additions & 6 deletions R/find_counternull_values.R
Expand Up @@ -5,6 +5,9 @@
#' @param counts Vector containing lower and upper bounds for number of
#' test statistics more extreme than observed test statistic in
#' counternull randomization distribution (optional)
#' @param width Integer indicating the number of values to search for to retrieve
#' counternull set. Default value = 10000. (Increasing this argument may result
#' in additional counternull values being found.) (optional)
#' @param bw Histogram bin width (optional)
#'
#' @examples
Expand Down Expand Up @@ -42,11 +45,13 @@
#' If no counternull values are found, all entries in class are set to null.
#' If only one set of counternull values are found, "perm_two", low_two"
#' and "high_two" are set to null.
#'
#'
#' @references \doi{10.1111/j.1467-9280.1994.tb00281.x}
#' @export


find_counternull_values=function(null_r, counts = NULL, bw = NULL){
find_counternull_values=function(null_r, counts = NULL,width = NULL, bw = NULL){

if(!inherits(null_r,"null_rand")){
stop('Argument "null_r" must be of class "null_rand".')
Expand All @@ -59,6 +64,13 @@ find_counternull_values=function(null_r, counts = NULL, bw = NULL){

}

if(!is.null(width)){
if(!is.numeric(width) | length(width) != 1){
stop('Argument "width" must be an integer.')
}

}

if(is.null(counts)){
counts = null_r$counts
} else {
Expand Down Expand Up @@ -87,19 +99,23 @@ find_counternull_values=function(null_r, counts = NULL, bw = NULL){

# bounds are 4 times the observed effect size
low = 1
high = 10000
if(!is.null(width)){
high = max(10000, width)
} else{
high = 10000
}
search=seq(-4*abs(null_r$t_obs),4*abs(null_r$t_obs),
8*abs(null_r$t_obs)/(high-1))

if(null_r$alternative == "two-sided"){
s_p=search[search>=0]
s_n=search[search<0]
p=find_counternull_values_int(counts, search, null_r$t_obs, null_r$y,
p=find_counternull_values_int(counts, search,high, null_r$t_obs, null_r$y,
null_r$w, null_r$alternative,
null_r$rand_matrix,null_r$test_stat,
null_r$fun, s=0)

n=find_counternull_values_int(counts, search, null_r$t_obs, null_r$y,
n=find_counternull_values_int(counts, search, high,null_r$t_obs, null_r$y,
null_r$w, null_r$alternative,
null_r$rand_matrix, null_r$test_stat,
null_r$fun, s=1)
Expand Down Expand Up @@ -141,7 +157,7 @@ find_counternull_values=function(null_r, counts = NULL, bw = NULL){


} else{
c <- find_counternull_values_int(counts, search, null_r$t_obs,
c <- find_counternull_values_int(counts, search,high, null_r$t_obs,
null_r$y,null_r$w,
null_r$alternative,null_r$rand_matrix,
null_r$test_stat, null_r$fun, s=0)
Expand Down Expand Up @@ -285,7 +301,7 @@ plot.counternull=function(x, ...){

if(!is.null(x$low) & is.null(x$low_two)){

da=data.frame(xx = c(x$counternull_perm, null_r$null_dist),
dat=data.frame(xx = c(x$counternull_perm, null_r$null_dist),
group = rep(1:0, each = length(x$counternull_perm)))
}

Expand Down
6 changes: 4 additions & 2 deletions R/find_counternull_values_int.R
Expand Up @@ -2,6 +2,8 @@
#'
#' @param obs_c Number of extreme test statistics in null distribution
#' @param search Range of effect sizes to test as counternull values
#' @param width Integer indicating the number of values to search for to retrieve
#' counternull set.
#' @param t_obs Observed test statistic
#' @param y Vector of observed outcomes
#' @param w Vector indicating treatment assignments
Expand All @@ -19,12 +21,12 @@



find_counternull_values_int=function(obs_c, search, t_obs, y,w,
find_counternull_values_int=function(obs_c, search,width, t_obs, y,w,
alternative,rand_matrix,
test_stat, fun,
s){
low = 1
high = 10000
high = width
index = (round((low + high) / 2))
counternull_value=search[index] # estimated counternull value

Expand Down

0 comments on commit b556b1c

Please sign in to comment.