Skip to content

Commit 6ad25e5

Browse files
authored
Merge branch 'main' into opt_model_names
2 parents 06857ed + dab7bc0 commit 6ad25e5

File tree

6 files changed

+79
-15
lines changed

6 files changed

+79
-15
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export(parse_multiplemember)
1717
export(parse_power)
1818
export(parse_randomeffect)
1919
export(parse_varyarguments)
20+
export(parse_varyarguments_mf)
2021
export(parse_varyarguments_w)
2122
export(random_missing)
2223
export(rbimod)

R/parse_formula.r

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,28 +243,63 @@ parse_varyarguments_w <- function(sim_args, name) {
243243

244244
conditions <- expand.grid(list_select(sim_args[['vary_arguments']],
245245
names = name,
246-
exclude = FALSE),
246+
exclude = FALSE),
247247
KEEP.OUT.ATTRS = FALSE)
248+
# conditions <- list_select(sim_args[['vary_arguments']],
249+
# names = name,
250+
# exclude = FALSE)
248251
if(any(sapply(conditions, is.list))) {
249252
loc <- sapply(conditions, is.list)
250253
simp_conditions <- conditions[loc != TRUE]
251254
list_conditions <- conditions[loc == TRUE]
252-
list_conditions <- lapply(seq_along(list_conditions), function(xx)
255+
list_conditions <- lapply(seq_along(list_conditions), function(xx)
253256
unlist(list_conditions[xx], recursive = FALSE))
254257
for(tt in seq_along(list_conditions)) {
255258
names(list_conditions[[tt]]) <- gsub("[0-9]*", "", names(list_conditions[[tt]]))
256259
}
257-
lapply(1:nrow(conditions), function(xx) c(sim_args,
260+
lapply(seq_along(conditions), function(xx) c(sim_args,
258261
simp_conditions[xx, , drop = FALSE],
259-
do.call('c', lapply(seq_along(list_conditions), function(tt)
260-
list_conditions[[tt]][xx]))
262+
do.call('c', lapply(seq_along(list_conditions), function(tt)
263+
model_fit = list_conditions[xx]))
261264
))
262265
} else {
263266
lapply(1:nrow(conditions), function(xx) c(sim_args,
264267
conditions[xx, , drop = FALSE]))
265268
}
266269

267270
}
271+
#' Parse within varying arguments
272+
#'
273+
#' @param sim_args A named list with special model formula syntax. See details and examples
274+
#' for more information. The named list may contain the following:
275+
#' \itemize{
276+
#' \item fixed: This is the fixed portion of the model (i.e. covariates)
277+
#' \item random: This is the random portion of the model (i.e. random effects)
278+
#' \item error: This is the error (i.e. residual term).
279+
#' }
280+
#' @param name The name of the within simulation condition. This is primarily
281+
#' an internal function.
282+
#'
283+
#' @export
284+
parse_varyarguments_mf <- function(sim_args, name) {
285+
286+
conditions <- list_select(sim_args[['vary_arguments']],
287+
names = name,
288+
exclude = FALSE)
289+
if(any(sapply(conditions, is.list))) {
290+
loc <- sapply(conditions, is.list)
291+
list_conditions <- conditions[loc == TRUE]
292+
update_conditions <- lapply(seq_along(conditions), function(xx) c(sim_args,
293+
model_fit = list_conditions[xx]))
294+
for(xx in seq_along(update_conditions)) {
295+
names(update_conditions[[xx]]) <- gsub("\\..*", "", names(update_conditions[[xx]]))
296+
}
297+
} else {
298+
lapply(1:nrow(conditions), function(xx) c(sim_args,
299+
conditions[xx, , drop = FALSE]))
300+
}
301+
302+
}
268303

269304

270305
#' Parse correlation arguments

R/pow_sim.r

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,20 +144,26 @@ replicate_simulation_vary <- function(sim_args, return_list = FALSE,
144144

145145
within_conditions <- list_select(sim_args[['vary_arguments']],
146146
names = c('model_fit'),
147-
exclude = FALSE)
147+
exclude = FALSE, simplify = FALSE)
148+
if(length(within_conditions) > 0 ) {
149+
within_conditions_name <- names(
150+
list_select(sim_args[['vary_arguments']],
151+
names = c('model_fit'),
152+
exclude = FALSE, simplify = TRUE)
153+
)
154+
}
148155
between_conditions <- list_select(sim_args[['vary_arguments']],
149156
names = c('model_fit', 'power'),
150-
exclude = TRUE)
157+
exclude = TRUE, simplify = FALSE)
151158

152159
between_conditions_name <- data.frame(sapply(expand.grid(between_conditions, KEEP.OUT.ATTRS = FALSE),
153160
as.character))
154-
within_conditions_name <- data.frame(sapply(expand.grid(within_conditions, KEEP.OUT.ATTRS = FALSE),
155-
as.character))
161+
156162

157163
sim_arguments <- parse_varyarguments(sim_args)
158164

159-
if(length(within_conditions_name) > 0) {
160-
sim_arguments_w <- parse_varyarguments_w(sim_args, name = c('model_fit'))
165+
if(length(within_conditions) > 0) {
166+
sim_arguments_w <- parse_varyarguments_mf(sim_args, name = c('model_fit'))
161167

162168
if(any(unlist(lapply(seq_along(sim_arguments_w), function(xx)
163169
sim_arguments_w[[xx]][['model_fit']] |> names())) == 'name')) {
@@ -184,7 +190,7 @@ replicate_simulation_vary <- function(sim_args, return_list = FALSE,
184190
}, future.seed = future.seed)
185191
}, future.seed = future.seed)
186192
}
187-
if(length(within_conditions_name) == 0) {
193+
if(length(within_conditions) == 0) {
188194

189195
power_out <- future.apply::future_lapply(seq_along(sim_arguments), function(xx) {
190196
future.apply::future_replicate(sim_arguments[[xx]][['replications']],
@@ -209,7 +215,7 @@ replicate_simulation_vary <- function(sim_args, return_list = FALSE,
209215
rep(1:sim_args[['replications']],
210216
each = num_rows[xx]/sim_args[['replications']]))
211217

212-
if(length(within_conditions_name) > 0) {
218+
if(length(within_conditions) > 0) {
213219
num_terms <- lapply(seq_along(power_out), function(xx)
214220
lapply(seq_along(power_out[[xx]]), function(yy)
215221
lapply(power_out[[xx]][[yy]], nrow))

R/simglm_master_function.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@ simglm_modelfit <- function(data, sim_args) {
6767
}
6868

6969
data
70-
}
70+
}

R/util.r

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,6 @@ list_select <- function(list, names, exclude = TRUE, simplify = FALSE) {
393393
} else {
394394
list[index]
395395
}
396-
397396
}
398397

399398
# Horrible hack to keep CRAN happy and suppress NOTES about

man/parse_varyarguments_mf.Rd

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)