Skip to contents

This package is still early-stage. The interface works, but it is still likely to change.

toulbar2 must be installed

Design generation depends on the external toulbar2 solver.

Before generating a design:

  • make sure toulbar2 is installed on your system
  • if toulbar2 --help works in a shell, the package should be able to use it too
  • if the binary is not on PATH, set TOULBAR2_BIN environment variable to the full path

You can check what the package sees with:

1. Define the attribute space

Start by defining the attributes and their levels. This example uses two multi-level attributes and three binary attributes.

cfg <- cjtd_design_config(
  attributes = list(
    brand = c("A", "B", "C", "D"),
    price = c("very_high", "high", "mid", "low", "very_low"),
    f1 = c("off", "on"),
    f2 = c("off", "on"),
    f3 = c("off", "on")
  ),
  n_tasks = 10,
  n_alternatives = 3,
  n_versions = 2
)

2. Define restrictions

Here we add:

  • a pair prohibition: brand == "A" cannot appear with price == "very_low"
  • a count restriction: across f1, f2, f3, the number of "on" values must be between 1 and 2 within each alternative
cfg <- cjtd_forbid_pairs(
  cfg,
  attr_a = "brand",
  levels_a = "A",
  attr_b = "price",
  levels_b = "very_low"
)

cfg <- cjtd_require_n_selected(
  cfg,
  selected = list(
    f1 = "on",
    f2 = "on",
    f3 = "on"
  ),
  n = 1:2
)

3. Run the design

Generate the design with cjtd_generate_design().

design <- cjtd_generate_design(cfg)
design

On overlaps: currently the package does not expose dedicated tools to actively “motivate” the algorithm to include more overlaps. The basic balancing logic is the same as in ChoiceModelR, except that this implementation is much faster and also supports restrictions such as cjtd_require_n_selected().

If you want to experiment with allowing more overlaps, you can adjust cost_weights so that overlaps are penalized less relative to the single-level and pair-level balance terms. For example:

design <- cjtd_generate_design(
  cfg,
  cost_weights = c(single = 12, pair = 12, overlap = 1)
)

The result is a cjtd_design object. It is a list-like object that contains:

  • the original config
  • design dimensions: n_versions, n_tasks, n_alternatives
  • progress/status fields such as filled_slots, total_slots, and status
  • design_index, the internal solved design representation
  • history, with step-by-step solver information

That object is useful for diagnostics and rendering. For analysis, you will usually want to extract a tidy table.

4. Extract the usable design table

Use cjtd_extract() to get the packed design table:

packed <- cjtd_extract(design)
packed

The extracted table has:

  • version
  • task
  • alt
  • attributes, a packed tibble/data-frame column containing the attribute values for each alternative

This is the main output to reshape or unnest for downstream conjoint analysis workflows.

5. Inspect diagnostics

Use cjtd_design_diagnostics() to compute simple balance diagnostics.

diagnostics <- cjtd_design_diagnostics(design)
diagnostics

The diagnostics object includes:

  • one-dimensional level counts and summaries
  • two-dimensional pair counts and summaries
  • compact imbalance measures that help spot obvious problems

6. Render a workbook

Use cjtd_design_render() to prepare an xlsx workbook for inspection and sharing.

wb <- cjtd_design_render(design)
openxlsx::saveWorkbook(wb, "design.xlsx", overwrite = TRUE)

The workbook includes:

  • a config tab
  • a design tab built from the packed extracted table
  • a diagnostics_1d tab
  • a diagnostics_2d tab when pair diagnostics are present

This is mainly a review/export convenience layer around the design table and diagnostics.