New mobile app: Resampling (Bootstrap Confidence Intervals)

The Art & Science of Learning from Data

The Art & Science of Learning from DataThe Art & Science of Learning from DataThe Art & Science of Learning from Data
Home
Web Apps
Mobile Apps
Datasets
R Code
YouTube
Errata

The Art & Science of Learning from Data

The Art & Science of Learning from DataThe Art & Science of Learning from DataThe Art & Science of Learning from Data
Home
Web Apps
Mobile Apps
Datasets
R Code
YouTube
Errata
More
  • Home
  • Web Apps
  • Mobile Apps
  • Datasets
  • R Code
  • YouTube
  • Errata

  • Home
  • Web Apps
  • Mobile Apps
  • Datasets
  • R Code
  • YouTube
  • Errata
Art of Stat

R Code

The new edition contains R code to replicate almost all analysis shown in the book. You can find the commented R-code at the end of each chapter, in the Chapter Summary pages. Below, you can view and download the R code instructions.

R Code by Chapter

See below for chapter by chapter R code

Download PDF

R-Code by Chapter

Chapter 1

  • Example 5: Google Analytics - Loading a .csv data file into R
    • Annotated PDF, Raw R-Code​

Chapter 2

  • Example 2: Shark Attacks - Proportions and Percentages
    • Annotated PDF, Raw R-Code
  • Example 3: U.S. Shark Attacks - Pie Charts and Bar Charts
    • Annotated PDF, Raw R-Code
  • Example 4: Sodium Content of Cereals - Dot Plot
    • Annotated PDF, Raw R-Code
  • Example 5: Sodium Content of Cereals - Stem-and-Leaf Plot
    • Annotated PDF, Raw R-Code
  • Example 6: TV Hours per Day - Histogram for a Discrete Variable
    • Annotated PDF, Raw R-Code
  • Example 7: Sodium Content of Cereals - Histogram for a Continuous Variable
    • Annotated PDF, Raw R-Code
  • Example 9: Warming Trends in New York City - Time Trend
    • Annotated PDF, Raw R-Code
  • Example 10: Sodium Content of Cereals - Mean and Median
    • Annotated PDF, Raw R-Code
  • Example 11: CO2 Pollution - Mean, Median, and Outliers
    • Annotated PDF, Raw R-Code
  • Example 12: Number of Children - Standard Deviation
    • Annotated PDF, Raw R-Code
  • Example 14: Student Heights - Empirical Rule
    • Annotated PDF, Raw R-Code
  • Example 15: Sodium Content of Cereals - Quartiles
    • Annotated PDF, Raw R-Code
  • Example 16: Sodium Content of Cereals - Box Plot
    • Annotated PDF, Raw R-Code
  • Example 17: Pollution Outliers - z-Scores
    • Annotated PDF, Raw R-Code
  • Example 19: Heptathlon - Standardizing
    • Annotated PDF, Raw R-Code
  • Exercise 2.11: Using the Alligator Food Choice  to demonstrate creating basic frequency tables (count and percentages) and Barcharts, Pareto Charts and Pie Charts
    • Annotated PDF, Raw R-Code

Chapter 3

  • Example 2: Pesticide Residues - Explanatory and Response Variables
    • Annotated PDF, Raw R-Code
  • Example 3: Pesticide Residues - Graphing Conditional Proportions
    • Annotated PDF, Raw R-Code
  • Example 6: Internet and Facebook Use - Scatterplot
    • Annotated PDF, Raw R-Code
  • Example 8: Internet and Facebook Use - Correlation Coefficient
    • Annotated PDF, Raw R-Code
  • Example 10: Baseball Scoring - Regression Equation
    • Annotated PDF, Raw R-Code
  • Example 11: Palm Beach County - Residual
    • Annotated PDF, Raw R-Code
  • Example 12: Olympic High Jumps - Exploring Multivariate Relationships
    • Annotated PDF, Raw R-Code
  • Example 13: Global Warming - Extrapolation
    • Annotated PDF, Raw R-Code
  • Example 14: Education and Murder Rates - Influential Outliers
    • Annotated PDF, Raw R-Code
  • Example 15: Education and Murder Rates - Causation and Correlation
    • Annotated PDF, Raw R-Code

Chapter 4

  • Example 4: Drawing Prize Winners - Simple Random Sample
    • Annotated PDF, Raw R-Code
  • Example 5: Auditing a School District - Selecting a Simple Random Sample
    • Annotated PDF, Raw R-Code

Chapter 5

  • Example 2: Fairness of Rolling Dice - Randomness
    • Annotated PDF, Raw R-Code
  • Example 3: Multiple-Choice Pop Quiz - Sample Space
    • Annotated PDF, Raw R-Code

