Skip to content

Commit

Permalink
Modfed really is just too slow to be default
Browse files Browse the repository at this point in the history
  • Loading branch information
jhelvy committed May 9, 2023
1 parent 3406823 commit fb6025f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
33 changes: 16 additions & 17 deletions R/design.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
#' choice set given the sample from the prior preference distribution.
#' Defaults to `FALSE`.
#' @param method Which method to use for obtaining a Bayesian D-efficient
#' design, `"Modfed"` or `"CEA"`? Defaults to `"Modfed"`. See `?idefix::Modfed`
#' and `?idefix::CEA` for more details.
#' design, `"CEA"` or `"Modfed"`? Defaults to `"CEA"`. See `?idefix::CEA`
#' and `?idefix::Modfed` for more details.
#' @param max_iter A numeric value indicating the maximum number allowed
#' iterations when searching for a Bayesian D-efficient design. The default is
#' 50.
Expand Down Expand Up @@ -89,20 +89,18 @@
#' )
#'
#' # Make a Bayesian D-efficient design with a prior model specified
#' # Note that by default method = "Modfed" and parallel = TRUE.
#' # This example uses "CEA" because it is faster.
#' # Note that by default parallel = TRUE.
#' design_deff <- cbc_design(
#' profiles = profiles,
#' n_resp = 30, # Number of respondents
#' n_alts = 2, # Number of alternatives per question
#' n_q = 5, # Number of questions per respondent
#' n_resp = 300, # Number of respondents
#' n_alts = 3, # Number of alternatives per question
#' n_q = 6, # Number of questions per respondent
#' n_start = 1,
#' priors = list(
#' price = -0.1,
#' type = c(0.1, 0.2),
#' freshness = c(0.1, 0.2)
#' ),
#' method = "CEA",
#' parallel = FALSE
#' )
cbc_design <- function(
Expand All @@ -118,7 +116,7 @@ cbc_design <- function(
priors = NULL,
prior_no_choice = NULL,
probs = FALSE,
method = "Modfed",
method = "CEA",
max_iter = 50,
parallel = TRUE
) {
Expand Down Expand Up @@ -388,15 +386,16 @@ make_design_deff <- function(

profiles_restricted <- nrow(expand.grid(lvl.names)) > nrow(profiles)

if (profiles_restricted & (method == "CEA")) {
# "CEA" method only works with unrestricted profile set
method == "Modfed"
warning(
'The "CEA" algorithm requires the use of an unrestricted set of ',
'profiles, so "Modfed" is now being used instead.'
)
}

if (method == "CEA") {
# "CEA" method only works with unrestricted profile set
if (profiles_restricted) {
stop(
'The CEA algorithm requires the use of an unrestricted set of ',
'profiles. Set \'method = "Modfed"\', which can use restricted ',
'profiles, or consider using an unrestricted set of profiles.'
)
}
D <- idefix::CEA(
lvls = lvls,
coding = coding,
Expand Down
16 changes: 7 additions & 9 deletions man/cbc_design.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fb6025f

Please sign in to comment.