Closed StevenCHowell closed 6 years ago
Yes--simply remove them from the candidate set. skpr
only uses the test points that you provide when searching for a design, so disallowed combinations are trivial to add.
That makes sense.
For the next guy (or future-me), here is one way to remove the points (6, 7, 8 in this example):
candidateset <- candidateset[-c(6, 7, 8), ]
If you load the package dplyr, you can also filter them according via a inequality or boolean expression.
For example, here I filter the allowed points down to a circle around the origin:
library(dplyr)
candset = expand.grid(x=seq(-1,1,0.1),y=c(-1,1,0.1))
filteredcandset = filter(candset, x^2+y^2 <= 1)
I am finding that even when I remove options from the candidate set, they still end up in the design. Here is some example code demonstrating this
#Setting random number generator seed:
set.seed(1)
# Generating candidate set:
candidateset = expand.grid(f1 = c(-1,1),
f2 = c(1,2,3,4,5))
# Remove disallowed combinations:
candidateset <- subset(candidateset,
!(f2 %in% c(5) & f1 %in% c(-1)) &
!(f2 %in% c(1, 2, 3) & f1 %in% c(1)))
# Generating design for hard-to-change factors:
design_htc = gen_design(candidateset = candidateset,
model = ~f1,
trials = 4)
# Generating design:
design = gen_design(candidateset = candidateset,
model = ~.,
trials = 12,
splitplotdesign = design_htc,
splitplotsizes = 3,
optimality = "Alias",
splitcolumns = TRUE)
with the resulting candidate set being
f1 | f2 | |
---|---|---|
1 | -1 | 1 |
3 | -1 | 2 |
5 | -1 | 3 |
7 | -1 | 4 |
8 | 1 | 4 |
10 | 1 | 5 |
and the resulting design
Block1 | f1 | f2 | |
---|---|---|---|
1.1 | 1 | -1 | 5 |
1.2 | 1 | -1 | 1 |
1.3 | 1 | -1 | 5 |
2.1 | 2 | -1 | 1 |
2.2 | 2 | -1 | 5 |
2.3 | 2 | -1 | 1 |
3.1 | 3 | 1 | 4 |
3.2 | 3 | 1 | 1 |
3.3 | 3 | 1 | 4 |
4.1 | 4 | 1 | 4 |
4.2 | 4 | 1 | 1 |
4.3 | 4 | 1 | 1 |
Note that I the (f1, f2) combinations (-1, 5) and (1, 1) were both removed from the candidate set but still end up in the design.
Here is the output from sessionInfo()
showing the R and skpr versions:
R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 14393)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] skpr_0.49.1 shiny_1.0.5 RevoUtils_10.0.8
[4] RevoUtilsMath_10.0.1
loaded via a namespace (and not attached):
[1] pbdZMQ_0.2-6 repr_0.12.0 splines_3.4.3 lattice_0.20-35
[5] colorspace_1.3-2 htmltools_0.3.6 viridisLite_0.2.0 rintrojs_0.2.0
[9] survival_2.41-3 rlang_0.1.6 pillar_1.0.1 withr_2.1.1
[13] registry_0.5 rngtools_1.3.1 doRNG_1.6.6 uuid_0.1-2
[17] foreach_1.4.5 plyr_1.8.4 pkgmaker_0.27 stringr_1.2.0
[21] munsell_0.4.3 rvest_0.3.2 codetools_0.2-15 kableExtra_0.9.0
[25] evaluate_0.10.1 knitr_1.18 doParallel_1.0.12 httpuv_1.3.5
[29] parallel_3.4.3 IRdisplay_0.4.4 Rcpp_0.12.14 xtable_1.8-2
[33] readr_1.1.1 backports_1.1.2 scales_0.5.0 IRkernel_0.8.11
[37] jsonlite_1.5 mime_0.5 hms_0.4.0 digest_0.6.13
[41] stringi_1.1.6 grid_3.4.3 rprojroot_1.3-1 bibtex_0.4.2
[45] tools_3.4.3 magrittr_1.5 shinythemes_1.1.1 tibble_1.4.1
[49] crayon_1.3.4 pkgconfig_2.0.1 Matrix_1.2-12 xml2_1.1.1
[53] rmarkdown_1.8 httr_1.3.1 rstudioapi_0.7 iterators_1.0.9
[57] R6_2.2.2 nlme_3.1-131 compiler_3.4.3
It looks like this is a bug--it shouldn't be hard to fix.
I expect that if f1 was easy-to-change this might not happen. I see how the hard-to-change values are assigned to the first level of randomization. When the selects points for the second level, it seems to not check the candidate set.
If I instead do
#Setting random number generator seed:
set.seed(1)
# Generating candidate set:
candidateset = expand.grid(f1 = c(-1,1),
f2 = c(1,2,3,4,5))
# Remove disallowed combinations:
candidateset <- subset(candidateset,
!(f2 %in% c(5) & f1 %in% c(-1)) &
!(f2 %in% c(1, 2, 3) & f1 %in% c(1)))
# Generating design:
design = gen_design(candidateset = candidateset,
model = ~.,
trials = 12,
optimality = "Alias",
splitcolumns = TRUE)
the resulting design is
f1 | f2 |
---|---|
-1 | 1 |
1 | 4 |
-1 | 4 |
1 | 4 |
-1 | 1 |
1 | 5 |
1 | 5 |
-1 | 4 |
-1 | 4 |
-1 | 1 |
-1 | 4 |
-1 | 1 |
which looks like it is working. This supports the idea that the issue is related to introducing a split-plot factor with disallowed combinations.
It was a simple normalization error--this is fixed in the version I just updated, v0.53.1
.
@tylermorganwall, how often do you push a new version to cran? I do not have the ability to compile from source on the machine I am using this on, and it looks like the cran version is still v0.49.1
.
I can only upload a new version every thirty days or so--any more frequently and the CRAN complains. I'll see if I can upload the most current version today.
The latest version is on CRAN--it usually takes the CRAN a few days to build all of the binaries, though.
Does
skpr
support disallowed combinations?