Skip to content

Commit

Permalink
Merge pull request #18 from jhelvy/design-udpates
Browse files Browse the repository at this point in the history
v0.3.4 design updates
  • Loading branch information
jhelvy authored Jun 13, 2023
2 parents 0941dde + 0b697d7 commit d6b63e5
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Version: 0.3.4
Date: 2023-06-13 18:09:36 UTC
SHA:
dcb6aa72d97c124bb6194b5a5334c698d7062eb3
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: cbcTools
Title: Design and Evaluate Choice-Based Conjoint Survey Experiments
Version: 0.3.3.9001
Version: 0.3.4
Maintainer: John Helveston <[email protected]>
Authors@R: c(
person(given = "John",
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# cbcTools (development version)

# cbcTools 0.3.4

- Another small bug fix in `cbc_design()` related to #16 where factor level ordering for categorical variables were being mis-ordered.
- Updated how the `method` argument is handled by default in `cbc_design()` to be more flexible (anticipating other methods in the future).
- Added `keep_db_error` arg to `cbc_design()`.

# cbcTools 0.3.3

- Bug fix in `cbc_design()` where factor level ordering for categorical variables were being mis-ordered.
Expand Down
33 changes: 27 additions & 6 deletions R/design.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@
#' 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, `"CEA"` or `"Modfed"`? Defaults to `"CEA"`. See `?idefix::CEA`
#' and `?idefix::Modfed` for more details.
#' design, `"CEA"` or `"Modfed"`? If `priors` are specified, it defaults to
#' `"CEA"`, otherwise it defaults to `NULL`. See `?idefix::CEA` and
#' `?idefix::Modfed` for more details.
#' @param keep_db_error If `TRUE`, for Bayesian D-efficient designs the returned
#' object will be a list containing the design and the DB-error score.
#' Defaults to `FALSE`.
#' @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 @@ -101,6 +105,7 @@
#' type = c(0.1, 0.2),
#' freshness = c(0.1, 0.2)
#' ),
#' method = "CEA",
#' parallel = FALSE
#' )
cbc_design <- function(
Expand All @@ -116,10 +121,18 @@ cbc_design <- function(
priors = NULL,
prior_no_choice = NULL,
probs = FALSE,
method = "CEA",
method = NULL,
keep_db_error = FALSE,
max_iter = 50,
parallel = TRUE
) {
if (!is.null(priors)) {
if (is.null(method)) {
# Set default method to 'CEA' if priors are specified and
# user didn't specify a method.
method <- 'CEA'
}
}
check_inputs_design(
profiles,
n_resp,
Expand All @@ -134,6 +147,7 @@ cbc_design <- function(
prior_no_choice,
probs,
method,
keep_db_error,
max_iter,
parallel
)
Expand All @@ -149,7 +163,8 @@ cbc_design <- function(
} else {
design <- make_design_deff(
profiles, n_resp, n_alts, n_q, n_blocks, n_draws, no_choice, n_start,
label, priors, prior_no_choice, probs, method, max_iter, parallel
label, priors, prior_no_choice, probs, method, keep_db_error, max_iter,
parallel
)
}
# Reset row numbers
Expand Down Expand Up @@ -343,7 +358,8 @@ reorder_cols <- function(design) {

make_design_deff <- function(
profiles, n_resp, n_alts, n_q, n_blocks, n_draws, no_choice, n_start,
label, priors, prior_no_choice, probs, method, max_iter, parallel
label, priors, prior_no_choice, probs, method, keep_db_error, max_iter,
parallel
) {
# Set up initial parameters for creating design

Expand Down Expand Up @@ -404,7 +420,7 @@ make_design_deff <- function(
method <- "Modfed"
warning(
'The "CEA" algorithm requires the use of an unrestricted set of ',
'profiles, so "Modfed" is now being used instead.'
'profiles, so "Modfed" is being used instead.'
)
}

Expand Down Expand Up @@ -479,6 +495,11 @@ make_design_deff <- function(
round(D$error, 5)
)

# Return list containing the design and DB error if keep_db_error = TRUE
if (keep_db_error) {
return(list(design = design, db_err = D$error))
}

return(design)
}

Expand Down
13 changes: 7 additions & 6 deletions R/input_checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ check_inputs_design <- function(
prior_no_choice,
probs,
method,
keep_db_error,
max_iter,
parallel
) {
Expand All @@ -57,15 +58,15 @@ check_inputs_design <- function(

}

# Check that user specified an appropriate method for Bayesian D-efficient
# designs
if ((method != "CEA") & (method != "Modfed")) {
stop('The method argument must be either "Modfed" or "CEA"')
}
# Check that priors are appropriate if specified

# Check if there are missing levels in priors (if priors are used)
if (!is.null(priors)) {

# Check that user specified an appropriate method
if ((method != "CEA") & (method != "Modfed")) {
stop('The method argument must be either "Modfed" or "CEA"')
}

# Check that prior names aren't missing
prior_names <- names(priors)
profile_lvls <- profiles[,2:ncol(profiles)]
Expand Down
2 changes: 0 additions & 2 deletions inst/CITATION
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ bibentry(bibtype = "Manual",
url = "https://jhelvy.github.io/cbcTools/",
header = "To cite cbcTools in publications use:"
)


13 changes: 10 additions & 3 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 d6b63e5

Please sign in to comment.