Title: | Multinomial Logit Models with Random Parameters |
---|---|
Description: | An implementation of maximum simulated likelihood method for the estimation of multinomial logit models with random coefficients as presented by Sarrias and Daziano (2017) <doi:10.18637/jss.v079.i02>. Specifically, it allows estimating models with continuous heterogeneity such as the mixed multinomial logit and the generalized multinomial logit. It also allows estimating models with discrete heterogeneity such as the latent class and the mixed-mixed multinomial logit model. |
Authors: | Mauricio Sarrias [aut, cre] , Ricardo Daziano [aut], Yves Croissant [ctb] |
Maintainer: | Mauricio Sarrias <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.1-3.3 |
Built: | 2024-11-04 04:04:14 UTC |
Source: | https://github.com/mauricio1986/gmnl |
Calculate the Akaike's information Criterion (AIC) or the Bayesian
information Criterion (BIC) for an object of class gmnl
.
## S3 method for class 'gmnl' AIC(object, ..., k = 2) ## S3 method for class 'gmnl' BIC(object, ...)
## S3 method for class 'gmnl' AIC(object, ..., k = 2) ## S3 method for class 'gmnl' BIC(object, ...)
object |
a fitted model of class |
... |
additional arguments to be passed to or from other functions. |
k |
a numeric value, use as penalty coefficient for number of parameters in the fitted model. |
For more information see AIC
or BIC
A numeric value with the corresponding AIC or BIC value.
gmnl
for the estimation of multinomial logit models with observed and unobserved individual heterogeneity.
## Estimate MNL model data("TravelMode", package = "AER") library(mlogit) TM <- mlogit.data(TravelMode, choice = "choice", shape = "long", alt.levels = c("air", "train", "bus", "car"), chid.var = "individual") mnl <- gmnl(choice ~ wait + vcost + travel + gcost | 0 , data = TM) AIC(mnl) BIC(mnl)
## Estimate MNL model data("TravelMode", package = "AER") library(mlogit) TM <- mlogit.data(TravelMode, choice = "choice", shape = "long", alt.levels = c("air", "train", "bus", "car"), chid.var = "individual") mnl <- gmnl(choice ~ wait + vcost + travel + gcost | 0 , data = TM) AIC(mnl) BIC(mnl)
Computes the “bread” of the sandwich covariance matrix for objects of class gmnl
.
## S3 method for class 'gmnl' bread(x, ...)
## S3 method for class 'gmnl' bread(x, ...)
x |
a fitted model of class |
... |
other arguments when |
For more information see bread
from the package sandwich.
The covariance matrix times observations
Zeileis A (2006), Object-oriented Computation of Sandwich Estimators. Journal of Statistical Software, 16(9), 1–16.
These are a set of functions that help to extract the variance-covariance matrix, the correlation matrix, and the standard error of the random parameters for models of class gmnl
.
cov.gmnl(x, Q = NULL) cor.gmnl(x, Q = NULL) se.cov.gmnl(x, sd = FALSE, Q = NULL, digits = max(3, getOption("digits") - 2))
cov.gmnl(x, Q = NULL) cor.gmnl(x, Q = NULL) se.cov.gmnl(x, sd = FALSE, Q = NULL, digits = max(3, getOption("digits") - 2))
x |
an object of class |
Q |
this argument is only valid if the " |
sd |
if |
digits |
the number of digits. |
The variance-covariance matrix is computed using the Cholesky decomposition .
se.cov.gmnl
function is a wrapper for the deltamethod
function of the msm package.
cov.gmnl
returns a matrix with the variance of the random parameters if the model is fitted with random coefficients. If the model is fitted with correlation = TRUE
, then the variance-covariance matrix is returned.
If correlation = TRUE
in the fitted model, then se.cov.gmnl
returns a coefficient matrix for the elements of the variance-covariance matrix or the standard deviations if sd = TRUE
.
Mauricio Sarrias [email protected]
Greene, W. H. (2012). Econometric Analysis, Seventh Edition. Pearson Hall.
Train, K. (2009). Discrete Choice Methods with Simulation. Cambridge University Press.
gmnl
for the estimation of different multinomial models with individual heterogeneity.
## Not run: ## Examples using Electricity data set from mlogit package library(mlogit) data("Electricity", package = "mlogit") Electr <- mlogit.data(Electricity, id.var = "id", choice = "choice", varying = 3:26, shape = "wide", sep = "") ## Estimate a MIXL model with correlated random parameters Elec.cor <- gmnl(choice ~ pf + cl + loc + wk + tod + seas| 0, data = Electr, subset = 1:3000, model = 'mixl', R = 10, panel = TRUE, ranp = c(cl = "n", loc = "n", wk = "n", tod = "n", seas = "n"), correlation = TRUE) ## Use functions for correlated random parameters cov.gmnl(Elec.cor) se.cov.gmnl(Elec.cor) se.cov.gmnl(Elec.cor, sd = TRUE) cor.gmnl(Elec.cor) ## End(Not run)
## Not run: ## Examples using Electricity data set from mlogit package library(mlogit) data("Electricity", package = "mlogit") Electr <- mlogit.data(Electricity, id.var = "id", choice = "choice", varying = 3:26, shape = "wide", sep = "") ## Estimate a MIXL model with correlated random parameters Elec.cor <- gmnl(choice ~ pf + cl + loc + wk + tod + seas| 0, data = Electr, subset = 1:3000, model = 'mixl', R = 10, panel = TRUE, ranp = c(cl = "n", loc = "n", wk = "n", tod = "n", seas = "n"), correlation = TRUE) ## Use functions for correlated random parameters cov.gmnl(Elec.cor) se.cov.gmnl(Elec.cor) se.cov.gmnl(Elec.cor, sd = TRUE) cor.gmnl(Elec.cor) ## End(Not run)
This a helper function to obtain the individuals' conditional estimate of the either random parameters or willingness-to-pay.
effect.gmnl(x, par = NULL, effect = c("ce", "wtp"), wrt = NULL, ...)
effect.gmnl(x, par = NULL, effect = c("ce", "wtp"), wrt = NULL, ...)
x |
an object of class |
par |
a string giving the name of the variable with a random parameter. |
effect |
a string indicating what should be computed: the conditional expectation of the individual coefficients " |
wrt |
a string indicating with respect to which variable the willingness-to-pay should be computed. |
... |
further arguments. Ignorred. |
A named list where "mean
" contains the individuals' conditional mean for the random parameter or willingness-to-pay, and where "sd.est
" contains standard errors.
Mauricio Sarrias.
Greene, W. H. (2012). Econometric Analysis, Seventh Edition. Pearson Hall.
Train, K. (2009). Discrete Choice Methods with Simulation. Cambridge University Press.
gmnl
for the estimation of multinomial Logit models with individual parameters.
## Not run: ## Data data("TravelMode", package = "AER") library(mlogit) TM <- mlogit.data(TravelMode, choice = "choice", shape = "long", alt.levels = c("air", "train", "bus", "car"), chid.var = "individual") ## MIXL model with observed heterogeneity mixl.hier <- gmnl(choice ~ vcost + gcost + travel + wait | 1 | 0 | income + size - 1, data = TM, model = "mixl", ranp = c(travel = "t", wait = "n"), mvar = list(travel = c("income","size"), wait = c("income")), R = 30, haltons = list("primes"= c(2, 17), "drop" = rep(19, 2))) ## Get the individuals' conditional mean and their standard errors for lwage bi.travel <- effect.gmnl(mixl.hier, par = "travel", effect = "ce") summary(bi.travel$mean) summary(bi.travel$sd.est) ## Get the individuals' conditional WTP of travel with respect to gcost wtp.travel <- effect.gmnl(mixl.hier, par = "travel", effect = "wtp", wrt = "gcost") summary(wtp.travel$mean) summary(wtp.travel$sd.est) ## End(Not run)
## Not run: ## Data data("TravelMode", package = "AER") library(mlogit) TM <- mlogit.data(TravelMode, choice = "choice", shape = "long", alt.levels = c("air", "train", "bus", "car"), chid.var = "individual") ## MIXL model with observed heterogeneity mixl.hier <- gmnl(choice ~ vcost + gcost + travel + wait | 1 | 0 | income + size - 1, data = TM, model = "mixl", ranp = c(travel = "t", wait = "n"), mvar = list(travel = c("income","size"), wait = c("income")), R = 30, haltons = list("primes"= c(2, 17), "drop" = rep(19, 2))) ## Get the individuals' conditional mean and their standard errors for lwage bi.travel <- effect.gmnl(mixl.hier, par = "travel", effect = "ce") summary(bi.travel$mean) summary(bi.travel$sd.est) ## Get the individuals' conditional WTP of travel with respect to gcost wtp.travel <- effect.gmnl(mixl.hier, par = "travel", effect = "wtp", wrt = "gcost") summary(wtp.travel$mean) summary(wtp.travel$sd.est) ## End(Not run)
It extracts the gradient for each observation evaluated at the estimated parameters for an object of class gmnl
.
## S3 method for class 'gmnl' estfun(x, ...)
## S3 method for class 'gmnl' estfun(x, ...)
x |
a fitted model of class |
... |
other arguments. Ignored. |
For more information see estfun
from package sandwich.
The gradient matrix of dimension
Zeileis A (2006), Object-oriented Computation of Sandwich Estimators. Journal of Statistical Software, 16(9), 1–16.
A generic function to collect coefficients and summary statistics from a gmnl
object. It is used in mtable
.
getSummary.gmnl(obj, alpha = 0.05, ...)
getSummary.gmnl(obj, alpha = 0.05, ...)
obj |
a |
alpha |
level of the confidence intervals, |
... |
further arguments, |
For more details see package memisc
Four kind of variables are used in multinomial choice models with individual heterogeneity: alternative
specific and individual specific variables; variables for the mean of the random parameters (deterministic taste variations), and variables
for the scale function. gFormula
deals with this type of models using suitable methods to extract
the elements of the model.
gFormula(object) is.gFormula(object) ## S3 method for class 'gFormula' model.frame(formula, data, ..., lhs = NULL, rhs = NULL) ## S3 method for class 'gFormula' model.matrix(object, data, rhs = NULL, Q = NULL, ...)
gFormula(object) is.gFormula(object) ## S3 method for class 'gFormula' model.frame(formula, data, ..., lhs = NULL, rhs = NULL) ## S3 method for class 'gFormula' model.matrix(object, data, rhs = NULL, Q = NULL, ...)
object |
a formula for the |
formula |
a |
data |
a |
... |
further arguments. |
lhs |
see |
rhs |
see |
Q |
number of classes for the latent class model, |
Estimate different types of multinomial logit models with observed and unobserved individual heterogneity, such as MIXL, S-MNL, G-MNL, LC and MM-MNL models. These models are estimated using Maximum Simulated Likelihood. It supports both cross-sectional and panel data.
gmnl( formula, data, subset, weights, na.action, model = c("mnl", "mixl", "smnl", "gmnl", "lc", "mm"), start = NULL, ranp = NULL, R = 40, Q = 2, haltons = NA, mvar = NULL, seed = 12345, correlation = FALSE, bound.err = 2, panel = FALSE, hgamma = c("direct", "indirect"), reflevel = NULL, init.tau = 0.1, init.gamma = 0.1, notscale = NULL, print.init = FALSE, gradient = TRUE, typeR = TRUE, ... ) ## S3 method for class 'gmnl' print( x, digits = max(3, getOption("digits") - 3), width = getOption("width"), ... ) ## S3 method for class 'gmnl' summary(object, ...) ## S3 method for class 'summary.gmnl' print( x, digits = max(3, getOption("digits") - 2), width = getOption("width"), ... ) ## S3 method for class 'gmnl' update(object, new, ...) ## S3 method for class 'gmnl' coef(object, ...) ## S3 method for class 'gmnl' model.matrix(object, ...) ## S3 method for class 'gmnl' residuals(object, outcome = TRUE, ...) ## S3 method for class 'gmnl' df.residual(object, ...) ## S3 method for class 'gmnl' fitted(object, outcome = TRUE, ...) ## S3 method for class 'gmnl' logLik(object, ...) ## S3 method for class 'gmnl' nObs(x, ...)
gmnl( formula, data, subset, weights, na.action, model = c("mnl", "mixl", "smnl", "gmnl", "lc", "mm"), start = NULL, ranp = NULL, R = 40, Q = 2, haltons = NA, mvar = NULL, seed = 12345, correlation = FALSE, bound.err = 2, panel = FALSE, hgamma = c("direct", "indirect"), reflevel = NULL, init.tau = 0.1, init.gamma = 0.1, notscale = NULL, print.init = FALSE, gradient = TRUE, typeR = TRUE, ... ) ## S3 method for class 'gmnl' print( x, digits = max(3, getOption("digits") - 3), width = getOption("width"), ... ) ## S3 method for class 'gmnl' summary(object, ...) ## S3 method for class 'summary.gmnl' print( x, digits = max(3, getOption("digits") - 2), width = getOption("width"), ... ) ## S3 method for class 'gmnl' update(object, new, ...) ## S3 method for class 'gmnl' coef(object, ...) ## S3 method for class 'gmnl' model.matrix(object, ...) ## S3 method for class 'gmnl' residuals(object, outcome = TRUE, ...) ## S3 method for class 'gmnl' df.residual(object, ...) ## S3 method for class 'gmnl' fitted(object, outcome = TRUE, ...) ## S3 method for class 'gmnl' logLik(object, ...) ## S3 method for class 'gmnl' nObs(x, ...)
formula |
a symbolic description of the model to be estimated. The formula is divided in five parts, each of them separated by the symbol |
data |
the data of class |
subset |
an optional vector specifying a subset of observations. |
weights |
an optional vector of weights. Default to 1. |
na.action |
a function wich indicated what should happen when the data
contains |
model |
a string indicating which model is estimated. The options are " |
start |
a vector of starting values. |
ranp |
a named vector whose names are the random parameters and values the distribution:
" |
R |
the number of draws of pseudo-random numbers if |
Q |
number of classes for LC or MM-MNL models. |
haltons |
only relevant if |
mvar |
only valid if |
seed |
seed for the random number generator. Default is |
correlation |
only relevant if |
bound.err |
only relevant if model is |
panel |
if |
hgamma |
a string indicated how to estimate the parameter gamma. If " |
reflevel |
the base alternative. |
init.tau |
initial value for the |
init.gamma |
initial value for |
notscale |
only relevant if model is |
print.init |
if |
gradient |
if |
typeR |
if |
... |
additional arguments to be passed to |
x , object
|
and object of class |
digits |
the number of digits. |
width |
width. |
new |
an updated formula for the |
outcome |
if |
Let the utility to person from choosing alternative
on choice occasion
be:
where is i.i.d extreme value, and
vary across individuals. Each model estimated by
gmnl
depends on how is specified. The options are the following:
S-MNL if , where the scale
varies across individuals.
MIXL if , where
is a draw from some distribution. For example, if
, then
.
GMNL if , where
is the scale parameter, and
is a parameter that controls how the variance of residual taste heterogeneity varies with scale.
LC if with probability
for
, where
is the total number of classes.
MM-MIXL if with probability
for
, where
is the total number of classes.
Observed heterogeneity can be also accommodated in the random parameters when the MIXL is estimated by including individual-specific covariates. Specifically, the vector of random coefficients is
where is a set of characteristics of individual
that influence the mean of the taste parameters; and
is matrix of parameters. To estimate this model, the fourth part of the
formula
should be specified along with the mvar
argument.
One can also allow the mean of the scale to differ across individuals by including individual-specific characteristics. Thus, the scale parameters can be written as
where is a vector of attributes of individual
. To estimate this model, the fifth part of the
formula
should include the variables that enter .
For models with latent classes, the class assignment is modeled as a semi-parametric multinomial logit format
for . Latent class models (LC and MM-MIXL) requires at least that a constant should be specified in the fifth part of the
formula
. If the class assignment, , is also determined by socio-economic characteristics, these variables can be also included in the fifth part.
Models that involve random parameters are estimated using Maximum Simulated Likelihood using the maxLik
function of maxLik
package.
An object of class “gmnl
” with the following elements
coefficients |
the named vector of coefficients, |
logLik |
a set of values of the maximum likelihood procedure, |
mf |
the model framed used, |
formula |
the formula (a |
time |
|
freq |
frequency of dependent variable, |
draws |
type of draws used, |
model |
the fitted model, |
R |
number of draws used, |
ranp |
vector indicating the variables with random parameters and their distribution, |
residuals |
the residuals, |
correlation |
whether the model is fitted assuming that the random parameters are correlated, |
bi |
matrix of conditional expectation of random parameters, |
Q |
number of classes, |
call |
the matched call. |
Mauricio Sarrias [email protected]
Keane, M., & Wasi, N. (2013). Comparing alternative models of heterogeneity in consumer choice behavior. Journal of Applied Econometrics, 28(6), 1018-1045.
Fiebig, D. G., Keane, M. P., Louviere, J., & Wasi, N. (2010). The generalized multinomial logit model: accounting for scale and coefficient heterogeneity. Marketing Science, 29(3), 393-421.
Greene, W. H., & Hensher, D. A. (2010). Does scale heterogeneity across individuals matter? An empirical assessment of alternative logit models. Transportation, 37(3), 413-428.
Train, K. (2009). Discrete choice methods with simulation. Cambridge University Press.
mlogit
, mlogit.data
, maxLik
, Rchoice
## Examples using the Fishing data set from the AER package data("TravelMode", package = "AER") library(mlogit) TM <- mlogit.data(TravelMode, choice = "choice", shape = "long", alt.levels = c("air", "train", "bus", "car"), chid.var = "individual") ## Not run: ## S-MNL model, ASCs not scaled smnl <- gmnl(choice ~ wait + vcost + travel + gcost| 1, data = TM, model = "smnl", R = 100, notscale = c(1, 1, 1, rep(0, 4))) summary(smnl) ## MIXL model with observed heterogeneity mixl.hier <- gmnl(choice ~ vcost + gcost + travel + wait | 1 | 0 | income + size - 1, data = TM, model = "mixl", ranp = c(travel = "t", wait = "n"), mvar = list(travel = c("income","size"), wait = c("income")), R = 30, haltons = list("primes"= c(2, 17), "drop" = rep(19, 2))) summary(mixl.hier) ## Examples using the Electricity data set from the mlogit package data("Electricity", package = "mlogit") Electr <- mlogit.data(Electricity, id.var = "id", choice = "choice", varying = 3:26, shape = "wide", sep = "") ## Estimate a MIXL model with correlated random parameters Elec.cor <- gmnl(choice ~ pf + cl + loc + wk + tod + seas| 0, data = Electr, subset = 1:3000, model = 'mixl', R = 10, panel = TRUE, ranp = c(cl = "n", loc = "n", wk = "n", tod = "n", seas = "n"), correlation = TRUE) summary(Elec.cor) cov.gmnl(Elec.cor) se.cov.gmnl(Elec.cor) se.cov.gmnl(Elec.cor, sd = TRUE) cor.gmnl(Elec.cor) ## Estimate a G-MNL model, where ASCs are also random Electr$asc2 <- as.numeric(Electr$alt == 2) Electr$asc3 <- as.numeric(Electr$alt == 3) Electr$asc4 <- as.numeric(Electr$alt == 4) Elec.gmnl <- gmnl(choice ~ pf + cl + loc + wk + tod + seas + asc2 + asc3 + asc4 | 0, data = Electr, subset = 1:3000, model = 'gmnl', R = 30, panel = TRUE, notscale = c(rep(0, 6), 1, 1, 1), ranp = c(cl = "n", loc = "n", wk = "n", tod = "n", seas = "n", asc2 = "n", asc3 = "n", asc4 = "n")) summary(Elec.gmnl) ## Estimate a LC model with 2 classes Elec.lc <- gmnl(choice ~ pf + cl + loc + wk + tod + seas| 0 | 0 | 0 | 1, data = Electr, subset = 1:3000, model = 'lc', panel = TRUE, Q = 2) summary(Elec.lc) ## Estimate a MM-MIXL model Elec.mm <- gmnl(choice ~ pf + cl + loc + wk + tod + seas| 0 | 0 | 0 | 1, data = Electr, subset = 1:3000, model = 'mm', R = 30, panel = TRUE, ranp = c(pf = "n", cl = "n", loc = "n", wk = "n", tod = "n", seas = "n"), Q = 2, iterlim = 500) summary(Elec.mm) ## End(Not run)
## Examples using the Fishing data set from the AER package data("TravelMode", package = "AER") library(mlogit) TM <- mlogit.data(TravelMode, choice = "choice", shape = "long", alt.levels = c("air", "train", "bus", "car"), chid.var = "individual") ## Not run: ## S-MNL model, ASCs not scaled smnl <- gmnl(choice ~ wait + vcost + travel + gcost| 1, data = TM, model = "smnl", R = 100, notscale = c(1, 1, 1, rep(0, 4))) summary(smnl) ## MIXL model with observed heterogeneity mixl.hier <- gmnl(choice ~ vcost + gcost + travel + wait | 1 | 0 | income + size - 1, data = TM, model = "mixl", ranp = c(travel = "t", wait = "n"), mvar = list(travel = c("income","size"), wait = c("income")), R = 30, haltons = list("primes"= c(2, 17), "drop" = rep(19, 2))) summary(mixl.hier) ## Examples using the Electricity data set from the mlogit package data("Electricity", package = "mlogit") Electr <- mlogit.data(Electricity, id.var = "id", choice = "choice", varying = 3:26, shape = "wide", sep = "") ## Estimate a MIXL model with correlated random parameters Elec.cor <- gmnl(choice ~ pf + cl + loc + wk + tod + seas| 0, data = Electr, subset = 1:3000, model = 'mixl', R = 10, panel = TRUE, ranp = c(cl = "n", loc = "n", wk = "n", tod = "n", seas = "n"), correlation = TRUE) summary(Elec.cor) cov.gmnl(Elec.cor) se.cov.gmnl(Elec.cor) se.cov.gmnl(Elec.cor, sd = TRUE) cor.gmnl(Elec.cor) ## Estimate a G-MNL model, where ASCs are also random Electr$asc2 <- as.numeric(Electr$alt == 2) Electr$asc3 <- as.numeric(Electr$alt == 3) Electr$asc4 <- as.numeric(Electr$alt == 4) Elec.gmnl <- gmnl(choice ~ pf + cl + loc + wk + tod + seas + asc2 + asc3 + asc4 | 0, data = Electr, subset = 1:3000, model = 'gmnl', R = 30, panel = TRUE, notscale = c(rep(0, 6), 1, 1, 1), ranp = c(cl = "n", loc = "n", wk = "n", tod = "n", seas = "n", asc2 = "n", asc3 = "n", asc4 = "n")) summary(Elec.gmnl) ## Estimate a LC model with 2 classes Elec.lc <- gmnl(choice ~ pf + cl + loc + wk + tod + seas| 0 | 0 | 0 | 1, data = Electr, subset = 1:3000, model = 'lc', panel = TRUE, Q = 2) summary(Elec.lc) ## Estimate a MM-MIXL model Elec.mm <- gmnl(choice ~ pf + cl + loc + wk + tod + seas| 0 | 0 | 0 | 1, data = Electr, subset = 1:3000, model = 'mm', R = 30, panel = TRUE, ranp = c(pf = "n", cl = "n", loc = "n", wk = "n", tod = "n", seas = "n"), Q = 2, iterlim = 500) summary(Elec.mm) ## End(Not run)
Methods for gmnl
objects which provide a plot of the distribution of the conditional expectation of the random parameters or the distribution of the conditional willigness-to-pay.
## S3 method for class 'gmnl' plot( x, par = NULL, effect = c("ce", "wtp"), wrt = NULL, type = c("density", "histogram"), adjust = 1, main = NULL, col = "indianred1", breaks = 10, ylab = NULL, xlab = NULL, ind = FALSE, id = NULL, ... )
## S3 method for class 'gmnl' plot( x, par = NULL, effect = c("ce", "wtp"), wrt = NULL, type = c("density", "histogram"), adjust = 1, main = NULL, col = "indianred1", breaks = 10, ylab = NULL, xlab = NULL, ind = FALSE, id = NULL, ... )
x |
an object of class |
par |
a string giving the name of the variable with random parameter. |
effect |
a string indicating whether the conditional expectation, " |
wrt |
a string indicating with respect to which variable the WTP should be computed if |
type |
a string indicating the type of distribution: it can be a |
adjust |
bandwidth for the kernel density. |
main |
an overall title for the plot. |
col |
color for the graph. |
breaks |
number of breaks for the histrogram if |
ylab |
a title for the y axis. |
xlab |
a title for the x axis. |
ind |
a boolean. If |
id |
only relevant if |
... |
further arguments to be passed to |
Mauricio Sarrias
Greene, W. H. (2012). Econometric Analysis, Seventh Edition. Pearson Hall.
Train, K. (2009). Discrete Choice Methods with Simulation. Cambridge University Press.
gmnl
for the estimation of different multinomial models with individual heterogeneity and effect.gmnl
.
## Not run: ## Examples using the Electricity data set from the mlogit package library(mlogit) data("Electricity", package = "mlogit") Electr <- mlogit.data(Electricity, id.var = "id", choice = "choice", varying = 3:26, shape = "wide", sep = "") ## Estimate a MIXL model with correlated random parameters Elec.cor <- gmnl(choice ~ pf + cl + loc + wk + tod + seas| 0, data = Electr, subset = 1:3000, model = 'mixl', R = 10, panel = TRUE, ranp = c(cl = "n", loc = "n", wk = "n", tod = "n", seas = "n"), correlation = TRUE) ## Plot the density of the conditional expectation distribution of loc plot(Elec.cor, par = "loc", effect = "ce", type = "density", col = "grey") ## Plot the conditional expectation of loc for each individual plot(Elec.cor, par = "loc", effect = "ce", ind = TRUE, id = 1:30) ## Plot the WTP for cl plot(Elec.cor, par = "loc", effect = "wtp", wrt = "pf") ## End(Not run)
## Not run: ## Examples using the Electricity data set from the mlogit package library(mlogit) data("Electricity", package = "mlogit") Electr <- mlogit.data(Electricity, id.var = "id", choice = "choice", varying = 3:26, shape = "wide", sep = "") ## Estimate a MIXL model with correlated random parameters Elec.cor <- gmnl(choice ~ pf + cl + loc + wk + tod + seas| 0, data = Electr, subset = 1:3000, model = 'mixl', R = 10, panel = TRUE, ranp = c(cl = "n", loc = "n", wk = "n", tod = "n", seas = "n"), correlation = TRUE) ## Plot the density of the conditional expectation distribution of loc plot(Elec.cor, par = "loc", effect = "ce", type = "density", col = "grey") ## Plot the conditional expectation of loc for each individual plot(Elec.cor, par = "loc", effect = "ce", ind = TRUE, id = 1:30) ## Plot the WTP for cl plot(Elec.cor, par = "loc", effect = "wtp", wrt = "pf") ## End(Not run)
The vcov
method for gmnl
objects extracts the covariance matrix of the coefficients or the random parameters. It also allows to get the standard errors for the variance-covariance matrix of the random parameters
## S3 method for class 'gmnl' vcov( object, what = c("coefficient", "ranp"), type = c("cov", "cor", "sd"), se = FALSE, Q = NULL, digits = max(3, getOption("digits") - 2), ... )
## S3 method for class 'gmnl' vcov( object, what = c("coefficient", "ranp"), type = c("cov", "cor", "sd"), se = FALSE, Q = NULL, digits = max(3, getOption("digits") - 2), ... )
object |
a fitted model of class |
what |
indicates which covariance matrix has to be extracted. The default is |
type |
if the model is estimated with random parameters, then this argument indicates what matrix should be returned. If |
se |
if |
Q |
this argument is only valid if the " |
digits |
number of digits, |
... |
further arguments |
This new interface replaces the cor.gmnl
, cov.gmnl
and se.cov.gmnl
functions which are deprecated.
gmnl
for the estimation of multinomial logit models with random parameters.
Compute the willingness-to-pay.
wtp.gmnl(object, wrt = NULL, digits = max(3, getOption("digits") - 2))
wtp.gmnl(object, wrt = NULL, digits = max(3, getOption("digits") - 2))
object |
an object of class |
wrt |
a string indicating the variable with respect to which the WTP is computed, |
digits |
number of significant digits to be used for most numbers. |
For each coefficient, this function computes both the point estimate and standard error of WTP with respect to the variable specified in the argument wrt
. Specifically, let be the coefficient for variable
, then
where is the coefficient for the variable specified with the argument
wrt
. Note that, wtp.gmnl
does not include the negative sign.
wtp.gmnl
function is a wrapper for the deltamethod
function of the msm package.
A coefficient matrix with the WTP point estimates and standard errors.
Mauricio Sarrias.
Greene, W. H. (2012). Econometric Analysis, Seventh Edition. Pearson Hall.
Train, K. (2009). Discrete Choice Methods with Simulation. Cambridge University Press.
deltamethod
for the estimation of the standard errors.
## Examples using the Electricity data set from the mlogit package library(mlogit) data("Electricity", package = "mlogit") Electr <- mlogit.data(Electricity, id.var = "id", choice = "choice", varying = 3:26, shape = "wide", sep = "") ## Estimate a conditional logit model clogit <- gmnl(choice ~ pf + cl + loc + wk + tod + seas| 0, data = Electr) wtp.gmnl(clogit, wrt = "pf")
## Examples using the Electricity data set from the mlogit package library(mlogit) data("Electricity", package = "mlogit") Electr <- mlogit.data(Electricity, id.var = "id", choice = "choice", varying = 3:26, shape = "wide", sep = "") ## Estimate a conditional logit model clogit <- gmnl(choice ~ pf + cl + loc + wk + tod + seas| 0, data = Electr) wtp.gmnl(clogit, wrt = "pf")