mlogit a r package for the estimation of the multinomial
play

mlogit : a R package for the estimation of the multinomial logit - PowerPoint PPT Presentation

Theoretical background Implementation Examples mlogit : a R package for the estimation of the multinomial logit Yves Croissant 1 1 (LET University Lyon II) UseR 2009 July, 9th 2009 Croissant Theoretical background Implementation Examples


  1. Theoretical background Implementation Examples mlogit : a R package for the estimation of the multinomial logit Yves Croissant 1 1 (LET University Lyon II) UseR 2009 July, 9th 2009 Croissant

  2. Theoretical background Implementation Examples Motivations the multinomial logit model is widely used to modelize the choice among a set of alternatives and R provide no function to estimate this model, mlogit enables the estimation of the basic multinomial logit model and provides the tools to manipulate the model, some extensions of the basic model (random parameter logit, heteroskedastic logit and nested logit) are also provided Croissant

  3. Theoretical background Implementation Examples Motivations the multinomial logit model is widely used to modelize the choice among a set of alternatives and R provide no function to estimate this model, mlogit enables the estimation of the basic multinomial logit model and provides the tools to manipulate the model, some extensions of the basic model (random parameter logit, heteroskedastic logit and nested logit) are also provided Croissant

  4. Theoretical background Implementation Examples Motivations the multinomial logit model is widely used to modelize the choice among a set of alternatives and R provide no function to estimate this model, mlogit enables the estimation of the basic multinomial logit model and provides the tools to manipulate the model, some extensions of the basic model (random parameter logit, heteroskedastic logit and nested logit) are also provided Croissant

  5. Theoretical background Implementation Examples Outline of the talk Theoretical background 1 Discrete choice models Logit models Implementation 2 Data management Estimation methods Estimation functions Examples 3 Croissant

  6. Theoretical background Discrete choice models Implementation Logit models Examples Random utility and decision rule  β ⊤ = 1 x 1 + ǫ 1 = V 1 + ǫ 1 U 1   β ⊤ U 2 = 1 x 1 + ǫ 2 = V 2 + ǫ 2   . . . . . .    β ⊤ = J x J + ǫ J = V J + ǫ J U J  l chosen if :  U l − U 1 = ( V l − V 1 ) + ( ǫ l − ǫ 1 ) > 0   U l − U 2 = ( V l − V 2 ) + ( ǫ l − ǫ 2 ) > 0   . . .    U l − U J = ( V l − V J ) + ( ǫ l − ǫ J ) > 0  Croissant

  7. Theoretical background Discrete choice models Implementation Logit models Examples Probability : general case  ( V l − V 1 ) + ǫ l ǫ 1 <   ǫ 2 < ( V l − V 2 ) + ǫ l   . . .    ( V l − V J ) + ǫ l ǫ J <  (P l | ǫ l ) = P( U l > U 1 , . . . , U l > U J ) = F ( ǫ 1 < ( V l − V 1 ) + ǫ l , . . . , ǫ J < ( V l − V J ) + ǫ l ) � P l = (P l | ǫ l ) f l ( ǫ l ) d ǫ l � P l = F (( V l − V 1 ) + ǫ l , . . . , ( V l − V J ) + ǫ l ) f l ( ǫ l ) d ǫ l Croissant

  8. Theoretical background Discrete choice models Implementation Logit models Examples Logit models The marginal distribution of the error terms follows a Gumbel (or extreme value) distribution, which has the following cumulative and density functions : F ( ǫ ) = e − e − ( ǫ − µ ) /θ f ( ǫ ) = 1 θ e − ( ǫ − µ ) /θ e − e − ( ǫ − µ ) /θ where µ is the location parameter and θ the scale parameter. If the observed part of utility contains an intercept, the location parameter is irrelevant. The mean is µ + γθ (where γ = 0 . 577 is the Euler-Macheroni constant) and the variance is θ π 2 6 Croissant

  9. Theoretical background Discrete choice models Implementation Logit models Examples Typology of logit models multinomial nested heteroscedastic mixed independence yes no yes yes homscedasticity yes yes no yes identical parameters yes yes yes no Croissant

  10. Theoretical background Discrete choice models Implementation Logit models Examples The multinomial logit model P l | ǫ l = P( U l > U 1 , . . . , U l > U J ) = F ( ǫ 1 < ( V l − V 1 ) + ǫ l , . . . , ǫ J < ( V l − V J ) + ǫ l ) k � = l e − e − ( Vl − Vk + ǫ l ) � = because of the hypothesis of independance and homoscedasticity. � P l = (P l | ǫ l ) f l ( ǫ l ) d ǫ l k � = l e − e − ( Vl − Vk + ǫ l ) e − e − ǫ l d ǫ l � � = e V l P l = � k e V k The probabilities that enter the log-likelihood has a closed form. Croissant

  11. Theoretical background Discrete choice models Implementation Logit models Examples The heteroskedastic logit model ( Vl − Vj + ǫ l ) − θ j � e − e P l | ǫ l = j � = i � + ∞ − ( Vl − Vk + ǫ l ) − ǫ l 1 e − ǫ l θ l d ǫ l θ k � e − e θ l e − e P l = θ l −∞ k � = l There is no closed form for this integral, but it can be writen : � + ∞ − ( Vl − Vk + θ l ln u ) θ k � e − e e − u du P l = 0 k � = l � + ∞ G ( u ) e − u du and can This integral has the form : P l = 0 efficiently estimated using Gauss-Laguerre quadrature. Croissant

  12. Theoretical background Discrete choice models Implementation Logit models Examples The nested logit model Alternatives are grouped in different nests n , m = 1 . . . N . The unobservable part of utilities still have marginal distributions which are Gumbell, but they are now correlated within nests :  � λ n  N � � � e − ǫ k /λ n exp  −  n =1 k ∈ B n It can be shown that the probability of choosing an alternative l in nest m is : k ∈ B m e V k /λ m � λ m − 1 P l = e V l /λ m �� k ∈ B n e V k /λ n � λ n � N �� n =1 Croissant

  13. Theoretical background Discrete choice models Implementation Logit models Examples The mixed (or random parameters) logit model The ǫ are assumed to be iid . But the parameters of the observed part of utility are now individual specific : V li = β ⊤ i x li e V li P li | β i = � k e V ki Some hypothesis are made about the distribution of the individual specific parameters: β i | f ( θ ). The expected value of the probability is then : e V li � � � E(P li | β i ) = . . . k e V ki f ( β, θ ) d β � The dimension of the integral is the number of random parameters Croissant

  14. Theoretical background Data management Implementation Estimation methods Examples Estimation functions Shaping the data Like panel (or longitudinal) data, data may be stored in a“wide”or in a“long”format : in“wide”format, each row is a choice and each column is a variable for a specific alternative, in“long”format, each row is an alternative and each column is a variable. with the mlogit package, data should be stored in“long”format. Raw data are reshaped using the mlogit.data function. Croissant

  15. Theoretical background Data management Implementation Estimation methods Examples Estimation functions Shaping the data Like panel (or longitudinal) data, data may be stored in a“wide”or in a“long”format : in“wide”format, each row is a choice and each column is a variable for a specific alternative, in“long”format, each row is an alternative and each column is a variable. with the mlogit package, data should be stored in“long”format. Raw data are reshaped using the mlogit.data function. Croissant

  16. Theoretical background Data management Implementation Estimation methods Examples Estimation functions Shaping the data Like panel (or longitudinal) data, data may be stored in a“wide”or in a“long”format : in“wide”format, each row is a choice and each column is a variable for a specific alternative, in“long”format, each row is an alternative and each column is a variable. with the mlogit package, data should be stored in“long”format. Raw data are reshaped using the mlogit.data function. Croissant

  17. Theoretical background Data management Implementation Estimation methods Examples Estimation functions Shaping the data Like panel (or longitudinal) data, data may be stored in a“wide”or in a“long”format : in“wide”format, each row is a choice and each column is a variable for a specific alternative, in“long”format, each row is an alternative and each column is a variable. with the mlogit package, data should be stored in“long”format. Raw data are reshaped using the mlogit.data function. Croissant

  18. Theoretical background Data management Implementation Estimation methods Examples Estimation functions Shaping the data : a“long”data.frame R> library("mlogit") R> data("ModeChoice", package = "Ecdat") R> head(ModeChoice, 5) mode ttme invc invt gc hinc psize 1 0 69 59 100 70 35 1 2 0 34 31 372 71 35 1 3 0 35 25 417 70 35 1 4 1 0 10 180 30 35 1 5 0 64 58 68 68 30 2 R> Mo <- mlogit.data(ModeChoice, choice = "mode", + shape = "long", alt.levels = c("air", + "train", "bus", "car")) Croissant

  19. Theoretical background Data management Implementation Estimation methods Examples Estimation functions R> head(Mo, 5) chid alt mode ttme invc invt gc 1.air 1 air FALSE 69 59 100 70 1.train 1 train FALSE 34 31 372 71 1.bus 1 bus FALSE 35 25 417 70 1.car 1 car TRUE 0 10 180 30 2.air 2 air FALSE 64 58 68 68 hinc psize 1.air 35 1 1.train 35 1 1.bus 35 1 1.car 35 1 2.air 30 2 Croissant

Recommend


More recommend