Skip to content

Commit 0bcf0b6

Browse files
committed
patch for no_choice to work with remove_dominant
1 parent 2ac50fb commit 0bcf0b6

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

‎R/design.R‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,21 +1316,36 @@ compute_partial_utilities_with_interactions <- function(X_matrix, priors) {
13161316
compute_partial_utilities <- function(X_matrix, priors) {
13171317
n_profiles <- nrow(X_matrix)
13181318

1319+
# Extract parameters excluding no_choice if present
1320+
if (priors$has_no_choice) {
1321+
no_choice_index <- which(names(priors$pars) == "no_choice")
1322+
pars_without_no_choice <- priors$pars[-no_choice_index]
1323+
} else {
1324+
pars_without_no_choice <- priors$pars
1325+
}
1326+
13191327
# Compute mean partial utility across par draws if exist
13201328
par_draws <- priors$par_draws
1321-
n_draws <- nrow(par_draws)
13221329
if (!is.null(par_draws)) {
1323-
pars <- par_draws[1, ]
1330+
# For Bayesian case, exclude no_choice from draws too
1331+
if (priors$has_no_choice) {
1332+
par_draws_without_no_choice <- par_draws[, -no_choice_index]
1333+
} else {
1334+
par_draws_without_no_choice <- par_draws
1335+
}
1336+
1337+
n_draws <- nrow(par_draws_without_no_choice)
1338+
pars <- par_draws_without_no_choice[1, ]
13241339
partials <- compute_partial_utility_single(X_matrix, pars, n_profiles)
13251340
for (i in 2:n_draws) {
1326-
pars <- par_draws[i, ]
1341+
pars <- par_draws_without_no_choice[i, ]
13271342
partials <- partials +
13281343
compute_partial_utility_single(X_matrix, pars, n_profiles)
13291344
}
13301345
return(partials / n_draws)
13311346
}
1332-
# Otherwise just compute direct partial utility using prior pars
1333-
return(compute_partial_utility_single(X_matrix, priors$pars, n_profiles))
1347+
# Otherwise just compute direct partial utility using prior pars (without no_choice)
1348+
return(compute_partial_utility_single(X_matrix, pars_without_no_choice, n_profiles))
13341349
}
13351350

13361351
compute_partial_utility_single <- function(X_matrix, pars, n_profiles) {

‎vignettes/design.Rmd‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,8 @@ table(design_multi_balance$price)
388388

389389
> **Note**: The `balance_by` argument cannot be used simultaneously with `label`. Choose one approach based on your design needs.
390390
391+
> **Note**: The `balance_by` feature is only available for `"random"`, `"shortcut"`, `"minoverlap"`, and `"balanced"` methods. D-optimal methods (`"stochastic"`, `"modfed"`, `"cea"`) prioritize statistical efficiency over balance and do not support this feature.
392+
391393
## Blocking
392394

393395
For D-optimal methods, create multiple design blocks to reduce respondent burden using the `n_blocks` argument. In the example below, two blocks are created with each block containing `n_q = 6` questions:

0 commit comments

Comments
 (0)