Science Score: 33.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
○codemeta.json file
-
○.zenodo.json file
-
✓DOI references
Found 3 DOI reference(s) in README -
✓Academic publication links
Links to: sciencedirect.com, springer.com -
✓Committers with academic emails
1 of 4 committers (25.0%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (15.3%) to scientific vocabulary
Last synced: 10 months ago
·
JSON representation
Repository
Implement MDCEV model in R using Stan
Basic Info
Statistics
- Stars: 10
- Watchers: 2
- Forks: 4
- Open Issues: 0
- Releases: 0
Created over 7 years ago
· Last pushed over 2 years ago
Metadata Files
Readme
License
README.Rmd
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# Kuhn-Tucker and Multiple Discrete-Continuous Extreme Value (MDCEV) Model Estimation and Simulation in R: The rmdcev Package
[](https://github.com/plloydsmith/rmdcev/actions)
[](https://github.com/plloydsmith/rmdcev/actions/workflows/R-CMD-check.yaml)
The **rmdcev** R package estimate and simulates Kuhn-Tucker demand models with individual heterogeneity. The models supported by **rmdcev** are the multiple-discrete continuous extreme value (MDCEV) model and Kuhn-Tucker specification common in the environmental economics literature on recreation demand. Latent class and random parameters specifications can be implemented and the models are fit using maximum likelihood estimation or Bayesian estimation. All models are implemented in Stan, which is a C++ package for performing full Bayesian inference (see https://mc-stan.org/). The **rmdcev** package also implements demand forecasting and welfare calculation for policy simulation.
## Current Status
Development is in progress. Currently users can estimate the following models:
1. Bhat (2008) MDCEV model specifications
2. Kuhn-Tucker model specification in environmental economics (von Haefen and Phaneuf, 2005)
Models can be estimated using
1. Fixed parameter models (maximum likelihood or Bayesian estimation)
2. Latent class models (maximum likelihood estimation)
3. Random parameters models (Bayesian estimation)
## Installation
I recommend you first install **rstan** by following these steps:
https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started
Once **rstan** is installed, you can install **rmdcev** from CRAN using
``` r
install.packages("rmdcev")
```
Or install the latest version of **rmdcev** from GitHub using devtools
``` r
if (!require(devtools)) {
install.packages("devtools")
library(devtools)
}
install_github("plloydsmith/rmdcev", dependencies = TRUE, INSTALL_opts="--no-multiarch")
```
If you have any issues with installation or use of the package, please let me know by [filing an issue](https://github.com/plloydsmith/rmdcev/issues).
## References
Background on the models, estimation, and simulation as well as a walk through of the package is provided in
Lloyd-Smith, P (2021). ["Kuhn-Tucker and Multiple Discrete-Continuous Extreme Value Model Estimation and Simulation in R: The rmdcev Package"](https://doi.org/10.32614/RJ-2021-015) The R Journal, 12(2): 251-265.
For more details on the model specification and estimation:
Bhat, C.R. (2008) ["The Multiple Discrete-Continuous Extreme Value (MDCEV) Model: Role of Utility Function Parameters, Identification Considerations, and Model Extensions"](https://www.sciencedirect.com/science/article/pii/S0191261507000677) Transportation Research Part B, 42(3): 274-303.
von Haefen, R. and Phaneuf D. (2005) ["Kuhn-Tucker Demand System Approaches to Non-Market Valuation"](https://link.springer.com/chapter/10.1007/1-4020-3684-1_8) In: Scarpa R., Alberini A. (eds) Applications of Simulation Methods in Environmental and Resource Economics. The Economics of Non-Market Goods and Resources, vol 6. Springer, Dordrecht.
For more details on the demand and welfare simulation:
Pinjari, A.R. and Bhat , C.R. (2011) ["Computationally Efficient Forecasting Procedures for Kuhn-Tucker Consumer Demand Model Systems: Application to Residential Energy Consumption Analysis."](https://www.caee.utexas.edu/prof/bhat/MDCEV_Forecasting.html) Technical paper, Department of Civil & Environmental Engineering, University of South Florida.
Lloyd-Smith, P (2018). ["A New Approach to Calculating Welfare Measures in Kuhn-Tucker Demand Models."](https://www.sciencedirect.com/science/article/pii/S1755534517300994) Journal of Choice Modeling, 26: 19-27
## Estimation
As an example, we can simulate some data using Bhat (2008)'s 'Gamma' specification. In this example, we are simulating data for 2,000 individuals and 10 non-numeraire alternatives. We will randomly generate the parameter values to simulate the data and then check these values to our estimation results.
```{r}
library(pacman)
p_load(tidyverse, rmdcev)
set.seed(12345)
model <- "gamma"
nobs <- 2000
nalts <- 10
sim.data <- GenerateMDCEVData(model = model, nobs = nobs, nalts = nalts)
```
Estimate model using MLE (note that we set "psi_ascs = 0" to omit any alternative-specific constants)
``` {r}
mdcev_est <- mdcev(~ b1 + b2 + b3 + b4 + b5 + b6,
data = sim.data$data,
psi_ascs = 0,
model = model,
algorithm = "MLE")
```
Summarize results
``` {r}
summary(mdcev_est)
```
Compare estimates to true values
``` {r}
coefs <- as_tibble(sim.data$parms_true) %>%
mutate(true = as.numeric(true)) %>%
cbind(summary(mdcev_est)[["CoefTable"]]) %>%
mutate(cl_lo = Estimate - 1.96 * Std.err,
cl_hi = Estimate + 1.96 * Std.err)
head(coefs, 200)
```
Compare outputs using a figure
```{r, warning = FALSE}
coefs %>%
ggplot(aes(y = Estimate, x = true)) +
geom_point(size=2) +
geom_text(label=coefs$parms,position=position_jitter(width=.5,height=1)) +
geom_abline(slope = 1) +
geom_errorbar(aes(ymin=cl_lo,ymax=cl_hi,width=0.2))
```
## Welfare simulation
Create policy simulations (these are 'no change' policies with no effects)
```{r}
npols <- 2 # Choose number of policies
policies <- CreateBlankPolicies(npols, mdcev_est)
df_sim <- PrepareSimulationData(mdcev_est, policies, nsims = 1)
```
Simulate welfare changes
```{r}
wtp <- mdcev.sim(df_sim$df_indiv,
df_common = df_sim$df_common,
sim_options = df_sim$sim_options,
cond_err = 1,
nerrs = 15,
sim_type = "welfare")
summary(wtp)
```
## Thanks
This package was not developed in isolation and I gratefully acknowledge Joshua Abbott, Allen Klaiber, Lusi Xie, the [apollo team](http://www.apollochoicemodelling.com/), and the Stan team, whose codes or suggestions were helpful in putting this package together.
Owner
- Name: Patrick Lloyd-Smith
- Login: plloydsmith
- Kind: user
- Website: https://plloydsmith.github.io
- Repositories: 2
- Profile: https://github.com/plloydsmith
Water and Resource Economist at the University of Saskatchewan
GitHub Events
Total
Last Year
Committers
Last synced: over 3 years ago
All Time
- Total Commits: 388
- Total Committers: 4
- Avg Commits per committer: 97.0
- Development Distribution Score (DDS): 0.023
Top Committers
| Name | Commits | |
|---|---|---|
| Patrick Lloyd-Smith | p****h@g****m | 379 |
| Andrew Johnson | a****n@a****m | 7 |
| Lloyd-Smith | p****3@u****a | 1 |
| Andrew Johnson | a****n@p****u | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: over 2 years ago
All Time
- Total issues: 4
- Total pull requests: 5
- Average time to close issues: 9 days
- Average time to close pull requests: 14 days
- Total issue authors: 2
- Total pull request authors: 2
- Average comments per issue: 3.25
- Average comments per pull request: 2.0
- Merged pull requests: 5
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 2
- Average time to close issues: N/A
- Average time to close pull requests: about 1 month
- Issue authors: 0
- Pull request authors: 1
- Average comments per issue: 0
- Average comments per pull request: 5.0
- Merged pull requests: 2
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- LusiXie (2)
- rawls238 (2)
Pull Request Authors
- andrjohns (3)
- plloydsmith (2)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
- Total downloads: unknown
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 7
- Total maintainers: 1
cran.r-project.org: rmdcev
Kuhn-Tucker and Multiple Discrete-Continuous Extreme Value Models
- Homepage: https://github.com/plloydsmith/rmdcev
- Documentation: http://cran.r-project.org/web/packages/rmdcev/rmdcev.pdf
- License: MIT + file LICENSE
- Status: removed
-
Latest release: 1.2.5
published over 3 years ago
Rankings
Forks count: 11.3%
Stargazers count: 17.9%
Dependent packages count: 29.8%
Average: 30.1%
Dependent repos count: 35.5%
Downloads: 56.1%
Maintainers (1)
Last synced:
over 2 years ago
Dependencies
DESCRIPTION
cran
- R >= 4.0.0 depends
- Rcpp >= 1.0.5 depends
- methods * depends
- Formula * imports
- RcppParallel >= 5.0.1 imports
- dplyr >= 0.7.8 imports
- purrr * imports
- rstan >= 2.21.0 imports
- rstantools >= 2.1.1 imports
- stats * imports
- tibble * imports
- tidyr * imports
- utils * imports
- knitr * suggests
- rmarkdown * suggests
- testthat * suggests