R Code
R code in the end-of-chapter sections
The 5th edition includes commented R code sections at the end of each chapter, under Chapter Summary. Each section contains the R code that replicates the analysis in the chapter. You can view the R code from all Chapter Summaries in the PDF below.
Browse the end-of-chapter R notesPDF · 842 KB▾
Your browser may not display the PDF inline. Open the PDF.
R scripts for over 100 examples from the book
For over one hundred examples from the book, there is an annotated PDF that walks through the R code and output, plus the raw R script to run yourself. Open a chapter to see its examples.
All files are available in the artofstat/RCode GitHub repository.
Chapter 11 example▾
Example 5: Google Analytics
Loading a .csv data file into R
Chapter 215 examples▾
Example 2: Shark Attacks
Proportions and Percentages
Example 3: U.S. Shark Attacks
Pie Charts and Bar Charts
Example 4: Sodium Content of Cereals
Dot Plot
Example 5: Sodium Content of Cereals
Stem-and-Leaf Plot
Example 6: TV Hours per Day
Histogram for a Discrete Variable
Example 7: Sodium Content of Cereals
Histogram for a Continuous Variable
Example 9: Warming Trends in New York City
Time Trend
Example 10: Sodium Content of Cereals
Mean and Median
Example 11: CO2 Pollution
Mean, Median, and Outliers
Example 12: Number of Children
Standard Deviation
Example 14: Student Heights
Empirical Rule
Example 15: Sodium Content of Cereals
Quartiles
Example 16: Sodium Content of Cereals
Box Plot
Example 17: Pollution Outliers
z-Scores
Example 19: Heptathlon
Standardizing
Chapter 310 examples▾
Example 2: Pesticide Residues
Explanatory and Response Variables
Example 3: Pesticide Residues
Graphing Conditional Proportions
Example 6: Internet and Facebook Use
Scatterplot
Example 8: Internet and Facebook Use
Correlation Coefficient
Example 10: Baseball Scoring
Regression Equation
Example 11: Palm Beach County
Residual
Example 12: Olympic High Jumps
Exploring Multivariate Relationships
Example 13: Global Warming
Extrapolation
Example 14: Education and Murder Rates
Influential Outliers
Example 15: Education and Murder Rates
Causation and Correlation
Chapter 42 examples▾
Example 4: Drawing Prize Winners
Simple Random Sample
Example 5: Auditing a School District
Selecting a Simple Random Sample
Chapter 52 examples▾
Example 2: Fairness of Rolling Dice
Randomness
Example 3: Multiple-Choice Pop Quiz
Sample Space
Chapter 610 examples▾
Example 3: Expected No. of Games
Mean of a Probability Distribution
Example 5: Risk Taking
Standard Deviation of a Probability Distribution
Example 7: Talk Times on Smartphones
Finding Normal Probabilities
Example 8: IQ Scores
Cumulative Probability and a Percentile Value
Example 9: Relative Standing on SAT
Using z-Scores to Find Percentiles
Example 10: Who Gets a B
Using z-Scores to Find Interval Probabilities
Example 11: Test Scores That Use Different Scales
Comparing z-Scores
Example 12: Speed Dating
Binomial Probabilities
Example 13: Testing for Gender Bias in Promotions
Binomial Distribution
Example 14: Checking for Racial Profiling
Normal Approximation of the Binomial Distribution
Chapter 73 examples▾
Example 3: Predicting the Election Outcome
Normal Shape of the Sampling Distribution
Example 5: Average Salary
Sampling Distribution of the Sample Mean
Example 6: Carbon Footprint of Sandwiches
Sampling Distribution of the Sample Correlation Coefficient
Chapter 810 examples▾
Example 2: A Wife's Career
Standard Error and Margin of Error
Example 3: Paying Higher Prices to Protect the Environment
Constructing and Interpreting a Confidence Interval
Example 4: Influenza Vaccine
99% Confidence Interval
Example 5: Exit Poll
Choosing a Sample Size
Example 8: Number of Hours Spent Watching Television
Standard Error and Confidence Interval for a Population Mean
Example 9: Buying on eBay
Using t-Distribution for a Confidence Interval for the Mean
Example 10: Finding Mean Education in South Africa
Finding n
Example 11: Flight Departure Delays
Percentile Confidence Interval
Example 12: Median Departure Delay
Confidence Interval for a Median
Example 13: Carbon Footprint
Confidence Interval for the Correlation
Chapter 93 examples▾
Example 4: Opinion on Fracking
Two-Sided Significance Test
Example 6: Cars Stopping for Pedestrians
Significance Test about a Population Proportion
Example 8: Weight Change
One-Sided Significance Test about a Mean
Chapter 109 examples▾
Example 3: Cancer Death Rates
Standard Error for the Difference of Two Sample Proportions
Example 4: Cancer Death Rates
Confidence Interval for the Difference of Two Proportions
Example 5: TV Watching
Significance Test Comparing Two Proportions
Example 7: Text with Graph
Standard Error for the Difference of Two Sample Means
Example 8: Text with Graph
Confidence Interval for the Difference of Two Means
Example 9: Driving Reaction Times
Significance Test Comparing Two Means
Example 10: Loan Amount and Terms
Bootstrap Distribution of the Difference Between Two Medians
Example 14: Diver Reaction Time
Comparing Means for Two Dependent Samples
Example 17: Speech Recognition Systems
McNemar's Test
Chapter 117 examples▾
Example 3: Happiness and Income
Chi-Squared Statistic
Example 4: Happiness and Income
Chi-Squared Distribution
Example 5: Headache from Flu Vaccine
Testing Homogeneity
Example 6: Mendelian Genetics
Testing Goodness of Fit
Example 9: Religiosity and Gender
Standardized Residuals
Example 10: Tea-Tasting Experiment
Fisher's Exact Test
Example 11: Hero or Criminal
Permutation Test
Chapter 129 examples▾
Example 2: The Strength Study
Scatterplot
Example 3: Maximum Bench Press
Regression Line
Example 5: Maximum Bench Press
Inference About the Slope
Example 6: Maximum Bench Press
95% Confidence Interval for a Slope
Example 10: The Strength Study
The Squared Correlation Coefficient
Example 12: College GPA
Standardized Residual
Example 13: College GPA
Using Residuals to Check Model Assumptions
Example 14: Maximum Bench Press
Residual Standard Deviation
Example 15: Maximum Bench Press
Confidence and Prediction Intervals
Chapter 1310 examples▾
Example 2: House Selling Prices
Multiple Regression
Example 3: House Selling Prices
Multiple Correlation Coefficient and R-Squared
Example 4: Athletes' Weight
Estimating Residual Standard Deviation
Example 5: Athletes' Weight
Overall F Test for Predictors
Example 6: Athletes' Weight
Hypothesis Test for the Multiple Regression Parameter Beta
Example 7: Athletes' Weight
Confidence Interval for Beta
Example 8: House Selling Prices
Histogram of Standardized Residuals
Example 9: House Selling Prices
Plotting Residuals
Example 10: House Selling Prices
Indicator Variables
Example 12: Travel Credit Cards
Logistic Regression Model
Chapter 147 examples▾
Example 3: Telephone Holding Times
One-Way ANOVA
Example 5: Number of Friends and Happiness
Fisher Test
Example 6: Number of Friends and Happiness
Tukey Test
Example 7: Telephone Holding Times
Regression Analysis
Example 9: Corn Yield
Testing the Main Effects
Example 10: Corn Yield
Regression Modeling
Example 11: Corn Yield
Testing for Interaction
Chapter 154 examples▾
Example 2: Tanning Studio Versus Lotion
P-Value for Wilcoxon Test
Example 3: Driving Reaction Times
Wilcoxon Test: Finding Ranks
Example 5: Frequent Dating and College GPA
Kruskal-Wallis Test
Example 8: GRE Test Scores
Wilcoxon Signed-Rank Test