Preface
Quickstart
Acknowledgements
1
Introduction to R
1.1
What is R?
1.2
Packages
1.2.1
Installing Packages
1.2.2
Using and Loading Packages
1.2.3
Required Packages
1.3
Using R
1.3.1
R as a Calculator
1.3.2
Assigning Variables
1.3.3
Rounding
1.3.4
Vectors
1.3.5
Plotting
1.3.6
Exercises
1.4
Documentation and Help
1.4.1
Online Help
1.4.2
Built-in Documentation and Help
2
Working with Data
2.1
Loading Data
2.1.1
The
Import Dataset
RStudio Button
2.1.2
The
read_csv()
Function (in the
readr
package)
2.1.3
The Working Directory
2.2
Exploring Data
2.2.1
Summary Functions
2.3
Plotting Data
2.3.1
Bar Plots
2.3.2
Histograms
2.3.3
Box Plots
3
Bivariate Data
3.1
Bivariate Plots
3.1.1
Box Plots
3.1.2
Scatter Plots
3.2
Bivariate Numerical Summaries
3.2.1
Covariance
3.2.2
Correlation
3.3
Simple Linear Regression
3.3.1
Plotting the Regression Line
3.3.2
Reverse Regression
4
Tabular Data
4.1
Two-Way Tables
4.1.1
Matrices
4.1.2
Example Dataset
4.1.3
Working with Two-Way Tables
4.1.4
Distributions in Two-Way Tables
4.1.5
Chi-squared Test
4.1.6
Exercises
4.2
Simpson’s Paradox
4.3
Sensitivity and Specificity
5
Simulation and Distributions
5.1
Basic Simulation
5.1.1
Flipping Coins
5.1.2
Rolling Dice
5.1.3
Random Seeds
5.1.4
Plotting Results
5.2
Discrete Distributions
5.2.1
The Bernoulli Distribution
5.2.2
The Binomial Distribution
5.2.3
The Poisson Distribution
5.3
Continuous Distributions
5.3.1
The Normal Distribution
5.3.2
The Uniform Distribution
5.3.3
The Exponential Distribution
5.4
Limit Theorems
5.4.1
The Law of Large Numbers
5.4.2
The Central Limit Theorem
6
Inference
Example Dataset: Theo’s Chocolate Bars
6.1
Confidence Intervals
6.1.1
Illustrating Confidence Intervals
6.2
Hypothesis Tests
6.2.1
Illustrating a Hypothesis Test
6.2.2
Hypothesis Tests for Means
6.2.3
Two-sample Tests
6.2.4
Tests for Proportions
6.2.5
Power
7
Regression
Example Dataset: U.S. Democratic Votes by State
7.1
Linear Regression
7.2
Checking Model Assumptions
7.3
Testing Individual Coefficients
7.4
Confidence and Prediction Intervals
8
Accessing Literature
8.1
Academic Search Engines
8.1.1
Google Scholar
8.1.2
Other Search Engines
8.2
Accessing Literature Through Paywalls
8.3
Literature Exercise
Locate Article
8.3.1
Critical Reading
9
Assignments
9.1
Running Code and Outliers
Introduction
9.1.1
Sample means
9.1.2
Absolute differences in sample means
9.1.3
Standard deviations
9.1.4
Absolute differences in standard deviations
9.1.5
Effect of the outliers
9.2
Simple Linear Regression
Dataset: Shark Pups
9.2.1
Summary Statistics
9.2.2
Computing the Regression Line
9.2.3
Fitting the Reverse Regression
9.2.4
Adding a New Point
9.3
Two-way Tables and Simpson’s Paradox
Dataset: Race and Capital Punishment
Working with the Combined Data
Conditioning on the Victim’s Race
Comparing Relative Risks by the Defendant’s Race
9.4
Design of Experiments
Locate Article
9.4.1
Critical Reading
9.5
Distributions and the CLT
9.5.1
The Poisson distribution
9.5.2
The Exponential distribution
9.5.3
The CLT, sample size, and asymptotic normality
9.6
Confidence Intervals and Hypothesis Tests
Dataset: Weather Data
9.6.1
Confidence intervals and hypothesis tests for means
9.6.2
Power Calculations
9.7
Regression Inference
Dataset: State-level Presidential Election Data
9.7.1
Testing Coefficients
Dataset: Florida County-level Presidential Election Data
9.7.2
Checking for an Outlier
Introduction to Statistics with R
6
Inference
Learning Objectives
Useful Functions