Description Usage Arguments Value Author(s) Examples
shape a data.frame in a suitable form for the use of the exploded logit with the mlogit function in package mlogit.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
data |
a data.frame |
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 data.frame: whether long if each row is an alternative or wide if each row is an observation |
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 wide data.frame) |
alt.var |
the name of the variable that contains the alternative index (for a long data.frame only) or the name under which the alternative index will be stored (the default name is alt) |
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 wide data.frame, they are guessed from the variable names and the choice variable (both should be the same), for a long data.frame, they are guessed from the alt.var argument |
id.var |
the name of the variable that contains the individual index if any |
opposite |
returns the opposite of the specified variables |
drop.index |
should the index variables be dropped from the data.frame |
ranked |
a logical value which is true if the response is a rank |
... |
further arguments passed to reshape |
xlogit.data
returns 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'). The choice variable is a boolean which indicates the choice made. This function use reshape if the data.frame is in wide format.
Thilo Klein
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 | ## Not run:
## Game2 is a data.frame in long format for which the response is a
## ranking variable (see example in package mlogit, function mlogit.data)
## --- 1. baseline case (equivalent to mlogit package)
## load data
data("Game2", package = "mlogit")
head(Game2, 13)
## transform data
G <- xlogit.data(Game2, shape = "long", choice = "ch",
alt.var = "platform", ranked = TRUE)
head(G, 30)
## --- 2. handle missing values
## introduce NAs
Game2$ch[Game2$ch != 1] <- NA
## transform data
G <- xlogit.data(Game2, shape = "long", choice = "ch", alt.var = "platform", ranked = TRUE)
head(G, 30)
## --- 3. handle varying choice sets
## drop choice options
Game2 <- Game2[-c(7:8),]
## transform data
G <- xlogit.data(Game2, shape = "long", choice = "ch", alt.var = "platform", ranked = TRUE)
head(G, 30)
## --- 4. run models
summary(mlogit::mlogit(ch ~ own | -1 + hours + age, G, reflevel = "PC"))
summary(mlogit::mlogit(ch ~ 0 | -1 + age | own, G))
summary(mlogit::mlogit(ch ~ 0 | -1 + age, G))
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.