Skip to content

Commit 1dd0dc8

Browse files
committed
add crossed option for Spower
1 parent 5dd2a0b commit 1dd0dc8

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

R/Design.R

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
#' @param stringsAsFactors logical; should character variable inputs be coerced
2424
#' to factors when building a \code{data.frame}? Default is FALSE
2525
#'
26+
#' @param fully.crossed logical; create a fully-crossed design object? Setting to \code{FALSE}
27+
#' will attempt to combine the design elements column-wise via \code{data.frame(...)}
28+
#' instead of \code{expand.grid(...)}
29+
#'
2630
#' @return a \code{tibble} or \code{data.frame} containing the simulation experiment
2731
#' conditions to be evaluated in \code{\link{runSimulation}}
2832
#'
@@ -71,6 +75,11 @@
7175
#' Design
7276
#' print(Design, list2char = FALSE) # standard tibble output
7377
#'
78+
#' # design without crossing (inputs taken-as is)
79+
#' Design <- createDesign(N = c(10, 20),
80+
#' SD = c(1, 2), cross=FALSE)
81+
#' Design # only 2 rows
82+
#'
7483
#' ##########
7584
#'
7685
#' ## fractional factorial example
@@ -98,7 +107,7 @@
98107
#'
99108
#' }
100109
createDesign <- function(..., subset, fractional = NULL,
101-
tibble = TRUE, stringsAsFactors = FALSE){
110+
tibble = TRUE, stringsAsFactors = FALSE, fully.crossed = TRUE){
102111
dots <- list(...)
103112
if(any(sapply(dots, is, class2='data.frame') | sapply(dots, is, class2='tibble')))
104113
stop('data.frame/tibble design elements not supported; please use a list input instead',
@@ -116,7 +125,10 @@ createDesign <- function(..., subset, fractional = NULL,
116125
}
117126
colnames(ret) <- names(dots[[1L]])
118127
} else {
119-
ret <- expand.grid(..., stringsAsFactors = stringsAsFactors)
128+
ret <- if(fully.crossed)
129+
expand.grid(..., stringsAsFactors = stringsAsFactors)
130+
else
131+
data.frame(..., stringsAsFactors = stringsAsFactors)
120132
}
121133
if (!missing(subset)){
122134
e <- substitute(subset)
@@ -140,7 +152,7 @@ createDesign <- function(..., subset, fractional = NULL,
140152
#' structure.
141153
#'
142154
#' @param replications number of replications. Can be a scalar to reflect the same
143-
#' replications overall, or a vector of unequal replication bugets.
155+
#' replications overall, or a vector of unequal replication budgets.
144156
#'
145157
#' @param repeat_conditions integer vector used to repeat each design row
146158
#' the specified number of times. Can either be a single integer, which repeats

man/createDesign.Rd

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/expandReplications.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)