createDataset: Create a Dataset for Choice Experiment Analysis

View source: R/createDataset.R

createDatasetR Documentation

Create a Dataset for Choice Experiment Analysis

Description

This function takes a design matrix and generates a dataset for use in choice experiments. It handles blocks, replicates the design for the number of respondents, and assigns respondent IDs.

Usage

createDataset(design, respondents)

Arguments

design

A data frame containing the design matrix for the choice experiment. It should include at least the columns Choice.situation and optionally Block.

respondents

The number of respondents to generate data for.

Details

The function performs the following steps:

  • Checks if the Block column exists in the input design. If absent, it creates a single block.

  • Calculates the number of choice sets and blocks, and determines the number of sets per block.

  • Replicates the design to account for the specified number of respondents per block.

  • Assigns respondent IDs based on the number of respondents and blocks.

Value

A data frame containing the augmented design matrix with additional columns:

ID

A unique identifier for each respondent.

Choice.situation

The original choice situations, replicated for respondents.

Other columns

All original columns in the input design are retained.

Examples

# Example usage:
design <- data.frame(
  Choice.situation = rep(1:12),
  Attribute1 = rnorm(12),
  Attribute2 = sample(1:3, 12, replace = TRUE)
)
result <- createDataset(design, 10)

simulateDCE documentation built on Aug. 8, 2025, 6:37 p.m.