Assignment 1 Objectives

The purpose of this first assignment is to demonstrate that you have downloaded the “base R” and “RStudio” statistical programs and can open a SPSS datafile in RStudio.

This document was created as an R Markdown file. You will learn about R Markdown files later in the assignment. First, I want to familiarize you with the RStudio interface.

By the end of assignment #1, you should…

  • have created folders on both your personal computer and in cloud storage
  • have 6 full datasets downloaded
  • know how to create R Markdown (RMD) document in RStudio
  • know how to add and modify text, including italic or bold font and level headings, in an R Markdown document
  • know how to add and use an R code chunk in an RMD file
  • know how to use install.packages() and library() commands to install and load packages in R
  • know about groundhog.library() as a reproducible alternative for loading packages (optional but recommended)
  • know how to add hashtags (“#”) to comment out a section of R code so it does not run
  • be able to use the “here” package and here() function for simple, reproducible file directory referencing
  • be able to read data into R/RStudio using read_spss() function from “haven” package, then assign it to an object in the R environment using an assignment (<-) operator
  • be able to knit your RMD file into a Word document that you can save and submit for course credit

Assumptions & Ground Rules

For all assignments in this class, you must have access to a computer and should also use a cloud storage platform at IU, such as Dropbox, OneDrive, or Google Drive. Thus, for this and all future assignments, I will assume you are working on your own computer and are downloading base R and RStudio (free open source) programs on your own computer. If you experience technical difficulties, remember that you can contact UITS for help.

If you do not have access to your own computer or cannot download R/RStudio, you may be able to request limited access to a desktop computer with these programs pre-installed at IUB’s Social Science Research Center (SSRC). Whether you download R or access it elsewhere (e.g., via SSRC), the remainder of the steps must be completed on all computers for grading purposes. Also, for this and all future assignments, you MUST type all commands in by hand. Do not copy & paste except for troubleshooting purposes (i.e., if you cannot figure out what you mistyped).

Early on, you may have a lot of trouble getting your code to run due to minor typos. This is normal. Remember, you are learning to read and write a new (coding) language. As with learning any new languages, we learn from practice - and from correcting our mistakes.


Part 1 (Assignment 1.1)

Goal: Create new K300_L_LastName folder on your local computer, then download datasets and save to your new folder (i.e., “L” for “local” computer folder).

(Note: When following instructions, always substitute “LastName” for your own last name! Also, substitute YEAR_MO_DY for the actual date. E.g., 2022_05_17_Fordham_K300Assign1_1)

  1. On your computer, create a new folder called “K300_L_LastName” in a location that is easy to access (e.g., on Desktop or in “My Documents”).

  2. Create two new folders in your K300_L folder: a “Datasets” folder (K300_L_LastName > Datasets) and an “Assignments” folder (K300_L_LastName > Assignments)

  3. Visit the the Companion Website for Bachman, Paternoster, and Wilson’s Statistics for Criminology & Criminal Justice, 5th Ed (specifically, under the heading: R Data Sets, Full Versions) for the datasets.
    1. On the left sidebar, click “Datasets”
    2. Under the header Data Sets for SPSS Full Version, you will see six datasets:
      * Monitoring the Future 2013 grade 10_0.sav
      * 1992-2013 NCVS Lone Offender Assaults.sav
      * YouthDataset.sav
      * 2012 States Data.sav
      * 2013 YRBS.sav
      * GSS 2014.sav

  4. Download each dataset and save them all in the new “K300_L_LastName > Datasets” folder you made in Part 2.

  5. Take a screenshot (#1) of your new K300_L_LastName > Datasets folder with all six datasets downloaded in it. PC (Option 1): ctrl + prt sc then ctrl + P into a Word document. PC (Option 2): In the search bar type in “snipping tool” and use the tool to take a snapshot of your Datasets folder. *Mac: Command + shift + 3; this saves on your desktop.

  6. Save the Word document with your screenshot to your “K300_L_LastName > Assignments” folder. Name the file: YEAR_MO_DY_LastName_K300Assign1_1

Part 2 (Assignment 1.2)

Goal: Login to a cloud storage platform and create a K300_C_LastName cloud-based folder (i.e., “C” for “cloud” folder), and backup files.

This step ensures that you have an official IU cloud-based folder where you can save and back up all of your datasets and files for K300 assignments. Though not essential (i.e., you can complete the assignments without a cloud storage folder), by saving and backing up using cloud storage, you will be able to access your saved files from any computer and you will still have access to your saved files if your computer were to unfortunately stop working.

  1. Choose and login to a cloud storage platform, such as Dropbox, OneDrive, or Google Drive.

  2. Create a new folder called K300_C_LastName

  3. Create a new Datasets folder in your K300_C folder (K300_C_LastName > Datasets)

  4. Backup your datasets and assignment work Copy and paste the 6 datasets from your K300_L folder on your local computer into your “Datasets” folder on your cloud storage platform (K300_C_LastName > Datasets). You should also create a new “Assignments” folder in K300_C folder to save a copy of “Assign1_1” screenshot.

  5. Take a screenshot (#2) of your cloud storage “Datasets” folder (K300_C_LastName > Datasets) with all 6 datasets in it. Save in a Word document to your “Assignments” folder; name the file: YEAR_MO_DY_LastName_K300Assign1_2

If you would like an easier way of backing up files, you can learn how to sync your cloud storage folders directly to your computer. With this method, each time you save your R Markdown and Word files, they will automatically update in your cloud storage folders. In other words, you would be able to navigate to and use the cloud storage folders that you just created in the same way that you navigate to and use any other folder on your computer (e.g., via file explorer). If you are interested in using this method, the instructions for doing so through Dropbox are here.


Note: From this point forward, I will assume that you are backing up all folders and files you create on your local machine (K300_L_LastName) to your cloud storage folder (K300_C_LastName) as well. Doing so will save you immense trouble if something were to happen unexpectedly to the files and folders on your local machine.


Part 3 (Assignment 1.3)

Goal: Download R & R Studio; Open R Markdown; Knit first RMD file

In this section, you will begin by downloading and installing two programs on your computer: base R and RStudio.The first program, R, is simultaneously a computer coding language and a statistical software program. The second, RStudio, is an integrated development environment (IDE) that provides a more user-friendly interface for working with the R program. Throughout this course, you will learn to write and submit R code in RStudio to run statistical commands in the R program. After installing R & RStudio, you will run some simple commands to familiarize yourself with the basic features of the program and install two R packages.

  1. Follow the instructions at the link below to install the latest versions of R and RStudio on your personal Windows or Mac computer: https://www.datacamp.com/community/tutorials/installing-R-windows-mac-ubuntu. For more detailed instructions, check out Danielle Navarro’s videos for installing R and R Studio in Windows or on a Mac.

  2. Visit Antoine Soetewey’s blog (AS blog) entry at the link below, read the section titled “Main Components of RStudio,” and follow along in RStudio on your computer: https://towardsdatascience.com/how-to-install-r-and-rstudio-584eeefb1a41

  3. In RStudio, open an “R Markdown” file (File > New File > R Markdown…).
    1. Note: An R Script, which is the default file in RStudio, allows us to write and run code within R. However, an R Markdown file does this as well, while also permitting us to do so much more. For instance, you can write and edit text, write and run R code, and generate statistical results and plots directly in the RMarkdown file. You can even create entire books and webpages using R Markdown. In fact, this assignment was created using R Markdown!
    2. R Markdown is an essential tool for producing reproducible research because, with it, we can thoroughly document and simultaneously provide detailed explanations for all of our coding decisions in a project - from opening and manipulating data, to recoding and combining variables, to summarizing and analyzing data, to creating and modifying figures.
    3. We will start by simply opening and saving a new R Markdown file. For more detailed instructions, check out Danielle Navarro’s video on creating a new R Markdown file.
    4. Open a new R Markdown file using File > New File > R Markdown…