Learn R Programming

logitr (version 0.1.0)

recodeData: Recode a data frame to create dummy-coded categorical and interaction variables.

Description

Recodes a list of a dataframe (data) and two vectors (parNames and randPars) with discrete (categorical) variables and interaction variables added to the data frame as well as the parNames and randPars. This function is used internally inside the main logitr() function but is also exported for use in other libraries.

Usage

recodeData(data, parNames, randPars)

Arguments

data

The choice data, formatted as a data.frame object.

parNames

The names of the parameters to be estimated in the model. Must be the same as the column names in the data argument. For WTP space models, do not include price in parNames.

randPars

A named vector whose names are the random parameters and values the distribution: 'n' for normal or 'ln' for log-normal. Defaults to NULL.

Value

A list of a dataframe (data) and two vectors (parNames and randPars) with discrete (categorical) variables and interaction variables added.

Examples

Run this code
# NOT RUN {
data(yogurt)

result <- recodeData(
    data = yogurt,
    parNames = c("price", "feat", "brand", "price*brand"),
    randPars = c(feat = "n", brand = "n")
)

result$parNames
result$randPars
head(result$data)
# }

Run the code above in your browser using DataLab