Skip to content

filippopalomba/rcrologit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rcrologit

R build status

DISCLAIMER: If the following text is not compiling for whatever reason, please use the README.pdf file available in the repo.

The package provides estimation and inferential procedures for rank-ordered logit model with agents with heterogeneous taste preferences.

Setup

We have n i.i.d. random draws

D := ( Y i , X i ) i = 1 n

where Y i := ( Y i 0 , Y i 1 , , Y i J ) , Y i = 0 , 1 , , J , is a vector of ranks and C i := ( X i 0 , C i 1 , , C i J ) R ( J + 1 ) K , C i R K . Let the latent utility model (McFadden, 1974) be

U i j = u i j + ϵ i j , ϵ i j iid Gu ( 0 , 1 ) .

For notational convenience, define the functions r i : 0 , 1 , , J 0 , 1 , , J , i = 1 , , n . Such functions map the rank j 0 , 1 , , J into the corresponding item r ( j ) 0 , 1 , , J according to individual i 's preferences. To clarify

Y i j = k r i ( k ) = j

An observed ranking for a respondent implies a complete ordering of the underlying utilities. An individual will prefer an item with a higher utility over an item with a lower utility. If we observe a full ranking r i := ( r i ( 0 ) , r i ( 1 ) , , r i ( J ) ) , we know that

U i r i ( 0 ) > U i r i ( 1 ) > > U i r i ( J ) .

Therefore, the probability of observing a particular ranking r i is given by

P [ r i D ] = P [ U i r i ( 0 ) > U i r i ( 1 ) > > U i r i ( J ) D ] = j = 0 J 1 exp ( u i r i ( j ) ) j J exp ( u i r i ( ) ) .

In light of this, we can see that the rank-ordered logit is nothing else than a series of multinomial logit (MNL) models: when j = 0 we considered a MNL the most preferred item; another MNL for the second-ranked item to be preferred over all items except the one with rank 1, and so on. Finally, the probability of a complete ranking is made up of the product of these separate MNL probabilities. The product contains only J probabilities, because ranking the least preferred item is done with probability 1.

Modelling

In its most general form, we allow the user to model u i in the latent utility model as

$$ u_{i\ell} = X_{i\ell}^{\top} \boldsymbol{\beta}{\mathtt{F}} + Z_i^{\top} \boldsymbol{\alpha}{\ell,\mathtt{F}} + W_{i\ell}^{\top} \boldsymbol{\beta}i + V_i^{\top} \boldsymbol{\alpha}{i\ell} + \delta_{\ell} $$

An alternative, handier way to rewrite the model above is to define Z i := j = 1 J Z i × 1 ( j = ) and V i := j = 1 J V i × 1 ( j = ) , = 1 , 2 , , J , and consider the equivalent model

$$ u_{i\ell}=X_{i\ell}^\top\boldsymbol{\beta}{\mathtt{F}} + Z{i\ell}^\top\boldsymbol{\alpha}{\mathtt{F}} + W{i\ell}^\top\boldsymbol{\beta}i + V{i\ell}^\top\boldsymbol{\alpha}{i} + \delta\ell, $$

where:

  • X i are covariates varying at the unit-alternative level whose coefficients are modelled as fixed
  • Z i are covariates varying at the unit level whose coefficients are modelled as fixed
  • W i are covariates varying at the unit-alternative level whose coefficients are modelled as random
  • V i are covariates varying at the unit level whose coefficients are modelled as random the random coefficients
  • The heterogeneous taste coefficients are modeled as a joint multivariate normal and are i.i.d. across units with mean [ α R , β R ] and variance Σ .
  • δ are alternative-specific fixed effects
  • ϵ i Gu ( 0 , 1 ) are idiosyncratic i.i.d. shocks

Note that whenever W i and V i are not specified estimates a standard rank-ordered logit with no heterogeneous preferences and the conditional choice probabilities are given by

P [ r i D ] = j = 0 J 1 exp ( u i r i ( j ) ) j J exp ( u i r i ( ) ) .

If instead agents are allowed to have heterogeneous taste, then

P [ r i D ] = j = 0 J 1 exp ( u i r i ( j ) ( β i ) ) j J exp ( u i r i ( ) ( β i ) ) ϕ ( β i ; β , Σ ) d β i .

The parameter vector to be estimated is thus

θ = ( β F , β R , α F , α R , vech ( Σ ) , δ j = 1 J ) .

Estimation

The ideal maximum likelihood estimator is defined as

$$ \widehat{\theta}{\mathtt{ML}}:=\mathrm{arg}\max{\theta} \sum_{i=1}^n\log\int \prod_{j=0}^{J-1} \frac{\exp \left(u_{ir_i(j)}(\theta)\right)}{\sum\limits_{j\leq \ell\leq J} \exp \left(u_{ir_i(\ell)}(\theta)\right)} \phi(\beta_i;\beta_{\mathtt{R}},\Sigma) \mathrm{d} \beta_i. $$

We approximate the integral via montecarlo as

$$ \widehat{\mathbb{P}}{(\widehat{\beta},\widehat{\Sigma})}[r_i\mid \mathcal{D}]=\frac{1}{S}\sum{i=1}^S \prod_{j=0}^{J-1} \frac{\exp \left(u_{ir_i(j)}(\theta,\beta_i^{(s)})\right)}{\sum\limits_{j\leq \ell\leq J} \exp \left(u_{ir_i(\ell)}(\theta,\beta_i^{(s)})\right)}, $$

where $\boldsymbol{\beta}i\overset{\mathtt{iid}}{\sim}\mathsf{N}(\widehat{\boldsymbol\beta}{\mathtt{R}},\widehat{\boldsymbol{\Sigma}})$.

Installation

You can install the development version of rcrologit from GitHub with:

# install.packages("devtools")
devtools::install_github("filippopalomba/rcrologit")

Basic Usage

library(rcrologit)

data <- rcrologit_data

# Rank-ordered logit
dataprep <- dataPrep(data, idVar = "Worker_ID", rankVar = "rank",
                    altVar = "alternative",
                    covsInt.fix = list("Gender"),
                    covs.fix = list("log_Wage"), FE = c("Firm_ID"))
    
rologitEst <- rcrologit(dataprep)

# Rank-ordered logit
dataprep <- dataPrep(data, idVar = "Worker_ID", rankVar = "rank",
                    altVar = "alternative",
                    covsInt.het = list("Gender"),
                    covs.fix = list("log_Wage"), FE = c("Firm_ID"))
    
rologitEst <- rcrologit(dataprep, stdErr="skip")

About

Random Coefficients Rank-Ordered Logit

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •