Introduction

In the past few days, you have been practicing your R skills on DataCamp. The goal of today’s tutorial is to introduce you to Rstudio, which you will be using throughout this course both to learn the statistical concepts discussed in the textbook and also to analyze real data and come to informed conclusions. To straighten out which is which: R is the name of the programming language itself and RStudio is a convenient interface.

As the assignment progress, you are encouraged to explore beyond what the assignment dictate; a willingness to experiment will make you a much better programmer and statistician. Before we get to that stage, however, you need to build some basic fluency in Rstudio and Rmarkdown. Today we begin with the fundamental building blocks: the Rstudio interface, reading in data, and basic commands.

The RStudio Interface

Go ahead and launch RStudio on your computer.

You should see a window that looks like the image shown below.

The panel on the left is where the action happens. It’s called the console. Every time you launch RStudio, it will have the same text at the top of the console telling you the version of R that you’re running. Below that information is the prompt. As its name suggests, this prompt is really a request: a request for a command. Initially, interacting with R is all about typing commands and interpreting the output. These commands and their syntax have evolved over decades (literally) and now provide what many users feel is a fairly natural way to access data and organize, describe, and invoke statistical computations.

The panel in the upper right contains your environment as well as a history of the commands that you’ve previously entered.

Any plots that you generate will show up in the panel in the lower right corner. This is also where you can browse your files, access help, manage packages, etc.

R Packages

R is an open-source programming language, meaning that users can contribute packages that make our lives easier, and we can use them for free. For this assignment, and many others in the future, we will use the following R packages:

  • The suite of tidyverse packages: for data wrangling and data visualization

Let’s install this package by using the install packages button in the Tools tab.

Type tidyverse in the empty space. Make sure you checked the Install dependencies and click Install

You only need to install packages once, but you need to load them each time you relaunch RStudio.

We do this with the library function. Run the following line in your console.

library(tidyverse)

The Tidyverse packages share common philosophies and are designed to work together. You can find more about the packages in the tidyverse at tidyverse.org.

Creating your own Rmarkdown report

We will be using a markdown language, R Markdown, to type up the assignment.

This allows you to complete your assignment entirely in RStudio as well as ensuring reproducibility of your analysis and results. See the following videos describing why and how:

Why use R Markdown for assignment?

Step 1: install the rmarkdown package.

Use the same installing steps as before for tidyverse.

Step 2: download the Rmarkdown template

To help get you started we are providing a template for you. Copy the following code in the Rstudio console and hit enter:

download.file("https://raw.githubusercontent.com/sshanshans/stat140/master/docs/project/MP01/MP01-template.Rmd", destfile = "MP01.Rmd")

You will see a new file called MP01.Rmd in the Files tab on the pane in the bottom right corner of your RStudio window. We will refer to this as your “R markdown file” or “your report”. Click on the file name to open the file. All you need to do to complete this assignment is to type up your brief answers and the R code (when necessary) in the spaces provided in the document. Earlier in the course, spaces are provided for you to enter R code chunks. Later in the course you’ll need to figure out whether code is needed to answer a particular question, and if so a new chunk can be inserted by clicking on the Insert Chunk button (dropdown menu under Chunks on the upper right corner of your markdown document).

Step 3: a first knit

Before you keep going type your name next to “author” and the names of your group members for this mini-project. Then click on Knit to HTML and you’ll see your document in a new pop-up window.

Step 4: turn on your visual editor

What’s even better now with the new Rstudio preview there is a visual editor.

Step 5: finish all the problems in MP01

Step 6: polishing cannon balls and turning in your report

Now you have done all the problems. How could you export your report and turn that in on Gradescope. For that you will need to do Knit to pdf.

If R returns error, try typine the following code in your Console:

tinytex::install_tinytex()

Once the process in R is done, you will see a new pdf document generated in your current folder. Submit that pdf file on Gradescope. Each group only needs to turn in one report.

Peer evaluations

By the time you turn in your group project, you will be asked to fill a evaluation form for assess your group members’ participation, quality and quantity of work. Your final grade for the group project will be weighted by the peer evaluations of your group members. The rubric for peer assessment is provided as follows. Note that this evaluation form will be anonymous to everyone except me.