diff --git a/examples/mnl-design-bayesian-priors.R b/examples/mnl-design-bayesian-priors.R index 867c400..e698505 100644 --- a/examples/mnl-design-bayesian-priors.R +++ b/examples/mnl-design-bayesian-priors.R @@ -5,15 +5,18 @@ rm(list = ls(all = TRUE)) # library(spdesign) # Define the list of utility functions ---- +#' Generating a design with Bayesian priors. utility <- list( - alt1 = "b_x1[0.1] * x_1[2:5] + b_x2[uniform_p(-1, 1)] * x_2[c(0, 1)] + b_x3[normal_p(0, 1)] * x_3[seq(0, 1, 0.25)]", - alt2 = "b_x1 * x_1 + b_x2 * x_2 + b_x3 * x_3" + alt1 = "b_x1[0.1] * x1[2:5] + b_x2[uniform_p(-1, 1)] * x2[c(0, 1)] + b_x3[normal_p(0, 1)] * x3[seq(0, 1, 0.25)]", + alt2 = "b_x1 * x1 + b_x2 * x2 + b_x3 * x3" ) # Generate designs ---- -design <- generate_design(utility, rows = 6, +design <- generate_design(utility, rows = 20, model = "mnl", efficiency_criteria = "d-error", - algorithm = "federov", draws = "scrambled-sobol", + algorithm = "rsc", draws = "scrambled-sobol", control = list( - max_iter = 100 + max_iter = 10000 )) + +summary(design) diff --git a/examples/mnl-design-dummy-coding-bayesian-priors-and-level-occurrrence-restrictions.R b/examples/mnl-design-dummy-coding-bayesian-priors-and-level-occurrrence-restrictions.R new file mode 100644 index 0000000..8e28276 --- /dev/null +++ b/examples/mnl-design-dummy-coding-bayesian-priors-and-level-occurrrence-restrictions.R @@ -0,0 +1,26 @@ +# +# Example file for creating a simple MNL design with Bayesian priors +# +rm(list = ls(all = TRUE)) +# library(spdesign) + +# Define the list of utility functions ---- +#' Generating a design with Bayesian priors using dummy coding and level occurrences +#' NOTE: This design may take a long time. It has to first find a candidate that +#' meets the restrictions and then evaluate whether it is better than the +#' current best. Little information is provided about the process along the way. +utility <- list( + alt1 = "b_x1_dummy[c(uniform_p(-1, 1), uniform_p(-1, 1))] * x1[c(1, 2, 3)](6:10, 4:14, 6:10) + b_x2[0.4] * x2[c(0, 1)](9:11) + b_x3[-0.2] * x3[seq(0, 1, 0.25)]", + alt2 = "b_x1_dummy * x1 + b_x2 * x2 + b_x3 * x3" +) + + +# Generate designs ---- +design <- generate_design(utility, rows = 20, + model = "mnl", efficiency_criteria = "d-error", + algorithm = "random", draws = "scrambled-sobol", + control = list( + max_iter = 10000 + )) + +summary(design) diff --git a/examples/mnl-design-dummy-coding.R b/examples/mnl-design-dummy-coding.R index 9d62842..d0d564d 100644 --- a/examples/mnl-design-dummy-coding.R +++ b/examples/mnl-design-dummy-coding.R @@ -18,3 +18,6 @@ design <- generate_design(utility, rows = 20, # Add a blocking variable to the design with 2 blocks. design <- block(design, 2) + + +summary(design) diff --git a/examples/mnl-design-random-with-specified-level-occurrence.R b/examples/mnl-design-random-with-specified-level-occurrence.R index 80c1dd8..d70db72 100644 --- a/examples/mnl-design-random-with-specified-level-occurrence.R +++ b/examples/mnl-design-random-with-specified-level-occurrence.R @@ -6,8 +6,8 @@ rm(list = ls(all = TRUE)) # Define the list of utility functions ---- utility <- list( - alt1 = "b_x1_dummy[c(0.1, 0.2)] * x_1[c(1, 3, 5)](6:10) + b_x2[0.4] * x_2[c(0, 1)](9:11) + b_x3[-0.2] * x_3[seq(0, 1, 0.25)]", - alt2 = "b_x1_dummy * x_1 + b_x2 * x_2 + b_x3 * x_3" + alt1 = "b_x1_dummy[c(0.1, 0.2)] * x1[c(1, 2, 3)](4:14) + b_x2[0.4] * x2[c(0, 1)](9:11) + b_x3[-0.2] * x3[seq(0, 1, 0.25)]", + alt2 = "b_x1_dummy * x1 + b_x2 * x2 + b_x3 * x3" ) @@ -17,3 +17,5 @@ design <- generate_design(utility, rows = 20, algorithm = "federov", draws = "scrambled-sobol") design <- block(design, 4) + +summary(design) diff --git a/examples/mnl-design-with-restrictions.R b/examples/mnl-design-with-exclusions.R similarity index 100% rename from examples/mnl-design-with-restrictions.R rename to examples/mnl-design-with-exclusions.R diff --git a/examples/mnl-design-with-interactions.R b/examples/mnl-design-with-interactions.R index 78a363b..e22b316 100644 --- a/examples/mnl-design-with-interactions.R +++ b/examples/mnl-design-with-interactions.R @@ -6,11 +6,14 @@ rm(list = ls(all = TRUE)) # Define the list of utility functions ---- utility <- list( - alt1 = "b_x1[0.1] * x_1[1:5] + b_x2[0.4] * x_2[c(0, 1)] + b_x3[-0.2] * x_3[seq(0, 1, 0.25)] + b_x1x2[-0.1] * I(x_1 * x_2)", - alt2 = "b_x1 * x_1 + b_x2 * x_2 + b_x3 * x_3" + alt1 = "b_x1[0.1] * x1[1:5] + b_x2[0.4] * x2[c(0, 1)] + b_x3[-0.2] * x3[seq(0, 1, 0.25)] + b_x1x2[-0.1] * I(x1 * x2)", + alt2 = "b_x1 * x1 + b_x2 * x2 + b_x3 * x3" ) # Generate designs ---- design <- generate_design(utility, rows = 20, model = "mnl", efficiency_criteria = "d-error", - algorithm = "federov", draws = "scrambled-sobol") + algorithm = "federov", draws = "scrambled-sobol", + dudx = "b_x3") + +summary(design) diff --git a/examples/mnl-design-with-multiway-interactions.R b/examples/mnl-design-with-multiway-interactions.R index 6dca532..31c9938 100644 --- a/examples/mnl-design-with-multiway-interactions.R +++ b/examples/mnl-design-with-multiway-interactions.R @@ -6,11 +6,14 @@ rm(list = ls(all = TRUE)) # Define the list of utility functions ---- utility <- list( - alt1 = "b_x1[0.1] * x_1[1:5] + b_x2[0.4] * x_2[c(0, 1)] + b_x3[-0.2] * x_3[seq(0, 1, 0.25)] + b_x1x2[-0.1] * I(x_1 * x_2)", - alt2 = "b_x1 * x_1 + b_x2 * x_2 + b_x3 * x_3 + b_x1x2x3[0.1] * I(x_1 * x_2 * x_3)" + alt1 = "b_x1[0.1] * x1[1:5] + b_x2[0.4] * x2[c(0, 1)] + b_x3[-0.2] * x3[seq(0, 1, 0.25)] + b_x1x2[-0.1] * I(x1 * x2)", + alt2 = "b_x1 * x1 + b_x2 * x2 + b_x3 * x3 + b_x1x2x3[0.1] * I(x1 * x2 * x3)" ) # Generate designs ---- design <- generate_design(utility, rows = 20, model = "mnl", efficiency_criteria = "d-error", - algorithm = "federov", draws = "scrambled-sobol") + algorithm = "rsc", draws = "scrambled-sobol", + dudx = "b_x3") + +summary(design) diff --git a/examples/mnl-design-with-supplied-candidate-set.R b/examples/mnl-design-with-supplied-candidate-set.R index 96357b6..a94cd9e 100644 --- a/examples/mnl-design-with-supplied-candidate-set.R +++ b/examples/mnl-design-with-supplied-candidate-set.R @@ -13,10 +13,10 @@ utility <- list( # Use the full factorial as the candidate set candidate_set <- full_factorial( list( - alt1_x1 = 1:5, + alt1_x1 = 2:5, alt1_x2 = c(0, 1), alt1_x3 = seq(0, 1, 0.25), - alt2_x1 = 1:5, + alt2_x1 = 2:5, alt2_x2 = c(0, 1), alt2_x3 = seq(0, 1, 0.25) ) @@ -30,3 +30,6 @@ design <- generate_design(utility, rows = 20, model = "mnl", efficiency_criteria = "d-error", algorithm = "federov", draws = "scrambled-sobol", candidate_set = candidate_set) + + +summary(design) diff --git a/examples/mnl-design.R b/examples/mnl-design.R index 1677fd8..bdca57a 100644 --- a/examples/mnl-design.R +++ b/examples/mnl-design.R @@ -23,3 +23,6 @@ design <- generate_design(utility, rows = 20, # Add a blocking variable to the design with 4 blocks. design <- block(design, 4) + + +summary(design)