R Markdown Test

This is a test R Markdown document, based on the demo project from Jenny Bryan's R basics, workspace and working directory, RStudio projects tutorial.

The script generates and plots n random samples drawn from a line with intercept a and slope b plus gaussian noise with variance sigSq.

# Parameter definitions
n <- 100
a <- 1
b <- 6
sigSq <- 0.5
set.seed(42)
# x is sampled from a uniform distribution from 0 to 1 (non-inclusive)
x <- runif(n)
y <- a + b * x + rnorm(n, sd = sqrt(sigSq))
# Get and write the mean x value
(avgX <- mean(x))
## [1] 0.5245

To get an anti-aliased graph on Linux/Windows, you need to load the Cairo package and (for RPubs) tell knitr to use the CairoPNG device in the chunk options. Mac users get anti-aliasing by default.

# Plot the graph and the line of the sampled function
library(ggplot2)
library(Cairo)
str <- paste("y ~ ", a, " + ", b, " * x + gaussianNoise")
p <- qplot(x, y, main = str) + theme_bw()
p <- p + geom_abline(intercept = a, slope = b, col = "darkgreen", lwd = 1)
print(p)

plot of chunk CairoPlot

sessionInfo()
## R version 3.0.1 (2013-05-16)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## 
## locale:
## [1] LC_COLLATE=English_Canada.1252  LC_CTYPE=English_Canada.1252   
## [3] LC_MONETARY=English_Canada.1252 LC_NUMERIC=C                   
## [5] LC_TIME=English_Canada.1252    
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] Cairo_1.5-2     ggplot2_0.9.3.1 knitr_1.4.1    
## 
## loaded via a namespace (and not attached):
##  [1] colorspace_1.2-2   dichromat_2.0-0    digest_0.6.3      
##  [4] evaluate_0.4.7     formatR_0.9        grid_3.0.1        
##  [7] gtable_0.1.2       labeling_0.2       MASS_7.3-26       
## [10] munsell_0.4.2      plyr_1.8           proto_0.3-10      
## [13] RColorBrewer_1.0-5 reshape2_1.2.2     scales_0.2.3      
## [16] stringr_0.6.2      tools_3.0.1

Fortune Cookie

fortunes::fortune(12)
## 
## You can be maximally lazy, but still be efficient.
##    -- Kevin Murphy (describing the implementation of an algorithm)
##       gR 2003, Aalborg (September 2003)