Chapter 6

  • Example 3:  Expected No. of Games - Mean of a Probability Distribution
    • Annotated PDF, Raw R-Code
  • Example 5: Risk Taking - Standard Deviation of a Probability Distribution
    • Annotated PDF, Raw R-Code
  • Example 7: Talk Times on Smartphones - Finding Normal Probabilities
    • Annotated PDF, Raw R-Code
  • Example 8: IQ Scores - Cumulative Probability and a Percentile Value
    • Annotated PDF, Raw R-Code
  • Example 9: Relative Standing on SAT - Using z-Scores to Find Percentiles
    • Annotated PDF, Raw R-Code
  • Example 10: Who Gets a B - Using z-Scores to Find Interval Probabilities
    • Annotated PDF, Raw R-Code
  • Example 11: Test Scores That Use Different Scales - Comparing z-Scores
    • Annotated PDF, Raw R-Code
  • Example 12: Speed Dating - Binomial Probabilities
    • Annotated PDF, Raw R-Code
  • Example 13: Testing for Gender Bias in Promotions - Binomial Distribution
    • Annotated PDF, Raw R-Code
  • Example 14: Checking for Racial Profiling - Normal Approximation of the Binomial Distribution
    • Annotated PDF, Raw R-Code

Chapter 7

  • Example 3: Predicting the Election Outcome - Normal Shape of the Sampling Distribution
    •   Annotated PDF, Raw R-Code
  • Example 5: Average Salary - Sampling Distribution of the Sample Mean
    • Annotated PDF, Raw R-Code
  • Example 6: Carbon Footprint of Sandwiches - Sampling Distribution of the Sample Correlation Coefficient
    • Annotated PDF, Raw R-Code

Chapter 8

  • Example 2: A Wife's Career - Standard Error and Margin of Error
    • Annotated PDF, Raw R-Code
  • Example 3: Paying Higher Prices to Protect the Environment - Constructing and Interpreting a Confidence Interval
    • Annotated PDF, Raw R-Code
  • Example 4: Influenza Vaccine - 99% Confidence Interval
    • Annotated PDF, Raw R-Code
  • Example 5: Exit Poll - Choosing a Sample Size
    • Annotated PDF, Raw R-Code
  • Example 8: Number of Hours Spent Watching Television - Standard Error and Confidence Interval for a Population Mean
    • Annotated PDF, Raw R-Code
  • Example 9: Buying on eBay - Using t-Distribution for a Confidence Interval for the Mean
    • Annotated PDF, Raw R-Code
  • Example 10: Finding Mean Education in South Africa - Finding n
    • Annotated PDF, Raw R-Code
  • Example 11: Flight Departure Delays - Percentile Confidence Interval
    • Annotated PDF, Raw R-Code
  • Example 12: Median Departure Delay - Confidence Interval for a Median
    • Annotated PDF, Raw R-Code
  • Example 13: Carbon Footprint - Confidence Interval for the Correlation
    • Annotated PDF, Raw R-Code

Chapter 9

  • Example 4: Opinion on Fracking - Two-Sided Significance Test
    • Annotated PDF, Raw R-Code 
  • Example 6: Cars Stopping for Pedestrians - Significance Test about a Population Proportion
    • Annotated PDF, Raw R-Code
  • Example 8: Weight Change - One-Sided Significance Test about a Mean
    • Annotated PDF, Raw R-Code

Chapter 10

  • Example 3: Cancer Death Rates - Standard Error for the Difference of Two Sample Proportions 
    • Annotated PDF, Raw R-Code
  • Example 4: Cancer Death Rates - Confidence Interval for the Difference of Two Proportions
    • Annotated PDF, Raw R-Code
  • Example 5: TV Watching - Significance Test Comparing Two Proportions
    • Annotated PDF, Raw R-Code
  • Example 7: Text with Graph - Standard Error for the Difference of Two Sample Means
    • Annotated PDF, Raw R-Code
  • Example 8: Text with Graph - Confidence Interval for the Difference of Two Means
    • Annotated PDF, Raw R-Code
  • Example 9: Driving Reaction Times - Significance Test Comparing Two Means
    • Annotated PDF, Raw R-Code
  • Example 10: Loan Amount and Terms - Bootstrap Distribution of the Difference Between Two Medians
    • Annotated PDF, Raw R-Code
  • Example 14: Diver Reaction Time - Comparing Means for Two Dependent Samples
    • Annotated PDF, Raw R-Code
  • Example 17: Speech Recognition Systems - McNemar's Test
    • Annotated PDF, Raw R-Code

