Description Usage Arguments Value References Examples
Drawing the coefficient plots from either model result or coefficient table.
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | plot_coef(
m,
m.names = NULL,
order.variable = "original",
odds = FALSE,
vcov.est = NULL,
robust.type = "HC1",
cluster.var = NULL,
boot.sims = 300,
boot.seed = 578,
boot.ncores = 1,
show.ci = TRUE,
level.ci = 0.95,
drop.intercept = FALSE,
drop.intercept.names = "(Intercept)",
drop.variable.names = NULL,
point.shape = 16,
point.size = 1.5,
point.color = "black",
ci.linetype = 1,
ci.size = 0.5,
ci.height = 0.2,
overlap.names = "m.names",
overlap.gapwidth = 0.5,
overlap.shape.index = NULL,
overlap.color.index = NULL,
overlap.linetype.index = NULL,
overlap.legend.position = "bottom",
category.names = NULL,
category.names.location = "left",
category.names.angle = 0,
facet.names = NULL,
facet.x.scale = "fixed",
title = NULL,
y.title = NULL,
custom.variable.names = NULL,
custom.x.title = NULL,
custom.x.lim = NULL,
custom.x.breaks = NULL,
custom.themes = NULL,
footnote.gof = FALSE,
footnote.gof.nobs = "right",
footnote.gof.extracts = c("AIC", "Adj. R$^2$", "Log Likelihood"),
footnote.gof.reorder = NULL,
footnote.gof.linebreak = TRUE,
custom.footnote = NULL,
footnote.caption = FALSE,
footnote.fontsize = NULL,
footnote.fontcol = "black",
footnote.align = "right",
footnote.distance.from.side = 0.05,
footnote.distance.from.bottom = 0.75,
footnote.bottom.expand.rate = NULL,
show.plot = TRUE,
flip.plot = FALSE,
...
)
|
m |
Single or the list of model object or the
|
m.names |
The set of names that identifies each element in |
order.variable |
Order of coefficients in the plot(character/numeric vector).
|
odds |
Use odds ratio instead of coefficient in the output (boulean).
The default is |
vcov.est |
Single or a list of alternative variance-covariance matrix.
Each element must be one of raw variance-covariance matrix, |
robust.type |
The type of leverage adjustment passed to |
cluster.var |
Single or a list of |
boot.sims |
Number of iterations if bootstrap is used. |
boot.seed |
Random number seed if bootstrap method is used. |
boot.ncores |
Number of cores to parallelize bootstrap. The default is |
show.ci |
Show confidence interval (boulean). The default is |
level.ci |
The level used for confidence interval (numeric: 0-1).
The default is |
drop.intercept |
Drop the intercept from the plot (boulean).
If |
drop.intercept.names |
The name(s) of intercept (character/character vector).
Needed if |
drop.variable.names |
The name(s) of additional variables to drop
(character/character vector) from the ouput. The default is |
point.shape |
Shape of the point outputs (numeric/character).
The default is |
point.size |
Size of point outputs (numeric). The default is |
point.color |
Color of point (and ci) outputs (numeric). The default is |
ci.linetype |
The line type of confidence interval outputs (numeric).
The default is |
ci.size |
The line width of confidence interval outputs (numeric).
The default is |
ci.height |
The height of the vertical line added to the edge of confidence
interval outputs. The default is |
overlap.names |
Model labels that controls overlapping
(applied only when there are two or more |
overlap.gapwidth |
The gap between overlapped ouputs (numeric).
The default value is |
overlap.shape.index |
The index of shapes for overlapped point ouputs.
Must be in the same length as the list |
overlap.color.index |
The index of colors for overlapped point ouputs.
Must be in the same length as the list |
overlap.linetype.index |
The index of line types for overlapped confidence interval
ouputs. Must be in the same length as the list |
overlap.legend.position |
The position of the legend for overlapping classess.
See |
category.names |
The categories of variables (factor).
If not |
category.names.location |
The location of category names. Either |
category.names.angle |
The angle of category names (numeric). The default is |
facet.names |
If not |
facet.x.scale |
If |
title |
Plot title (character). The default is to include no title. |
y.title |
Y axis title (character). The default is to include no axis title. |
custom.variable.names |
Set of alternative variable names in the output (character vector). The default is |
custom.x.title |
Custom name for the X axis title (character). The default is |
custom.x.lim |
Custom limit for the X axis. The default is |
custom.x.breaks |
Custom breaks for the X axis. The default is |
custom.themes |
ggplot themes that overrides the default theme. The default is |
footnote.gof |
Include GOF measures in the footnote (boulean). The default is |
footnote.gof.nobs |
The position of "number of observation (N)" to be printed. The default is |
footnote.gof.extracts |
GOF measures to be inluded if |
footnote.gof.reorder |
The numeric vector specifying the alternative order of GOF (e.g., if there are three GOFs, and you want to flip the order of first and second GOF, then input |
footnote.gof.linebreak |
Include linebreak between models (boulean). If |
custom.footnote |
Custom footnote (character). The default is |
footnote.caption |
Use caption option in ggplot2 to add footnote. If |
footnote.fontsize |
The size of font. If |
footnote.fontcol |
The color of the font. The default is |
footnote.align |
The alignment of the footnote text. Either |
footnote.distance.from.side |
The horizontal distance of notes from the edge of graph space by the proportion of graph width (numeric: 0-1). The default is |
footnote.distance.from.bottom |
The vertical distance of notes from the bottom of graph bottom by the proportion of bottom graph margin height (numeric: 0-1). The default is |
footnote.bottom.expand.rate |
The expansion rate of the bottom margin of the graph to incorporate footnote (numeric). The value of |
show.plot |
Print the plot at the end of function (boulean). The default is |
flip.plot |
Flip the x and y axis of the plot. The default is |
... |
Additional arguments passed to |
ggplot
object without footnote (axis and theme settings can be added later). If footnote is added, then gtable
object is the output. It is impossible to add ggplot
elements to the gtable
object. gtable
plot can be viewed by using either grid.draw()
or plot()
function.
http://www.surefoss.org/dataanalysis/plotting-odds-ratios-aka-a-forrestplot-with-ggplot2/ is where my initial idea come from.
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | ## Load Data
library(pscl)
data(vote92)
## Recode Variables
vote92$voteBush <- as.numeric(
factor(vote92$vote,levels=c("Clinton","Bush")))*1 - 1
vote92$bushdis <- sqrt(vote92$bushdis)
vote92$clintondis <- sqrt(vote92$clintondis)
## Estimate Logistic Regression
fm <- formula(voteBush ~ dem + rep +
clintondis + bushdis +
persfinance + natlecon)
m <- glm(fm, data = vote92,
family = binomial("logit"))
## Basic Graph
plot_coef(m)
## Change X-axis to Odds Ratio
plot_coef(m, odds = TRUE)
## Export the Coefficients Table First, and import directly
cfci <- data.frame(cbind(coef(m), confint(m, level = 0.95)))
plot_coef(cfci)
## Estimate Model by Male and Female Subset
m_male <- glm(fm, data = vote92[vote92$female==0,],
family = binomial("logit"))
m_female <- glm(fm, data = vote92[vote92$female==1,],
family = binomial("logit"))
## Overlap Subsetted Results
plot_coef(list(m_male, m_female),
m.names = c("Male", "Female"))
## Add Title and Custom Variable Names
vn <- c("(Intercept)",
"Democrat","Republican",
"Ideological Distance from Clinton",
"Ideological Distance from Bush",
"Retrospective Personal Finance",
"Retrospective National Economy")
plot_coef(list(m_male, m_female),
m.names = c("Male", "Female"),
title = "Vote for Bush (1992)",
custom.variable.names = vn)
## Overlap the Third Model & Facet Variables by Category & Add GOF Footnote
fn <- c("Constant",rep("Preference",4),rep("Evaluation",2))
fn <- factor(fn,levels=unique(fn))
plot_coef(list(m_male, m_female, m),
m.names = c("Male", "Female", "All"),
category.names = fn,
title = "Vote for Bush (1992)",
custom.variable.names = vn,
footnote.gof = TRUE)
## Further Adding Facets
plot_coef(list(m_male, m_female, m),
m.names = c("Male", "Female", "ALL"),
overlap.linetype.index = c(1,2,1),
category.names = fn,
facet.names = c("Gender Subsets","Gender Subsets","All"),
title = "Vote for Bush (1992)",
custom.variable.names = vn,
footnote.gof = TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.