Learn R Programming

RprobitB (version 1.2.0)

as_cov_names: Re-label alternative specific covariates

Description

In {RprobitB}, alternative specific covariates must be named in the format "<covariate>_<alternative>". This helper function generates the format for a given choice_data set.

Usage

as_cov_names(choice_data, cov, alternatives)

Value

The choice_data input with updated column names.

Arguments

choice_data

[data.frame]
Choice data in wide format, where each row represents one choice occasion.

cov

[character()]
Names of alternative specific covariates in choice_data.

alternatives

[atomic()]
The alternative names.

Examples

Run this code
data("Electricity", package = "mlogit")
cov <- c("pf", "cl", "loc", "wk", "tod", "seas")
alternatives <- 1:4
colnames(Electricity)
Electricity <- as_cov_names(Electricity, cov, alternatives)
colnames(Electricity)

Run the code above in your browser using DataLab