table_coef: Plotting Coefficients

Description Usage Arguments Value Examples

View source: R/table_coef.R

Description

Drawing the coefficient table from model object(s). The wrapper function of texreg.

Usage

 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
table_coef(
  m,
  format = "screen",
  file.name = NULL,
  dir = NULL,
  m.names = NULL,
  order.variable = "original",
  vcov.est = NULL,
  robust.type = "HC1",
  cluster.var = NULL,
  boot.sims = 300,
  boot.seed = 578,
  boot.ncores = 1,
  digits = 3,
  drop.intercept = FALSE,
  drop.intercept.names = "(Intercept)",
  drop.variable.names = NULL,
  caption = NULL,
  custom.variable.names = NULL,
  footnote.psymbol = TRUE,
  custom.footnote = NULL,
  show.table = TRUE,
  booktabs = TRUE,
  dcolumn = FALSE,
  use.packages = FALSE,
  stars = c(0.001, 0.01, 0.05, 0.1),
  symbol = "dagger",
  caption.above = TRUE,
  single.row = FALSE,
  float.pos = "ht!!",
  fontsize = "footnotesize",
  encoding_from = NULL,
  encoding_to = NULL,
  include.deviance = FALSE,
  include.smooth = FALSE,
  ...
)

Arguments

m

Single or the list of model object.

format

The format for the table output (characater). The default is "screen" (The R Output. Cannot be saved.). Other options are "tex" (LaTex table), "html" (HTML table) and "doc" (HTML table saved as Microsof Word file).

file.name

The name of the file to be saved (character). The default is NULL (The output not saved to file). If extension is provided, it will automatically overwrite format.

dir

The directory of the file to be saved. Only applicable when file.name is not NULL.

m.names

The set of names that identifies each element in m. Considered if m is a list of models. The length of the vector must correspond with the length of m. If NULL (default), each element i is temporarily named as Model i.

order.variable

Order of coefficients in the plot(character/numeric vector). "original" (default) preserves the original order of the variables. Alternatively, you can specify the order of variables by numeric vector (applied after drop.intercept and drop.variable.names are applied, thus you don't need the names for dropped variables).

vcov.est

Single or a list of alternative variance-covariance matrix. Each element must be one of raw variance-covariance matrix, "robust", "boot", or NULL (default). If "robust", robust standard error (also see robust.type). If "cluster", cluster robust standard error (also see cluster.var). if "boot", bootstrapped standard error calculated by Boot function is used. Ignored if NULL (default) or the m is not model object. Must have the same length as m if it is a list.

robust.type

The type of robust standard error (applied only when vcov.est=="robust").

cluster.var

Single or a list of vector, matrix, or data.frame of cluster variables, where each column is a separate variable. Alternatively, a formula specifying the cluster variables to be used (see details in cluster.vcov. Applied only when vcov.est=="cluster".)

boot.sims

Number of iterations if bootstrap is used.

boot.seed

Random number seed if bootstrap is used.

boot.ncores

Number of cores to parallelize bootstrap. The default is 1. Use "auto" to automatically detect number of cores in computer.

digits

Rounding decimal points for values in the table.

drop.intercept

Drop the intercept from the plot (boulean). If FALSE (default), intercept included in the plot.

drop.intercept.names

The name(s) of intercept (character/character vector). Needed if drop.intercept is TRUE. This is used to identify and eliminate intercept variables from the output. Default value is '(Intercept)'.

drop.variable.names

The name(s) of additional variables to drop (character/character vector) from the ouput. The default is NULL.

caption

Table title caption (character). The default is to include no title caption. (Not applied if format=="screen")

custom.variable.names

List of alternative variable names in the output (character vector). The default is NULL. This is applied AFTER drop.intercept and drop.variable.names are applied, thus you don't need the names for dropped variables.

footnote.psymbol

Whether to add p-value symbols in the footnote.

custom.footnote

Custom footnote (character). The default is NULL. If assigned, footnote are added to the plot by plot_footnote function, and the function exports gtable object. Note that gtable object is less customizable than ggplot object. If it is also the case that footnote.gof == TRUE, custom footnote will be added as the new line after the GOF footnote.

show.table

Return the "screen" table at the end of function (boulean). Always returned if format=="screen". The default is TRUE.

booktabs

See texreg.

dcolumn

See texreg.

use.packages

See texreg.

stars

See texreg.

symbol

See texreg.

caption.above

See texreg.

single.row

See texreg.

float.pos

See texreg.

fontsize

See texreg.

encoding_from

If encoding conversion is required, what is the orignal encoding? (Only used when format=="tex".)

encoding_to

If encoding conversion is required, what is the encoding to be coverted to? (Only used when format=="tex".)

include.deviance

See extract.

include.smooth

See extract.

...

Other options in texreg or extract function.

Value

Regression table to be shown in console if format=="screen" or show.table==TRUE, NULL if else.

Examples

 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
 
## 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)

vote92$w <- abs(rnorm(nrow(vote92)))

## Estimate Logistic Regression
fm <- formula(voteBush ~ dem + rep +
               clintondis + bushdis +
               persfinance + natlecon)
m <- glm(fm, data = na.omit(vote92[,c(all.vars(fm),"w","perotdis")]),
         family = binomial("logit"), weights=w)

## Basic Table
table_coef(m)

## Export in Tex
table_coef(m, format = "tex")

## Show in Single Row
table_coef(m, single.row = TRUE)

## Try Different Standard Errors
table_coef(list(m,m,m,m), 
           m.names = c("Standard","Robust(HC1)","Cluster Robust","Bootstrapped"),
           vcov.est = list(NULL,"robust","cluster","boot"),
           cluster.var = na.omit(vote92[,c(all.vars(fm),"w","perotdis")])$perotdis)

## 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"))

## Table with Two Models
table_coef(list(m_male,m_female))

## Add Custom Variable Names
vn <- c("(Intercept)",
        "Democrat","Republican",
        "Ideological Distance from Clinton",
        "Ideological Distance from Bush",
        "Retrospective Personal Finance",
        "Retrospective National Economy")
table_coef(list(m_male, m_female), 
           m.names = c("Male", "Female"),
           custom.variable.names = vn)

## Add Title (Only Tex/HTML)
table_coef(list(m_male, m_female), format="tex",
           m.names = c("Male", "Female"),
           caption = "Vote for Bush (1992)",
           custom.variable.names = vn)

## Omit Some Variables
table_coef(list(m_male, m_female), 
           m.names = c("Male", "Female"),
           drop.variable.names = c("dem","natlecon"),
           custom.variable.names = vn[-c(2,7)])

## Reorder Variables So That Intercept Comes at the end
table_coef(list(m_male, m_female), 
           m.names = c("Male", "Female"),
           drop.variable.names = c("dem","natlecon"),
           order.variable = c(5, seq(1,4,1)),
           custom.variable.names = vn[-c(2,7)])


## Interaction Model
fm2 <- formula(voteBush ~ dem + rep +
                 clintondis + bushdis +
                 persfinance + natlecon + 
                 dem*clintondis)
m2 <- glm(fm2, data = vote92,
          family = binomial("logit"), weights=w)
table_coef(list(m,m2), 
           custom.variable.names = c(vn,"Democrat * Distance from Clinton"),
           order.variable=c(1,2,4,5,6,7,8,3))

gentok/estvis documentation built on April 2, 2020, 1:58 p.m.