Description Usage Arguments Value Author(s) See Also Examples
shape a data.frame in a suitable form for the use of the
mlogit function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | mlogit.data(
data,
choice = NULL,
shape = c("long", "wide"),
varying = NULL,
sep = ".",
alt.var = NULL,
chid.var = NULL,
alt.levels = NULL,
id.var = NULL,
group.var = NULL,
opposite = NULL,
drop.index = FALSE,
ranked = FALSE,
subset = NULL,
...
)
## S3 method for class 'mlogit.data'
print(x, ...)
## S3 method for class 'mlogit.data'
index(x, ...)
## S3 method for class 'mlogit.data'
x[i, j, drop = TRUE]
## S3 method for class 'mlogit.data'
x[[y]]
## S3 method for class 'mlogit.data'
x$y
## S3 replacement method for class 'mlogit.data'
object$y <- value
## S3 replacement method for class 'mlogit.data'
object[[y]] <- value
## S3 method for class 'mlogit.data'
mean(x, ...)
|
data |
a |
choice |
the variable indicating the choice made: it can be either a logical vector, a numerical vector with 0 where the alternative is not chosen, a factor with level 'yes' when the alternative is chosen |
shape |
the shape of the |
varying |
the indexes of the variables that are alternative specific, |
sep |
the seperator of the variable name and the alternative
name (only relevant for a |
alt.var |
the name of the variable that contains the
alternative index (for a |
chid.var |
the name of the variable that contains the choice index or the name under which the choice index will be stored, |
alt.levels |
the name of the alternatives: if null, for a
|
id.var |
the name of the variable that contains the individual index if any, |
group.var |
the name of the variable that contains the group index if any, |
opposite |
returns the opposite of the specified variables, |
drop.index |
should the index variables be dropped from the
|
ranked |
a logical value which is true if the response is a rank, |
subset |
a logical expression which defines the subset of observations to be selected, |
... |
further arguments passed to |
x, object |
a |
i |
the rows to extract, |
j |
the columns to extract, |
drop |
a boolean, equal to |
y |
the column of the |
value |
the replacement value, |
A mlogit.data object, which is a data.frame in long
format, i.e. one line for each alternative. It has a index
attribute, which is a data.frame that contains the index of
the choice made (chid), the index of the alternative (alt)
and, if any, the index of the individual (id) and of the
alternative groups (group). The choice variable is a boolean
which indicates the choice made. This function use
stats::reshape() if the data.frame is in wide format.
Yves Croissant
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | # ModeChoice is a long data.frame
data("TravelMode", package = "AER")
TM <- mlogit.data(TravelMode, choice = "choice", shape = "long",
alt.levels = c("air", "train", "bus", "car"))
# Same but the alt variable called mode is provided
TM <- mlogit.data(TravelMode ,choice = "choice", shape = "long",
alt.var = "mode")
# Same but the chid variable called individual is provided
TM <- mlogit.data(TravelMode, choice = "choice",
shape = "long", id.var = "individual",
alt.levels = c("air", "train", "bus", "car"))
# Same but with two own provided variables
TM <- mlogit.data(TravelMode, choice = "choice", shape = "long",
id.var = "individual", alt.var = "mode")
# Same but with two own provided variables which are deleted from the
# data.frame
TM <- mlogit.data(TravelMode, choice = "choice", shape = "long",
id.var = "individual", alt.var = "mode", drop.index = TRUE)
# Train is a wide data.frame with columns 'choiceid' is the choice
# index, the alternatives are named "ch1" and "ch2", the opposite of
# the variables is returned
data("Train", package = "mlogit")
Train <- mlogit.data(Train, choice = "choice", shape = "wide",
varying = 4:11, alt.levels = c("A", "B"), sep = "_",
opposite = c("price", "time", "change", "comfort"))
data("HC", package = "mlogit")
HC <- mlogit.data(HC, choice = "depvar", varying=c(2:8, 10:16), shape="wide")
# Game is a data.frame in wide format for which the response is a
# ranking variable
data("Game", package = "mlogit")
G <- mlogit.data(Game, shape="wide", varying = 1:12, alt.var = 'platform',
drop.index = TRUE, choice="ch", ranked =TRUE)
# Game2 contains the same data, but in long format
data("Game2", package = "mlogit")
G2 <- mlogit.data(Game2, shape='long', choice="ch", alt.var = 'platform', ranked = TRUE)
|
Loading required package: Formula
Loading required package: maxLik
Loading required package: miscTools
Please cite the 'maxLik' package as:
Henningsen, Arne and Toomet, Ott (2011). maxLik: A package for maximum likelihood estimation in R. Computational Statistics 26(3), 443-458. DOI 10.1007/s00180-010-0217-1.
If you have questions, suggestions, or comments regarding the 'maxLik' package, please use a forum or 'tracker' at maxLik's R-Forge site:
https://r-forge.r-project.org/projects/maxlik/
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.