# A simple example of a statistical analysis using R2wd

The document is an R script. Special commands provided in the R2wd package push output into a Word file.
library(R2wd)
wdGet()
wdTitle("Simple R2wd usage example")
wdTitle("Analysis of Fisher's iris data")
wdTitle("BERD Reproducible Research working group")
# load data
data(iris)
wdBody(sprintf(
"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 %d flowers from each of %d species of iris. The species are %s.",
table(iris$Species)[1], nlevels(iris$Species), paste(levels(iris$Species), collapse=", ")))
wdBody("First, let's run a simple ANOVA comparing the sepal lengths of the three species.")
a1 <- aov(Sepal.Length~Species, data=iris)
wdTable(round(summary(a1)[[1]],3), caption=": ANOVA table")
wdBody("We can see that the three species have significantly different sepal lengths. Figure 1 shows the corresponding boxplot.")
wdPlot(Sepal.Length~Species, data=iris, ylab="Sepal length", plotfun=boxplot, width=4, height=4)
wdSave(file.path(getwd(),"iris.docx"))
wdQuit()

This file has to be evaluated by R using source() or copy-paste. This produces the following Output file .
-- AnikoSzabo - 30 Dec 2010