]> git.donarmstrong.com Git - xtable.git/blob - pkg/vignettes/OtherPackagesGallery.Rnw
Added Other Packages vignette
[xtable.git] / pkg / vignettes / OtherPackagesGallery.Rnw
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
5 % !Rnw weave = knitr\r
6 % \VignetteEngine{knitr::knitr}\r
7 %**************************************************************************\r
8 \documentclass{article}\r
9 \usepackage[a4paper, height=24cm]{geometry} % geometry first\r
10 \usepackage{array}\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
23 \begin{document}\r
24 \r
25 \title{\bfseries\Large The Other Packages Gallery}\r
26 \author{\bfseries David J. Scott}\r
27 \maketitle\r
28 \r
29 \tableofcontents\r
30 \r
31 \newpage\r
32 \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
36 \r
37 <<set, include=FALSE>>=\r
38 library(knitr)\r
39 opts_chunk$set(fig.path = 'Figures/other', debug = TRUE, echo = TRUE)\r
40 opts_chunk$set(out.width = '0.9\\textwidth')\r
41 @\r
42 \r
43 The first step is to load the package and set some options for this document.\r
44 <<package, results='asis'>>=\r
45 library(xtable)\r
46 options(xtable.floating = FALSE)\r
47 options(xtable.timestamp = "")\r
48 options(width = 60)\r
49 @\r
50 \r
51 \section{The packages \pkg{spdep}, \pkg{splm}, and \pkg{sphet}}\r
52 \r
53 Code for supporting these packages and most of the examples used in\r
54 this section was originally provided by Martin Gubri\r
55 (\url{martin.gubri@framasoft.org}).\r
56 \r
57 \subsection{The package \pkg{spdep}}\r
58 \label{sec:package-pkgspdep}\r
59 \r
60 First load the package and create some objects.\r
61 <<dataspdep>>=\r
62 library(spdep)\r
63 data(oldcol)\r
64 COL.lag.eig <- lagsarlm(CRIME ~ INC + HOVAL, data = COL.OLD, \r
65                         nb2listw(COL.nb))\r
66 class(COL.lag.eig)\r
67 COL.errW.GM <- GMerrorsar(CRIME ~ INC + HOVAL, data = COL.OLD,\r
68                           nb2listw(COL.nb, style = "W"), \r
69                           returnHcov = TRUE)\r
70 class(COL.errW.GM)\r
71 COL.lag.stsls <- stsls(CRIME ~ INC + HOVAL, data = COL.OLD, \r
72                        nb2listw(COL.nb))\r
73 class(COL.lag.stsls)\r
74 @ %def\r
75 \r
76 \r
77 \subsubsection{\code{sarlm} objects}\r
78 \label{sec:codesarlm-objects}\r
79 \r
80 There is an \code{xtable} method for objects of this type.\r
81 <<xtablesarlm, results = 'asis'>>=\r
82 xtable(COL.lag.eig)\r
83 @ %def \r
84 \r
85 The method for \code{xtable} actually uses the summary of the object,\r
86 and an identical result is obtained when using the summary of the\r
87 object, even if the summary contains more additional information.\r
88 \r
89 <<xtablesarlmsumm, results = 'asis'>>=\r
90 xtable(summary(COL.lag.eig, correlation = TRUE))\r
91 @ %def\r
92 \r
93 This same pattern applies to the other objects from this group of packages.\r
94 \r
95 Note that additional prettying of the resulting table is possible, as\r
96 for any table produced using \code{xtable}. For example using the\r
97 \pkg{booktabs} package we get:\r
98 \r
99 <<xtablesarlmbooktabs, results = 'asis'>>=\r
100 print(xtable(COL.lag.eig), booktabs = TRUE)\r
101 @ %def\r
102 \r
103 \subsubsection{\code{gmsar} objects}\r
104 \label{sec:codegmsar-objects}\r
105 \r
106 \r
107 <<xtablegmsar, results = 'asis'>>=\r
108 xtable(COL.errW.GM)\r
109 @ %def \r
110 \r
111 \subsubsection{\code{stsls} objects}\r
112 \label{sec:codestsls-objects}\r
113 \r
114 \r
115 <<xtablestsls, results = 'asis'>>=\r
116 xtable(COL.lag.stsls)\r
117 @ %def \r
118 \r
119 \r
120 \r
121 \subsubsection{\code{spautolm} objects}\r
122 \label{sec:codespautolm-objects}\r
123 \r
124 The need for an \code{xtable} method for \code{spautolm} was expressed\r
125 by Guido Schulz (\url{schulzgu@student.hu-berlin.de}), who also\r
126 provided an example of an object of this type. The required code was\r
127 implemented by David Scott (\url{d.scott@auckland.ac.nz}).\r
128 \r
129 First create an object of the required type\r
130 \r
131 <<minimalexample, results = 'hide'>>=\r
132 library(spdep)\r
133 example(NY_data)\r
134 spautolmOBJECT <- spautolm(Z ~ PEXPOSURE + PCTAGE65P,data = nydata,\r
135                            listw = listw_NY, family = "SAR",\r
136                            method = "eigen", verbose = TRUE)\r
137 summary(spautolmOBJECT, Nagelkerke = TRUE)\r
138 @ %def\r
139 \r
140 \p\r
141 <<spautolmclass>>=\r
142 class(spautolmOBJECT)\r
143 @ %def \r
144 \r
145 \r
146 <<xtablespautolm, results = 'asis'>>=\r
147 xtable(spautolmOBJECT,\r
148        display = c("s",rep("f", 3), "e"), digits = 4)\r
149 @ %def \r
150 \r
151 \r
152 \r
153 \subsection{The package \pkg{splm}}\r
154 \label{sec:package-pkgsplm}\r
155 \r
156 First load the package and create some objects.\r
157 <<datasplm>>=\r
158 library(splm)\r
159 data(Produc, package = "plm")\r
160 data(usaww)\r
161 fm <- log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp\r
162 fespaterr <- spml(fm, data = Produc, listw = mat2listw(usaww),\r
163                   model = "within", spatial.error = "b", Hess = FALSE)\r
164 class(fespaterr)\r
165 GM <- spgm(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, data = Produc,\r
166            listw = usaww, moments = "fullweights", spatial.error = TRUE)\r
167 class(GM)\r
168 @ %def\r
169 \r
170 \r
171 \subsubsection{\code{splm} objects}\r
172 \label{sec:codesplm-objects}\r
173 \r
174 <<xtablesplm, results = 'asis'>>=\r
175 xtable(fespaterr)\r
176 @ %def \r
177 \r
178 \r
179 \p\r
180 <<xtablesplm1, results = 'asis'>>=\r
181 xtable(GM)\r
182 @ %def \r
183 \r
184 \r
185 \subsection{The package \pkg{sphet}}\r
186 \label{sec:package-pkgsphet}\r
187 \r
188 First load the package and create some objects.\r
189 <<datasphet>>=\r
190 library(sphet)\r
191 data(columbus)\r
192 listw <- nb2listw(col.gal.nb)\r
193 data(coldis)\r
194 res.stsls <- stslshac(CRIME ~ HOVAL + INC, data = columbus, listw = listw,  \r
195                       distance = coldis, type = 'Triangular')\r
196 class(res.stsls)\r
197 \r
198 res.gstsls <- gstslshet(CRIME ~ HOVAL + INC, data = columbus, listw = listw)\r
199 class(res.gstsls)\r
200 @ %def\r
201 \r
202 \r
203 \subsubsection{\code{sphet} objects}\r
204 \label{sec:codesphet-objects}\r
205 \r
206 <<xtablesphet, results = 'asis'>>=\r
207 xtable(res.stsls)\r
208 @ %def \r
209 \r
210 \p\r
211 <<xtablesphet1, results = 'asis'>>=\r
212 xtable(res.gstsls)\r
213 @ %def \r
214 \r
215 \r
216 \end{document}\r