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
toulbar2is installed on your system - if
toulbar2 --helpworks in a shell, the package should be able to use it too - if the binary is not on
PATH, setTOULBAR2_BINenvironment variable to the full path
You can check what the package sees with:
library(g6tr.cjtdes)
cjtd_find_toulbar2()1. Define the attribute space
Start by defining the attributes and their levels. This example uses two multi-level attributes and three binary attributes.
2. Define restrictions
Here we add:
- a pair prohibition:
brand == "A"cannot appear withprice == "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)
designOn 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, andstatus -
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)
packedThe extracted table has:
versiontaskalt-
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)
diagnosticsThe 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
configtab - a
designtab built from the packed extracted table - a
diagnostics_1dtab - a
diagnostics_2dtab when pair diagnostics are present
This is mainly a review/export convenience layer around the design table and diagnostics.