]> git.donarmstrong.com Git - xtable.git/commitdiff
Added Other Packages vignette
authordscott <dscott@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>
Wed, 6 Jan 2016 03:18:56 +0000 (03:18 +0000)
committerdscott <dscott@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>
Wed, 6 Jan 2016 03:18:56 +0000 (03:18 +0000)
git-svn-id: svn://scm.r-forge.r-project.org/svnroot/xtable@81 edb9625f-4e0d-4859-8d74-9fd3b1da38cb

pkg/vignettes/OtherPackagesGallery.Rnw [new file with mode: 0644]

diff --git a/pkg/vignettes/OtherPackagesGallery.Rnw b/pkg/vignettes/OtherPackagesGallery.Rnw
new file mode 100644 (file)
index 0000000..43fbebb
--- /dev/null
@@ -0,0 +1,216 @@
+%\VignetteIndexEntry{xtable List of Tables Gallery}\r
+%\VignetteDepends{xtable, spdep, splm, sphet}\r
+%\VignetteKeywords{LaTeX, HTML, table}\r
+%\VignettePackage{xtable}\r
+% !Rnw weave = knitr\r
+% \VignetteEngine{knitr::knitr}\r
+%**************************************************************************\r
+\documentclass{article}\r
+\usepackage[a4paper, height=24cm]{geometry} % geometry first\r
+\usepackage{array}\r
+\usepackage{booktabs}\r
+\usepackage{longtable}\r
+\usepackage{parskip}\r
+\usepackage{rotating}\r
+\usepackage{tabularx}\r
+\usepackage{titlesec}\r
+\usepackage{hyperref} % hyperref last\r
+\titleformat\subsubsection{\bfseries\itshape}{}{0pt}{}\r
+\newcommand\p{\vspace{2ex}}\r
+\newcommand\code[1]{\texttt{#1}}\r
+\newcommand\pkg[1]{\textbf{#1}}\r
+\setcounter{tocdepth}{2}\r
+\begin{document}\r
+\r
+\title{\bfseries\Large The Other Packages Gallery}\r
+\author{\bfseries David J. Scott}\r
+\maketitle\r
+\r
+\tableofcontents\r
+\r
+\newpage\r
+\r
+\section{Introduction}\r
+This document represents a test of the functions in \pkg{xtable} which\r
+deal with other packages\r
+\r
+<<set, include=FALSE>>=\r
+library(knitr)\r
+opts_chunk$set(fig.path = 'Figures/other', debug = TRUE, echo = TRUE)\r
+opts_chunk$set(out.width = '0.9\\textwidth')\r
+@\r
+\r
+The first step is to load the package and set some options for this document.\r
+<<package, results='asis'>>=\r
+library(xtable)\r
+options(xtable.floating = FALSE)\r
+options(xtable.timestamp = "")\r
+options(width = 60)\r
+@\r
+\r
+\section{The packages \pkg{spdep}, \pkg{splm}, and \pkg{sphet}}\r
+\r
+Code for supporting these packages and most of the examples used in\r
+this section was originally provided by Martin Gubri\r
+(\url{martin.gubri@framasoft.org}).\r
+\r
+\subsection{The package \pkg{spdep}}\r
+\label{sec:package-pkgspdep}\r
+\r
+First load the package and create some objects.\r
+<<dataspdep>>=\r
+library(spdep)\r
+data(oldcol)\r
+COL.lag.eig <- lagsarlm(CRIME ~ INC + HOVAL, data = COL.OLD, \r
+                        nb2listw(COL.nb))\r
+class(COL.lag.eig)\r
+COL.errW.GM <- GMerrorsar(CRIME ~ INC + HOVAL, data = COL.OLD,\r
+                          nb2listw(COL.nb, style = "W"), \r
+                          returnHcov = TRUE)\r
+class(COL.errW.GM)\r
+COL.lag.stsls <- stsls(CRIME ~ INC + HOVAL, data = COL.OLD, \r
+                       nb2listw(COL.nb))\r
+class(COL.lag.stsls)\r
+@ %def\r
+\r
+\r
+\subsubsection{\code{sarlm} objects}\r
+\label{sec:codesarlm-objects}\r
+\r
+There is an \code{xtable} method for objects of this type.\r
+<<xtablesarlm, results = 'asis'>>=\r
+xtable(COL.lag.eig)\r
+@ %def \r
+\r
+The method for \code{xtable} actually uses the summary of the object,\r
+and an identical result is obtained when using the summary of the\r
+object, even if the summary contains more additional information.\r
+\r
+<<xtablesarlmsumm, results = 'asis'>>=\r
+xtable(summary(COL.lag.eig, correlation = TRUE))\r
+@ %def\r
+\r
+This same pattern applies to the other objects from this group of packages.\r
+\r
+Note that additional prettying of the resulting table is possible, as\r
+for any table produced using \code{xtable}. For example using the\r
+\pkg{booktabs} package we get:\r
+\r
+<<xtablesarlmbooktabs, results = 'asis'>>=\r
+print(xtable(COL.lag.eig), booktabs = TRUE)\r
+@ %def\r
+\r
+\subsubsection{\code{gmsar} objects}\r
+\label{sec:codegmsar-objects}\r
+\r
+\r
+<<xtablegmsar, results = 'asis'>>=\r
+xtable(COL.errW.GM)\r
+@ %def \r
+\r
+\subsubsection{\code{stsls} objects}\r
+\label{sec:codestsls-objects}\r
+\r
+\r
+<<xtablestsls, results = 'asis'>>=\r
+xtable(COL.lag.stsls)\r
+@ %def \r
+\r
+\r
+\r
+\subsubsection{\code{spautolm} objects}\r
+\label{sec:codespautolm-objects}\r
+\r
+The need for an \code{xtable} method for \code{spautolm} was expressed\r
+by Guido Schulz (\url{schulzgu@student.hu-berlin.de}), who also\r
+provided an example of an object of this type. The required code was\r
+implemented by David Scott (\url{d.scott@auckland.ac.nz}).\r
+\r
+First create an object of the required type\r
+\r
+<<minimalexample, results = 'hide'>>=\r
+library(spdep)\r
+example(NY_data)\r
+spautolmOBJECT <- spautolm(Z ~ PEXPOSURE + PCTAGE65P,data = nydata,\r
+                           listw = listw_NY, family = "SAR",\r
+                           method = "eigen", verbose = TRUE)\r
+summary(spautolmOBJECT, Nagelkerke = TRUE)\r
+@ %def\r
+\r
+\p\r
+<<spautolmclass>>=\r
+class(spautolmOBJECT)\r
+@ %def \r
+\r
+\r
+<<xtablespautolm, results = 'asis'>>=\r
+xtable(spautolmOBJECT,\r
+       display = c("s",rep("f", 3), "e"), digits = 4)\r
+@ %def \r
+\r
+\r
+\r
+\subsection{The package \pkg{splm}}\r
+\label{sec:package-pkgsplm}\r
+\r
+First load the package and create some objects.\r
+<<datasplm>>=\r
+library(splm)\r
+data(Produc, package = "plm")\r
+data(usaww)\r
+fm <- log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp\r
+fespaterr <- spml(fm, data = Produc, listw = mat2listw(usaww),\r
+                  model = "within", spatial.error = "b", Hess = FALSE)\r
+class(fespaterr)\r
+GM <- spgm(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, data = Produc,\r
+           listw = usaww, moments = "fullweights", spatial.error = TRUE)\r
+class(GM)\r
+@ %def\r
+\r
+\r
+\subsubsection{\code{splm} objects}\r
+\label{sec:codesplm-objects}\r
+\r
+<<xtablesplm, results = 'asis'>>=\r
+xtable(fespaterr)\r
+@ %def \r
+\r
+\r
+\p\r
+<<xtablesplm1, results = 'asis'>>=\r
+xtable(GM)\r
+@ %def \r
+\r
+\r
+\subsection{The package \pkg{sphet}}\r
+\label{sec:package-pkgsphet}\r
+\r
+First load the package and create some objects.\r
+<<datasphet>>=\r
+library(sphet)\r
+data(columbus)\r
+listw <- nb2listw(col.gal.nb)\r
+data(coldis)\r
+res.stsls <- stslshac(CRIME ~ HOVAL + INC, data = columbus, listw = listw,  \r
+                      distance = coldis, type = 'Triangular')\r
+class(res.stsls)\r
+\r
+res.gstsls <- gstslshet(CRIME ~ HOVAL + INC, data = columbus, listw = listw)\r
+class(res.gstsls)\r
+@ %def\r
+\r
+\r
+\subsubsection{\code{sphet} objects}\r
+\label{sec:codesphet-objects}\r
+\r
+<<xtablesphet, results = 'asis'>>=\r
+xtable(res.stsls)\r
+@ %def \r
+\r
+\p\r
+<<xtablesphet1, results = 'asis'>>=\r
+xtable(res.gstsls)\r
+@ %def \r
+\r
+\r
+\end{document}\r