index_z: Index Z data

View source: R/designs_helpers.R

index_zR Documentation

Index Z data

Description

Index Z experimental design data. This function adds alternative id (AID) and / or choice set id (CID). This is an internal function which simplifies indexation of data during generation procedures with complex designs.

Usage

index_z(Z, alt_id = NULL, type = c("AID", "CID"))

Arguments

Z

Input data.frame object to be indexed

alt_id

Alternative id to be assigned to whole dataset.

type

"AID" or "CID". Specify the desired index to be added to the dataset. By default both "AID" and "CID" are added. This is an internal function which is used in data generation procedures.

Value

data.frame Indexed dataset Z.

Examples

# Create alternatives
alt1 <- alternative$new()
alt1$add_attributes(Quality = runif(min = 0, max = 1), Price = rnorm(mean = 5))
alt2 <- alternative$new()
alt2$add_attributes(Size = runif(min = 0, max = 1), Price = rnorm(mean = 6))

# Regroup alternatives into design
edesign <- experimental_design$new(alternatives = list(alt1, alt2))
Z <- designs_r(edesign, n = 1)

# Idendex data frame
Z <- index_z(Z, alt_id = 1)

nikitagusarov/dcesimulatr documentation built on Jan. 7, 2023, 4:27 p.m.