1 %\VignetteIndexEntry{xtable List of Tables Gallery}
\r
2 %\VignetteDepends{xtable, spdep, splm, sphet}
\r
3 %\VignetteKeywords{LaTeX, HTML, table}
\r
4 %\VignettePackage{xtable}
\r
6 % \VignetteEngine{knitr::knitr}
\r
7 %**************************************************************************
\r
8 \documentclass{article}
\r
9 \usepackage[a4paper, height=24cm]{geometry} % geometry first
\r
11 \usepackage{booktabs}
\r
12 \usepackage{longtable}
\r
13 \usepackage{parskip}
\r
14 \usepackage{rotating}
\r
15 \usepackage{tabularx}
\r
16 \usepackage{titlesec}
\r
17 \usepackage{hyperref} % hyperref last
\r
18 \titleformat\subsubsection{\bfseries\itshape}{}{0pt}{}
\r
19 \newcommand\p{\vspace{2ex}}
\r
20 \newcommand\code[1]{\texttt{#1}}
\r
21 \newcommand\pkg[1]{\textbf{#1}}
\r
22 \setcounter{tocdepth}{2}
\r
25 \title{\bfseries\Large The Other Packages Gallery}
\r
26 \author{\bfseries David J. Scott}
\r
33 \section{Introduction}
\r
34 This document represents a test of the functions in \pkg{xtable} which
\r
35 deal with other packages.
\r
37 <<set, include=FALSE>>=
\r
39 opts_chunk$set(fig.path = 'Figures/other', debug = TRUE, echo = TRUE)
\r
40 opts_chunk$set(out.width = '0.9\\textwidth')
\r
43 The first step is to load the package and set some options for this document.
\r
44 <<package, results='asis'>>=
\r
46 options(xtable.floating = FALSE)
\r
47 options(xtable.timestamp = "")
\r
52 \section{The packages \pkg{spdep}, \pkg{splm}, and \pkg{sphet}}
\r
54 Code for supporting these packages and most of the examples used in
\r
55 this section was originally provided by Martin Gubri
\r
56 (\url{martin.gubri@framasoft.org}).
\r
58 \subsection{The package \pkg{spdep}}
\r
59 \label{sec:package-pkgspdep}
\r
61 First load the package and create some objects.
\r
64 data("oldcol", package = "spdep")
\r
65 COL.lag.eig <- lagsarlm(CRIME ~ INC + HOVAL, data = COL.OLD[],
\r
68 COL.errW.GM <- GMerrorsar(CRIME ~ INC + HOVAL, data = COL.OLD,
\r
69 nb2listw(COL.nb, style = "W"),
\r
72 COL.lag.stsls <- stsls(CRIME ~ INC + HOVAL, data = COL.OLD,
\r
74 class(COL.lag.stsls)
\r
76 p1 <- predict(COL.lag.eig, newdata = COL.OLD[45:49,],
\r
77 listw = nb2listw(COL.nb))
\r
79 p2 <- predict(COL.lag.eig, newdata = COL.OLD[45:49,],
\r
80 pred.type = "trend", type = "trend")
\r
81 #type option for retrocompatibility with spdep 0.5-92
\r
84 imp.exact <- impacts(COL.lag.eig, listw = nb2listw(COL.nb))
\r
86 imp.sim <- impacts(COL.lag.eig, listw = nb2listw(COL.nb), R = 200)
\r
91 \subsubsection{\code{sarlm} objects}
\r
92 \label{sec:codesarlm-objects}
\r
94 There is an \code{xtable} method for objects of this type.
\r
95 <<xtablesarlm, results = 'asis'>>=
\r
99 The method for \code{xtable} actually uses the summary of the object,
\r
100 and an identical result is obtained when using the summary of the
\r
101 object, even if the summary contains more additional information.
\r
103 <<xtablesarlmsumm, results = 'asis'>>=
\r
104 xtable(summary(COL.lag.eig, correlation = TRUE))
\r
107 This same pattern applies to the other objects from this group of packages.
\r
109 Note that additional prettying of the resulting table is possible, as
\r
110 for any table produced using \code{xtable}. For example using the
\r
111 \pkg{booktabs} package we get:
\r
113 <<xtablesarlmbooktabs, results = 'asis'>>=
\r
114 print(xtable(COL.lag.eig), booktabs = TRUE)
\r
117 \subsubsection{\code{gmsar} objects}
\r
118 \label{sec:codegmsar-objects}
\r
121 <<xtablegmsar, results = 'asis'>>=
\r
122 xtable(COL.errW.GM)
\r
125 \subsubsection{\code{stsls} objects}
\r
126 \label{sec:codestsls-objects}
\r
129 <<xtablestsls, results = 'asis'>>=
\r
130 xtable(COL.lag.stsls)
\r
133 \subsubsection{\code{sarlm.pred} objects}
\r
134 \label{sec:codesarlmpred-objects}
\r
136 \code{xtable} has a method for predictions of \code{sarlm} models.
\r
138 <<xtablesarlmpred, results = 'asis'>>=
\r
142 This method transforms the \code{sarlm.pred} objects into data frames, allowing any number of attributes vectors which may vary according to predictor types.
\r
144 <<xtablesarlmpred2, results = 'asis'>>=
\r
148 \subsubsection{\code{lagImpact} objects}
\r
149 \label{sec:codelagimpact-objects}
\r
151 The \code{xtable} method returns the values of direct, indirect and total impacts for all the variables in the model. The class \code{lagImpact} have two different sets of attributes according to if simulations are used. But the \code{xtable} method always returns the three components of the non-simulation case.
\r
153 <<xtablelagimpactexact, results = 'asis'>>=
\r
158 <<xtablelagimpactmcmc, results = 'asis'>>=
\r
163 \subsubsection{\code{spautolm} objects}
\r
164 \label{sec:codespautolm-objects}
\r
166 The need for an \code{xtable} method for \code{spautolm} was expressed
\r
167 by Guido Schulz (\url{schulzgu@student.hu-berlin.de}), who also
\r
168 provided an example of an object of this type. The required code was
\r
169 implemented by David Scott (\url{d.scott@auckland.ac.nz}).
\r
171 First create an object of the required type.
\r
173 <<minimalexample, results = 'hide'>>=
\r
176 spautolmOBJECT <- spautolm(Z ~ PEXPOSURE + PCTAGE65P,data = nydata,
\r
177 listw = listw_NY, family = "SAR",
\r
178 method = "eigen", verbose = TRUE)
\r
179 summary(spautolmOBJECT, Nagelkerke = TRUE)
\r
184 class(spautolmOBJECT)
\r
188 <<xtablespautolm, results = 'asis'>>=
\r
189 xtable(spautolmOBJECT,
\r
190 display = c("s",rep("f", 3), "e"), digits = 4)
\r
195 \subsection{The package \pkg{splm}}
\r
196 \label{sec:package-pkgsplm}
\r
198 First load the package and create some objects.
\r
201 data("Produc", package = "plm")
\r
202 data("usaww", package = "splm")
\r
203 fm <- log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp
\r
204 respatlag <- spml(fm, data = Produc, listw = mat2listw(usaww),
\r
205 model="random", spatial.error="none", lag=TRUE)
\r
207 GM <- spgm(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, data = Produc,
\r
208 listw = usaww, moments = "fullweights", spatial.error = TRUE)
\r
211 imp.spml <- impacts(respatlag, listw = mat2listw(usaww, style = "W"), time = 17)
\r
216 \subsubsection{\code{splm} objects}
\r
217 \label{sec:codesplm-objects}
\r
219 <<xtablesplm, results = 'asis'>>=
\r
225 <<xtablesplm1, results = 'asis'>>=
\r
229 The \code{xtable} method works the same on impacts of \code{splm} models.
\r
231 <<xtablesplmimpacts, results = 'asis'>>=
\r
235 \subsection{The package \pkg{sphet}}
\r
236 \label{sec:package-pkgsphet}
\r
238 First load the package and create some objects.
\r
241 data("columbus", package = "spdep")
\r
242 listw <- nb2listw(col.gal.nb)
\r
243 data("coldis", package = "sphet")
\r
244 res.stsls <- stslshac(CRIME ~ HOVAL + INC, data = columbus, listw = listw,
\r
245 distance = coldis, type = 'Triangular')
\r
248 res.gstsls <- gstslshet(CRIME ~ HOVAL + INC, data = columbus, listw = listw)
\r
251 imp.gstsls <- impacts(res.gstsls, listw = listw)
\r
256 \subsubsection{\code{sphet} objects}
\r
257 \label{sec:codesphet-objects}
\r
259 <<xtablesphet, results = 'asis'>>=
\r
264 <<xtablesphet1, results = 'asis'>>=
\r
268 \code{sphet} also provides a method for computing impacts.
\r
270 <<xtablesphetimpacts, results = 'asis'>>=
\r
274 \section{The \pkg{zoo} package}
\r
275 \label{sec:pkgzoo-package}
\r
278 <<zoo, results = 'asis'>>=
\r
280 xDate <- as.Date("2003-02-01") + c(1, 3, 7, 9, 14) - 1
\r
282 x <- zoo(rnorm(5), xDate)
\r
289 <<zoots, results = 'asis'>>=
\r
290 tempTs <- ts(cumsum(1 + round(rnorm(100), 0)),
\r
291 start = c(1954, 7), frequency = 12)
\r
292 tempTable <- xtable(tempTs, digits = 0)
\r
294 tempZoo <- as.zoo(tempTs)
\r
295 xtable(tempZoo, digits = 0)
\r
299 \section{The \pkg{survival} package}
\r
300 \label{sec:pkgsurvival-package}
\r
303 <<survival, results = 'asis'>>=
\r
305 test1 <- list(time=c(4,3,1,1,2,2,3),
\r
306 status=c(1,1,1,0,1,1,0),
\r
307 x=c(0,2,1,1,1,0,0),
\r
308 sex=c(0,0,0,0,1,1,1))
\r
309 coxFit <- coxph(Surv(time, status) ~ x + strata(sex), test1)
\r