% Example of Literate Programming for Presentations % % James Keirstead % AcademicProductivity.com % 25 August 2009 % % Published at http://www.academicproductivity.com/2009/literate-programming-for-talks \title{Linear regression} \author{James Keirstead} \begin{document} \begin{frame} \maketitle \end{frame} In this talk, I will be demonstrating how to create a simple linear regression model in R. The first step is to create some data. Let's assume we have a simple function, $f(x)$ where $y = x + \epsilon$ and the error term, $\epsilon$, is normally distributed with $\mu = 0$ and $\sigma = 1$. % The following is an R code block that creates the x and y data series. It will not be visible in either the article or the slides. <>= x <- 1:100 y <- x + rnorm(100,0,1) @ Now that we've created our data set, let's inspect it. \begin{frame}{Our data set} <>= plot(x,y) @ \end{frame} Looks pretty linear! We can then perform the linear regression in R. %Note that this code will be shown in the lecture notes but not on the slides. <<>>= lm <- lm(y~x) @ The results of the linear regression show that the model is significant with an adjusted $r^2$ value of \Sexpr{round(summary(lm)$adj.r.squared,4)}. \begin{frame}{Results of linear regression} <>= summary(lm) @ \end{frame} \end{document}