Docsity

Creating Live Reports on Kentucky Senate Race using R, tikzDevice, knitr, and LATEX, Exercises of Fiction Writing

Partial preview of the text

Download Creating Live Reports on Kentucky Senate Race using R, tikzDevice, knitr, and LATEX and more Exercises Fiction Writing in PDF only on Docsity!

Dynamic Documents

David Allen

University of Kentucky

July 30, 2014

Presented at TUG 2014

1 Introduction

A generic definition of a dynamic document from Wikipedia:

A living document or dynamic document is a document that is continually edited and updated. A simple example of a living document is an article in Wikipedia, an online encyclopedia that permits anyone to freely edit its articles, in contrast to “dead” or “static documents”, such as an article in a single edition of the Encyclopedia Britannica.

2 The Kentucky Senate Race

On November 4, 2014, the Commonwealth of Kentucky will elect a United States Senator. This race has high national impact and is closely watched.

The Candidates

Alison Mitch

Credible Interval

The parameter of interest is the population proportion favoring Alison. A credible interval is such that the parameter lies within the interval with high probability. A credible interval is a more informative mode of presentation, as it conveys the uncertainty of knowledge about the parameter.

Details

Denote the proportion of the population favoring Alison by p. The first step in calculating a credible interval is finding the posterior density function of p given the sample results. One needs to select a level of credibility. The value 0.95 has a strong tradition and is used here. The 0.95 credibility interval is an interval ( p 1 , p 2 ) where P ( p 1 < p < p 2 ) = 0_._ 95. That probability statement does not uniquely determine the interval. The interval having minimal length is usually used.

Posterior Density with Credible Interval

Proportion Favoring Alison

Posterior Density

A “Report”

The cumulative results of polling through July 30, 2014 produced 55 potential voters favoring Alison and 45 favoring Mitch. These results give a 0.95 credible interval for the proportion favoring Alison of ( 0_._ 4528 , 0_._ 6428 ).

3 TikZ graphics

TikZ is a graphics package used in conjunction with TEX. It is included with most distributions of TEX, but may be downloaded at http://sourceforge.net/projects/pgf/. A large selection of examples of TikZ graphics are posted at http://www.texample.net/tikz/examples/.

Examples I have composed are on the next two slides.

Fish Tank

This graphic was hand coded in Sketch, http://www.frontiernet.net/~eugene.ressler/, and then processed into TikZ.

4 A overview of R

R is a language and environment for statistical computing and graphics. Its home page is http://www.r-project.org. R is a free software project. It compiles and runs on a wide variety of Unix platforms and similar systems (including FreeBSD and GNU/Linux), Windows and MacOSX. R is often the vehicle of choice for research in statistical methodology, and it provides an open source route to participation in that activity.

Statistical Procedures

R provides a wide variety of statistical techniques including linear and nonlinear modeling, classical statistical tests, time-series analysis, classification, and clustering.

5 A simple example

TikzDevice enables LATEX-ready output from R graphics functions. This is done by producing code that can be understood by the TikZ graphics language. All text in a graphic output with the tikz() function will be typeset by LATEX and therefore will match whatever fonts are currently used in the document. This also means that LATEX mathematics can be typeset directly into labels and annotations! Graphics produced this way can also be annotated with custom TikZ commands.

The R Graphic using tikzDevice

y

y = 10 + ( − 5 )^2