The instructions for our labs this quarter will be prestented in a file like this one. The file will explain statistical concepts, give examples of computer code needed to solve problems, and generally provide instructions. You should read it carefully. In fact, we recommend keeping this file open on half your screen and RStudio open on another tab. The instructions you find here will direct you to answer questions located in a template file that you download from D2L, edit, “knit” to pdf, and then re-upload to D2L for evaluation.
While some problems will require you to type answers, others will need you to create and editd code to solve problems. This code is evaluated in “code chunks.” You can create these executiable chunks by clicking the “Insert Chunk” button on the tool bar.
** Do exercise 1**
** Do exercise 2**
RStudio is also capable of loading large free data sets from repositories on the internet. This allows us to analyze some interesting statistical problems. Let’s see how this works by loading some data. To do so, copy the following command and paste it into the console at the bottom left of your RStudio window, and press enter. Note that you need to copy the whole line, including the word source and the parentheses.
source(“http://www.openintro.org/stat/data/arbuthnot.R”)
After you hit enter, you should see the arbuthnot data set in the environment box at the top right of your RStudio Window.
** Do exercise 3**
To turn in your lab report, you need to “knit” the template file to a PDF. To do this, click on the down arrow next to the knit button in the toolbar. Choose knit to pdf to create a pdf output. Warning You should get an error. If you look through the red text, you’ll see that the object ‘arbuthnot’ was not found. Why?
To understand the problem, you need to know a little about how R works. When you load data or create a variable in the Console, it adds that data to the environment. When you run an individual code chunk in a notebook, that chunk has access to everything in the environment. That’s why there was no error when you ran the code chunk containing the summary(arbuthnot) command.
However, when you use the knit command, the whole process starts from scratch. The commands in the notebook are run one after the other, but the notebook only sees commands that are actually typed in the notebook. Since you didn’t load the arbuthnot data set in the notebook, the notebook can’t find it when it gets to the summary(arbuthnot) command in the knitting process.
** Do exercise 4**
You are now done with lab for week 1!