Title: | Some extras for the mlogit package |
---|---|
Description: | Some extras for the mlogit package. I started this package because I could not make the predict function in mlogit robustly work without errors for mixed logit models. The function ml_predict can be used as a replacment (but still only works for a subset of random parameter specifications.) |
Authors: | Sebastian Kranz |
Maintainer: | Sebastian Kranz <[email protected]> |
License: | GPL >= 2.0 |
Version: | 0.1.0 |
Built: | 2024-12-22 02:46:26 UTC |
Source: | https://github.com/skranz/mlogitExtras |
Density function of triangular distribution
dtri(x, min = 0, max = 1)
dtri(x, min = 0, max = 1)
Extract Cholesky decomposition matrix of correlated random variables of an mlogit model
ml_chol(mod)
ml_chol(mod)
Note that the function is still restricted and does not yet work for all sorts of random parameter distributions that mlogit supports.
ml_draw_betas(mod, num.draws = 100, use.halton = FALSE, scale = NA)
ml_draw_betas(mod, num.draws = 100, use.halton = FALSE, scale = NA)
mod |
the estimated models |
num.draws |
the number of individuals for which random coefficients shall be drawn |
use.halton |
shall Halton sequences be used instead of psedudo-random numbers? |
A matrix with num.draws rows and one column for each explanatory variable that has random coefficients
Currently only works for models without alternative specific constants or alternative specific interaction effects.
ml_predict(mod, newdata, num.draws = 1000, use.halton = TRUE)
ml_predict(mod, newdata, num.draws = 1000, use.halton = TRUE)
mod |
An estimated mlogit model |
newdata |
A data set for the prediction in long format. The data set should have a column alt the indexed the alternative. The data set must be ordered first by choice situation and each choice situation must have the same number of alternatives in the same order. You may simply add a column chid specifying choice situation then arrange by chid, alt. |
num.draws |
Number of simulated consumers to compute market shares (relevant for mixed logit models only) |
use.halton |
Should Halton sequences instead of pseudo-random numbers be used to simulate consumers (default TRUE) |
A matrix of predicted choice probabilities with one row per choice situation and one column for each alternative. Each row sums up to 1.
Get tidy output of estimated coefficients of mlogit model as data frame
ml_tidy(mod, scale = NA)
ml_tidy(mod, scale = NA)
mod |
the estimated model |
scale |
A numeric value or variable name used to scale coefficients and standard errors. Typical application would be a "price" variable if you estimated a product choice. Then utilities can be interpreted as willingness to pay. |
Quantile function of triangular distribution
qtri(p, min = 0, max = 1)
qtri(p, min = 0, max = 1)
Helper function to show changes in choice probabilities / market shares
show_P_changes(org, new, digits = 1)
show_P_changes(org, new, digits = 1)