Introduction and orientation

Jacob M. Montgomery
Washington University in St. Louis
Department of Politcal Science

2020

Introduction

• Who are we?
• Our goals
• Tips and suggestions
• Syllabus
• Getting started in R

Introductions

• Who are you?
• What are you going to study?
• What is the last math class you took?
• What was the most exciting/fun thing you did this summer?

Orientation

Class discussion

• What is data science?
• What is team-based learning?
• How does this relate to politics/policy/political science?

1.1 What the …. ?

You can install R from: http://cran.r-project.org/bin/

• Works on all platforms
• Unless you are compiling your own software (e.g., Ubuntu), you will always want the ‘binary’ distribution of software.
• Helpful videos in the coursebook to get you started.

But you should go ahead and also install Rstudio: https://rstudio.com/

• Has great features for building code.
• Additional functionality for making R work nicely with other programs/languages.
• Much mor on this later.

1.2 The working environment for R/RStudio

• It is possible to do some things using the menus, but we will mostly use command line entry.
• We will also create scripts that can be run all at once, or using shortcut keys from the script editor.
• Let’s open up R studio and look around.

Now make a new script and save it to an appropriate directory. Add the following, save, and run.

print("Hello world")
## [1] "Hello world"

Highlight the line and hit command-R (in a Mac) to run without menus.

1.3: Big picture orientation

• Everything in R is object oriented. Data, functions, inputs and outputs will all be data objects.
• R is case sensitive. For that matter, it is also spelling sensitive.
• R is an open-source platform that comes with many basic functions.
• Lots and lots of people use R, write handouts for class, write websites, etc. Google is your friend (and your enemy).

1.4: R as a calculator

5+4 # Addition
## [1] 9
6-3  #Subtraction
## [1] 3
34 / 6 # Division
## [1] 5.666667
5 * 3 # Multiplication
## [1] 15
5^4 # Exponents
## [1] 625
625^(1/4) # More exponents
## [1] 5
11%%2 # modular arithmatic (11 mod 2)
## [1] 1
31 %/% 7 # The integer part of a fraction
## [1] 4

R comes with a number of constants pr-stored that you can use

6.25 # numbers
pi # And a few others
NA # Missing value
NULL # Nothing.
0/0 # NaN means "Not a number"
1/0 # Inf means infinity

R follows the order of operations (Please Excuse My Dear Aunt Sally). What will these evaluate to?

2*(3-4)+2
2*(3-4)+2*(4 + 3)^(1/3)

1.4: Objects and named storage

What if we wanted to calculate the % of eligible voters who turnout in the 06 elections in Alaska. (Data source: http://www.electproject.org/2006g)

• The <- operator asigns a value to that object. You can also use “=” mostly.
turnout.ak<-238307/496387 # Turnout divided by voting age population
• The ‘show(object)’ will be called if you just type the name
turnout.ak 
## [1] 0.4800831

Named storage also lets you handle each piece separately

total.votes.ak <-  238307
voting.age.population.ak <- 496387
turnout.ak
## [1] 0.4800831