DeclareDesign / randomizr

randomizr: Easy-to-Use Tools for Common Forms of Random Assignment and Sampling
https://declaredesign.org/r/randomizr
Other
37 stars 9 forks source link

complete_ra sometimes returns more than N randomisation values #90

Closed maj-biostat closed 2 years ago

maj-biostat commented 3 years ago

Reproducible example:

> set.seed(1); randomizr::complete_ra(1, prob_each = c(0.5, 0.5), conditions = 1:2)
[1] 2 1
> set.seed(4); randomizr::complete_ra(1, prob_each = c(0.5, 0.5), conditions = 1:2)
[1] 1
> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.2 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=en_AU.UTF-8       LC_NUMERIC=C               LC_TIME=en_AU.UTF-8       
 [4] LC_COLLATE=en_AU.UTF-8     LC_MONETARY=en_AU.UTF-8    LC_MESSAGES=en_AU.UTF-8   
 [7] LC_PAPER=en_AU.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] parallel  stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] randomizr_0.20.0     pbmcapply_1.5.0      rstan_2.21.2         StanHeaders_2.21.0-7 ggplot2_3.3.3       
[6] data.table_1.14.0   

loaded via a namespace (and not attached):
 [1] tidyselect_1.1.1    xfun_0.23           purrr_0.3.4         V8_3.4.2            colorspace_2.0-1   
 [6] vctrs_0.3.8         generics_0.1.0      stats4_4.1.0        loo_2.4.1           utf8_1.2.1         
[11] rlang_0.4.11        pkgbuild_1.2.0      pillar_1.6.1        glue_1.4.2          withr_2.4.2        
[16] DBI_1.1.1           matrixStats_0.58.0  lifecycle_1.0.0     munsell_0.5.0       gtable_0.3.0       
[21] stringfish_0.15.1   codetools_0.2-18    labeling_0.4.2      inline_0.3.19       RApiSerialize_0.1.0
[26] knitr_1.33          callr_3.7.0         ps_1.6.0            curl_4.3.1          fansi_0.5.0        
[31] Rcpp_1.0.6          scales_1.1.1        RcppParallel_5.1.4  jsonlite_1.7.2      farver_2.1.0       
[36] gridExtra_2.3       digest_0.6.27       processx_3.5.2      dplyr_1.0.6         qs_0.24.1          
[41] grid_4.1.0          cli_2.5.0           tools_4.1.0         magrittr_2.0.1      tibble_3.1.2       
[46] crayon_1.4.1        pkgconfig_2.0.3     ellipsis_0.3.2      prettyunits_1.1.1   assertthat_0.2.1   
[51] rstudioapi_0.13     R6_2.5.0            compiler_4.1.0   
nfultz commented 3 years ago

Thanks for your bug report - this appears to only happen when N = 1 and number of conditions > 1.

@acoppock I've attached a quick PR to fix this specific case, but there's several other instances of using sample(D) instead of sample(D, length(D)) that probably have the same behavior. One-argument sample sample(D) is different when D is length-one.

graemeblair commented 2 years ago

closed by https://github.com/DeclareDesign/randomizr/pull/91