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