R Markdown, and More

John Maindonald
September 2 2014

Under the R Umbrella

R has become a great umbrella for all and sundry

Once the abilities of a program are under the R umbrella, all of existing R is available for use, for data input, data manipulation, graphics, …

R Studio is an aid to organizing and checking work

Every project can become an exercise in combining together all the text for a report or paper, and code for all computer output, including graphs and tables. On a click of a mouse, the report, or presentation, or paper, automagically appears.

Hurricanes vs Himmicanes

(Publish and Be Damned?)

It can happen!

“Female hurricanes are deadlier than male hurricanes”,
by Jung, Shavitta, Viswanathana, and Hilbe.
http://www.pnas.org/cgi/doi/10.1073/pnas.1402786111

The paper has caused a stir on the blogosphere.

Did the authors plot the data!

plot of chunk doplot-bad

Plot data, exclude Agnes and Katrina

plot of chunk plot-omit-largest

Deaths vs Damage in 2014 $US, log scales

plot of chunk doplot

Effect of NDAM Given MinPressure

plot of chunk gam

Effect of Minpressure Given NDAM

plot of chunk gam2

Interactive Documents

The new (Sept 2 2014) preview release of RStudio.
has much enhanced abilities for creating interactive documents. Download from: http://www.rstudio.com/products/rstudio/download/preview/

The R package shiny supplies the needed web application framework. See:
http://rmarkdown.rstudio.com/authoring_shiny.html

To learn about Shiny, go to
http://shiny.rstudio.com/tutorial/

See also:

https://github.com/mages/googleVis/tree/master/vignettes

Click on Using_googleVis_with_knitr.Rmd

Data Input from SPSS

Replace path2file with the path to your file.

library(memisc)
path2file <- "sourceDir/zzz.sav"
nys1987Imp <- spss.system.file(path2file)
show(nys1987Imp)
desc <- description(nys1987Imp)

Description Details

The above has imported file details only. The following examines description details for the first four fields:

desc[1:4]

More Details — Codebook

The function codebook() provides more extensive information. The following provides codebook details for the first four fields:

codebook(nys1987Imp[,1:4], eval=FALSE)

Import Data

Use as.data.set() to extract the data, into an memisc data.set object. Use as.data.frame() to create a data frame from the data.set object. There may be some loss of information,

nys1987 <- as.data.set(nys1987Imp)
##
## Can now do, e.g.
nys1987Cols1to20 <- subset(nys1987, 
                           select=names(desc)[1:20])