A simple example of a statistical analysis using Sweave

The document is essentially written in LaTeX with specially marked chunks of R code inserted along the way. The file is usually saved with an .Rnw extension.

\title{Simple Sweave usage example:\\ Analysis of Fisher's iris data}
\author{BERD Reproducible Research working group}
\SweaveOpts{echo=false, eps=false}
<<StartUp, results=hide>>=
The famous (Fisher's or Anderson's) iris data set gives the measurements in centimeters of the variables
sepal length and width, and petal length and width, respectively, for \Sexpr{table(iris$Species)[1]} flowers from each of
\Sexpr{nlevels(iris$Species)} species of iris.  The species are \emph{\Sexpr{paste(levels(iris$Species), collapse=", ")}}.
First, let's run a simple ANOVA comparing the sepal lengths of the three species.
  a1 <- aov(Sepal.Length~Species, data=iris)
We can see that the three species have significantly different sepal lengths.  Figure~\ref{F:box} shows the corresponding
<<SLplot,fig=true, width=4, height=4>>=
 boxplot(Sepal.Length~Species, data=iris, ylab="Sepal length")
\caption{Boxplot of sepal lengths by species.}\label{F:box}
This file can be compiled within an R session by calling

Sweave("iris.Rnw", stylepath=FALSE)   

tools::texi2dvi("iris.tex", pdf=TRUE)  
This produces the following PDF file .

-- AnikoSzabo - 17 Dec 2010

Topic attachments
I Attachment Action Size Date Who Comment
iris.RnwRnw iris.Rnw manage 1 K 17 Dec 2010 - 20:42 UnknownUser  
iris.pdfpdf iris.pdf manage 95 K 17 Dec 2010 - 20:40 UnknownUser