Chapter 11

  • Example 3: Happiness and Income - Chi-Squared Statistic
    • Annotated PDF, Raw R-Code
  • Example 4: Happiness and Income - Chi-Squared Distribution
    • Annotated PDF, Raw R-Code
  • Example 5: Headache from Flu Vaccine - Testing Homogeneity
    • Annotated PDF, Raw R-Code
  • Example 6: Mendelian Genetics - Testing Goodness of Fit
    • Annotated PDF, Raw R-Code
  • Example 9: Religiosity and Gender - Standardized Residuals
    • Annotated PDF, Raw R-Code
  • Example 10: Tea-Tasting Experiment - Fisher's Exact Test
    • Annotated PDF, Raw R-Code
  • Example 11: Hero or Criminal - Permutation Test
    • Annotated PDF, Raw R-Code

Chapter 12

  • Example 2:  The Strength Study - Scatterplot
    • Annotated PDF, Raw R-Code
  • Example 3: Maximum Bench Press - Regression Line
    • Annotated PDF, Raw R-Code
  • Example 5: Maximum Bench Press - Inference About the Slope
    • Annotated PDF, Raw R-Code
  • Example 6: Maximum Bench Press - 95% Confidence Interval for a Slope
    • Annotated PDF, Raw R-Code
  • Example 10: The Strength Study - The Squared Correlation Coefficient 
    • Annotated PDF, Raw R-Code
  • Example 12: College GPA - Standardized Residual
    • Annotated PDF, Raw R-Code
  • Example 13: College GPA - Using Residuals to Check Model Assumptions
    • Annotated PDF, Raw R-Code
  • Example 14: Maximum Bench Press - Residual Standard Deviation
    • Annotated PDF, Raw R-Code
  • Example 15: Maximum Bench Press - Confidence and Prediction Intervals
    • Annotated PDF, Raw R-Code

Chapter 13

  • Example 2:  House Selling Prices - Multiple Regression
    • Annotated PDF, Raw R-Code
  • Example 3: House Selling Prices - Multiple Correlation Coefficient and     R-Squared
    • Annotated PDF, Raw R-Code
  • Example 4: Athletes' Weight - Estimating Residual Standard Deviation
    • Annotated PDF, Raw R-Code
  • Example 5: Athletes' Weight - Overall F Test for Predictors
    • Annotated PDF, Raw R-Code
  • Example 6: Athletes' Weight - Hypothesis Test for the Multiple Regression Parameter Beta
    • Annotated PDF, Raw R-Code
  • Example 7: Athletes' Weight - Confidence Interval for Beta
    • Annotated PDF, Raw R-Code
  • Example 8: House Selling Prices - Histogram of Standardized Residuals
    • Annotated PDF, Raw R-Code
  • Example 9: House Selling Prices - Plotting Residuals
    • Annotated PDF, Raw R-Code
  • Example 10: House Selling Prices - Indicator Variables
    • Annotated PDF, Raw R-Code
  • Example 12: Travel Credit Cards - Logistic Regression Model
    • Annotated PDF, Raw R-Code

Chapter 14

  • Example 3: Telephone Holding Times - One-Way ANOVA
    • Annotated PDF, Raw R-Code
  • Example 5: Number of Friends and Happiness - Fisher Test
    • Annotated PDF, Raw R-Code
  • Example 6: Number of Friends and Happiness - Tukey Test
    • Annotated PDF, Raw R-Code
  • Example 7: Telephone Holding Times - Regression Analysis
    • Annotated PDF, Raw R-Code
  • Example 9: Corn Yield - Testing the Main Effects
    • Annotated PDF, Raw R-Code
  • Example 10: Corn Yield - Regression Modeling
    • Annotated PDF, Raw R-Code
  • Example 11: Corn Yield - Testing for Interaction
    • Annotated PDF, Raw R-Code

Chapter 15

  • Example 2: Tanning Studio Versus Lotion - P-Value for Wilcoxon Test
    • Annotated PDF, Raw R-Code
  • Example 3: Driving Reaction Times - Wilcoxon Test: Finding Ranks
    • Annotated PDF, Raw R-Code
  • Example 5: Frequent Dating and College GPA - Kruskal-Wallis Test
    • Annotated PDF, Raw R-Code
  • Example 8: GRE Test Scores - Wilcoxon Signed-Rank Test
    • Annotated PDF, Raw R-Code

 Copyright © 2022 Bernhard Klingenberg - All Rights Reserved. 


This website uses cookies.

We use cookies to analyze website traffic and optimize your website experience. By accepting our use of cookies, your data will be aggregated with all other user data and solely be used to analyze website traffic.

DeclineAccept