Getting Started

Before starting the lab:

  • Friday’s tutorial is the real “Intro to Coding” online lesson. You should have already completed it… but if you haven’t, do so now. It is well worth your time.
  • Watch the Orientation to R Studio and Lab 1 video.
    • It will help walk you through setting up and completing this lab and understanding R Studio, where you’ll do your work.
  • Open the website that hosts your R Studio (click the little (R) icon in the top right)
  • Make a new “Quarto Document”
  • Save it and give it a name (it will automatically add a .qmd suffix to your file name)
  • Set up the “front matter” (the weird cell at the top of every quarto file that is not R code) with your name and other metadata.
  • Create code cells
  • Write text in between cells
  • When done, you will “Render” the document, which will generate a pdf file
  • Download that pdf to your computer
  • Go to Gradescope, find the “Lab 1” assignment, and submit that pdf.

Lab Assignment

  • Each coding question should be answered in a separate code cell.
  • Before each of these cells, write some text to say “Question 2” or whatever.
  • For non-coding questions, just write text (not in a code cell)

Question 0

Edit the “front matter” (if you don’t know what that is, watch the video above):

  • Set the author to be your full name
  • Set a reasonable title for this lab.
  • Make sure the format is either pdf or typst

Question 1

Create a vector with the even integers between 1 and 10, as well as the number 99 (six elements in total). Save it into an object named vec.

Question 2

Find the sum of the elements in vec.

Question 3

Write code to find the biggest element in vec. (Hint: try the max function)

Question 4

Find the mean of the elements in vec and round it to the nearest integer.

Question 5

Write a single line of R code to answer this math question: if you take the number three and multiply it by one point two, then take the result and raise it to the power of (thirteen divided by six), what do you get?

Question 6 - UN Votes

Since its founding in 1946, the United Nation has regularly put forth resolutions that aim to express the will of its members. Impactful historical resolutions have involved the Declaration of Human Rights in 1948, a prohibition on the use of nuclear and thermonuclear weapons in 1968, and the establishment of a no-fly zone in Libya in 2011. After each resolution is proposed, it is voted on in a roll-call vote of the member nations.

The data set at hand, unvotes, contains the voting records of every nation in the UN from 1946 - 2019 on three different issues: Colonialism, Human Rights, and Nuclear Weapons.

We have created a data visualization that shows the proportion of “yes” votes over time on three different issues: Colonialism, Human Rights, and Nuclear Weapons. Modify it to compare the voting patterns of the United States, the United Kingdom, and one other country of your choosing (not Turkey). You do not need to do anything else for this question.

Part 6A

Quick notes:

  • You’re going to basically just copy/paste some code and run it.
  • The goal is just to get more familiar with R Studio, running code, submitting assignments.
  • You are not expected to understand this code yet! So don’t panic. You’ll only be asked to make a minor change.
    • It may seem daunting, but by the third week of class or so, you’ll understand this code! Take this as encouragement: many things are not nearly as hard as they seem at first…

Steps:

  • Create TWO new code cells, and copy/paste the blocks of code below into them.
  • Run each cell by pressing the “play” button

First cell:

{r}
#| message: false
library(tidyverse)
library(stat20data)

Second cell:

{r}
unvotes |>
  filter(country %in% c("United Kingdom", "United States", "Turkey")) |>
  group_by(country, year, issue) |>
  summarize(percent_yes = mean(vote == "yes")) |>
  ggplot(mapping = aes(x = year, y = percent_yes, color = country)) +
  geom_point(alpha = 0.4) +
  geom_smooth(method = "loess", se = FALSE) +
  facet_wrap(~issue) +
  labs(title = "Percentage of 'Yes' votes in the UN General Assembly",
       y = "Proportion Yes",
       x = "Year",
       color = "Country") +
  theme(legend.position = "bottom")

These should both run. If not, ask for help.

Part 6B

Edit that second code cell to swap out Turkey for another country of your choice. Rerun that cell to get a new plot.

Note: if you get an error, double check that you spelled the country correctly, used capitalization correctly, and didn’t remove any quotes or other pieces of code!

Part 6C

Formulate two claims about voting behavior that is supported by this graphic. Categorize each claim as begin a summary, generalization, causal claim, or prediction.

(Just type your response as text, not in a code cell)

Part 6D

What else would you like to learn about this data set or the context of voting at the United Nations that would allow you to make more informed, accurate, thoughtful, and effective claims? List three specific items.

(Just type your response as text, not in a code cell)

When you’re done

Create your submission document by hitting the “render” buttonmake sure it looks right, then download the pdf, go to gradescope, find the Lab 1 assignment, and submit that pdf (assigning questions to pages as requested).

Remember, the video from the top of the page walks you through this.