Skip to content

Instantly share code, notes, and snippets.

@chrismeserole
Created April 14, 2015 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismeserole/3817d693153c5c688fb9 to your computer and use it in GitHub Desktop.
Save chrismeserole/3817d693153c5c688fb9 to your computer and use it in GitHub Desktop.
# install devtools & obsval
install.packages("devtools")
library("devtools")
devtools::install_github("chrismeserole/obsval")
library("obsval")
# install secondary packages
install.packages("mvtnorm")
install.packages("nnet")
library(mvtnorm)
library(nnet)
# specify parameters
data <- studentVote
specification <- 'warsup~female'
reg_model <- "mlogit"
n_draws <- 1000
effect_var <- 'female'
effect_var_high <- 1
effect_var_low <- 0
verbose <- TRUE
baseline_category <- "strongly oppose"
# run the model and calculate predicted probabilities
mymodel <- obsval( data, specification, reg_model, n_draws,
effect_var, effect_var_high, effect_var_low,
verbose, baseline_category )
# get results
mean(mymodel$pp_effect[,'strongly oppose'])
quantile(mymodel$pp_effect[,'strongly oppose'], c(0.025, 0.975))
# visualize results
plot(mymodel$pp_effect[,'strongly oppose'])
boxplot(mymodel$pp_effect[,'strongly oppose'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment