X.data: function to data manipulation for model estimation

Description Usage Arguments Author(s)

View source: R/X.data.R

Description

This function help to prepare data for model estimation.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
X.data(
  data,
  choice,
  alts,
  attrs,
  attr_coding = NULL,
  attr_level = NULL,
  avi = NULL,
  interact = NULL,
  flag = "nomial"
)

Arguments

data

A tibble, input data, wide format.

choice

A character, name of column indicating individuals' choice.

alts

A vector of characters, names of all alternatives, including the none-option if any.

attrs

A list contains three slices, whose elements have to be non- negative integers. The first one is a tibble, named "attrs_alts", indicating the alternative-specific attributes (excluding ASCs); the second one, named "asc", is a vector indicating the ASCs, and the third one, named "context", is a tibble indicating the context variables (includig individuals' socio-demographics). The column names in all tibbles represent the name of attributes, or context variables. All have same numbers of rows (elements) with the length of argument "alts". The element in tibbles/vector indicates if the attribute, constant or context variable is alternative-specific: "0" means the attribute, constant or context variable is not available for the alternative (based on the sequence of alternative in the argument "alts"); except "0", if some elements in one column have a same value, then the corresponding alternatives have generic parameter in terms of this attribute, constant or context variable.

In terms of data for ordered choice (i.e., flag == "order"), there is only one slice, that is "attrs_alts", another two slices "context" and "asc" should not be included.

attr_coding

A vector of character, names of categorical attributes. Default = NULL, which means all attributes are continuous.

attr_level

A list of vector of character, representing the levels of all categorical attributes. The first element of a vector is set as base level, others are set as 1, 2, 3...in sequence. This argument is only relevent when argument "attr_coding" is not NULL. Default = NULL.

avi

A character, name of column indicating if an alternative is available to individuals. Default = NULL, indicating all alternatives are available to all respondents. Each alternative should have such a column, for example, avi = "available" then the column's name for an alternative (e.g. the alternative's name is "car") should be "available:car" or "car:avilable". If this parameter is NULL, then those columns are not necessary. If this parameter is not NULL, then in such as column, the element should be 0 if the alternative is not available otherwise 1.

interact

A vector of character, name of attributes' interaction, connected by "*". Default = NULL.

flag

A character, indicating the choice alternatives are nomial or ordered. Default = "nomial".

Author(s)

X.PAN


xf-pan/dicmo documentation built on Jan. 25, 2021, 3:04 p.m.