View source: R/createDataset.R
createDataset | R Documentation |
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.
createDataset(design, respondents)
design |
A data frame containing the design matrix for the choice experiment.
It should include at least the columns |
respondents |
The number of respondents to generate data for. |
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.
A data frame containing the augmented design matrix with additional columns:
A unique identifier for each respondent.
The original choice situations, replicated for respondents.
All original columns in the input design
are retained.
# Example usage:
design <- data.frame(
Choice.situation = rep(1:12),
Attribute1 = rnorm(12),
Attribute2 = sample(1:3, 12, replace = TRUE)
)
result <- createDataset(design, 10)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.