Last data update: 2014.03.03

R: An 'xtable' method for 'xbal' objects
xtable.xbalR Documentation

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.

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(".", <ncols>)), where <ncols> 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.

Value

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

Examples

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

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(RItools)
Loading required package: SparseM

Attaching package: 'SparseM'

The following object is masked from 'package:base':

    backsolve

> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/RItools/xtable.xbal.Rd_%03d_medium.png", width=480, height=480)
> ### Name: xtable.xbal
> ### Title: An 'xtable' method for 'xbal' objects
> ### Aliases: xtable.xbal
> 
> ### ** Examples
> 
> data(nuclearplants)
> require(xtable)
Loading required package: 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")
% latex table generated in R 3.3.1 by xtable 1.8-2 package
% Mon Jul  4 23:07:04 2016
egin{sidewaystable}[ht]
centering
egin{tabular}{lrrrrrrrrrrrr}
  hline multicolumn{1}{r}{Strata:} &   multicolumn{ 6 }{c}{ unstrat } &   multicolumn{ 6 }{c}{ pt }  \ cline{2-7} cline{8-13} & pr=0 & pr=1 & adj.diff & std.diff & z &  & pr=0 & pr=1 & adj.diff & std.diff & z &  \ 
  hline
Date & 68.62 & 68.50 & -0.12 & -0.11 & -0.31 &     & 68.49 & 68.59 & 0.10 & 0.10 & 0.29 &     \ 
  Application to Contruction Time & 13.64 & 14.00 & 0.36 & 0.11 & 0.28 &     & 13.40 & 14.35 & 0.95 & 0.28 & 0.79 &     \ 
  License to Construction Time & 59.32 & 69.10 & 9.78 & 1.03 & 2.47 & *   & 59.18 & 68.55 & 9.37 & 0.99 & 2.31 & *   \ 
  Net Capacity & 805.18 & 869.80 & 64.62 & 0.34 & 0.89 &     & 806.45 & 873.02 & 66.57 & 0.35 & 0.92 &     \ 
  Northeast Region & 0.27 & 0.20 & -0.07 & -0.16 & -0.43 &     & 0.24 & 0.22 & -0.02 & -0.05 & -0.14 &     \ 
  Cooling Tower & 0.45 & 0.30 & -0.15 & -0.31 & -0.81 &     & 0.44 & 0.33 & -0.11 & -0.22 & -0.58 &     \ 
  Babcock-Wilcox Steam & 0.18 & 0.20 & 0.02 & 0.05 & 0.12 &     & 0.20 & 0.15 & -0.05 & -0.12 & -0.31 &     \ 
  Cumlative Plants & 8.73 & 8.10 & -0.63 & -0.10 & -0.26 &     & 8.72 & 7.90 & -0.82 & -0.13 & -0.34 &     \ 
   hline
end{tabular}
end{sidewaystable}
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>