Description Usage Arguments Value Source Examples
Simulate and plot quantities of interest from generalised linear models
1  sim_glm(obj, newdata, x_coef, group_coef, n = 1000, model = "lm", col_pal)

obj 
fitted model object from 
newdata 
data frame with fitted values for finding the quantities of
interest. Column names must match coefficient names in 
x_coef 
character string naming the variable from 
group_coef 
optional character string specifying the values for the
coefficient in 
n 
numeric specifying the number of simulations to run. 
model 
character string or function specifying the type of estimation
model for the quantity of interest. Currently must be the string

col_pal 
character string specifying the plot's colour palette. 
A gg ggplot2 object with predicted quantities represented by the simulation highest 50, 90, and 95 probability intervals. The central line is the median of the simulation interval.
Note: for predicted probabilities from logistic regression models, predictions outside of [0, 1] are discarded and so not included in the median or highest probability density intveral calculations.
King, Gary, Michael Tomz, and Jason Wittenberg. 2000. "Making the Most of Statistical Analyses: Improving Interpretation and Presentation." American Journal of Political Science 44(2): 34155.
Christopher Gandrud (2015). simPH: An R Package for Illustrating Estimates from Cox Proportional Hazard Models Including for Interactive and Nonlinear Effects. Journal of Statistical Software, 65(3), 120. URL http://www.jstatsoft.org/v65/i03/.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29  # Normal Linear Model example
library(car) # Contains data
m1 < lm(prestige ~ education + type,
data = Prestige)
fitted_prestige < expand.grid(education = 6:16, typewc = 1)
sim_glm(obj = m1, newdata = fitted_prestige, x_coef = 'education', n = 50)
fitted_prestige < expand.grid(education = 6:16, typewc = 0:1)
sim_glm(obj = m1, newdata = fitted_prestige, x_coef = 'education',
group_coef = 'typewc', n = 50)
# Logistic Model example
URL < 'http://www.ats.ucla.edu/stat/data/binary.csv'
Admission < read.csv(URL)
Admission$rank < as.factor(Admission$rank)
m2 < glm(admit ~ gre + gpa + rank,
data = Admission, family = 'binomial')
fitted_admit_1 < with(Admission,
expand.grid(gre = seq(220, 800, by = 10),
gpa = mean(gpa),
rank2 = 0:1))
sim_glm(obj = m2, newdata = fitted_admit_1, x_coef = 'gre',
group_coef = 'rank2', model = 'logit', n = 50)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.