Learn R Programming

RItools (version 0.1-13)

xtable.xbal: An xtable method for xbal objects

Description

This function uses the xtable package framework to display the results of a call to xBalance in LaTeX format. At the moment, it ignores the omnibus chi-squared test information.

Usage

## S3 method for class 'xbal':
xtable(x, caption = NULL, label = NULL, align = c("l",
  rep("r", ncol(xvardf))), digits = 2, display = NULL, col.labels = NULL,
  ...)

Arguments

x
An object resulting from a call to xBalance.
caption
See xtable.
label
See xtable.
align
See xtable. Our default (as of version 0.1-7) is right-aligned columns; for decimal aligned columns, see details, below.
digits
See xtable. Default is 2.
display
See xtable.
col.labels
Labels for the columns (the test statistics). Default are come from the call to print.xbal.
...
Other arguments to print.xbal.

Value

  • This function produces an xtable object which can then be printed with the appropriate print method (see print.xtable).

Details

The resulting LaTeX will present one row for each variable in the formula originally passed to xBalance, using the variable name used in the original formula. If you wish to have reader friendly labels instead of the original variables names, see the code examples below.

To get decimal aligned columns, specify align=c("l", rep(".", )), where is the number of columns to be printed, in your call to xtable. Then use the dcolumn package and define '.' within LaTeX: add the lines \usepackage{dcolumn} and \newcolumntype{.}{D{.}{.}{2.2}} to your LaTeX document's preamble.

Examples

Run this code
data(nuclearplants)
require(xtable)

# Test balance on a variety of variables, with the 'pr' factor
# indicating which sites are control and treatment units, with
# stratification by the 'pt' factor to group similar sites
xb1 <- xBalance(pr ~ date + t1 + t2 + cap + ne + ct + bw + cum.n,
                strata = data.frame(unstrat = factor(character(32)),
                pt = factor(nuclearplants$pt)),
                data = nuclearplants,
                report = c('adj.means', 'adj.mean.diffs',
                           'std.diffs', 'z.scores',
                           'chisquare.test', 'p.values'))

xb1.xtab <- xtable(xb1) # This table has right aligned columns

# Add user friendly names in the final table
rownames(xb1.xtab) <- c("Date", "Application to Contruction Time",
"License to Construction Time", "Net Capacity", "Northeast Region", "Cooling Tower",
"Babcock-Wilcox Steam", "Cumlative Plants")

print(xb1.xtab,
      add.to.row = attr(xb1.xtab, "latex.add.to.row"),
      hline.after = c(0, nrow(xb1.xtab)),
      sanitize.text.function = function(x){x},
      floating = TRUE,
      floating.environment = "sidewaystable")

Run the code above in your browser using DataLab