Foundations Of Statistics With R
Preface
0.1
Further reading
0.2
Installing R and RStudio
1
Data in R
1.1
Arithmetic and Variable Assignment
1.2
Help
1.3
Vectors
1.3.1
Creating vectors
1.4
Indexing Vectors
1.5
Data Types
1.5.1
Missing data
1.6
Data Frames
1.7
Reading data from files
1.8
Packages
1.9
Errors and Warnings
1.10
Useful Idioms
Vignette: Data science communities
Exercises
2
Probability
2.1
Probability basics
2.2
Simulations
2.2.1
Simulation with
sample
2.2.2
Using simulation to compute probabilities
2.2.3
Using
replicate
to repeat experiments
2.3
Conditional probability and independence
2.3.1
Independent events
2.3.2
Simulating conditional probability
2.3.3
Bayes’ Rule and conditioning
2.4
Counting arguments
Vignette: Negative Surveys
Exercises
3
Random Variables
3.1
Discrete random variables
3.2
Expected value
3.3
Binomial and geometric random variables
3.3.1
Binomial
3.3.2
Geometric
3.4
Continuous random variables
3.4.1
Expected value of a continuous random variable
3.5
Functions of a random variable
3.6
Variance and standard deviation
3.7
Normal random variables
3.7.1
Computations with normal random variables
3.7.2
Normal approximation to the binomial
3.8
Other special random variables
3.8.1
Poisson and exponential random variables
3.8.2
Uniform random variables
3.8.3
Negative binomial
3.8.4
Hypergeometric
3.9
Independent random variables
3.10
Summary
Vignette: An R Markdown Primer
Exercises
3.10.1
Using join to merge data frames
3.11
The apply family
Vignette: dplyr Murder Mystery
Vignette: Data and gender
Exercises
4
Data Visualization with ggplot
4.1
ggplot fundamentals
4.1.1
The grammar of graphics
4.1.2
Basic plot creation
4.1.3
Structured data
4.2
Visualizing a Single Variable
4.2.1
Histograms
4.2.2
Barplots
4.2.3
Density Plots
4.2.4
Boxplots
4.2.5
QQ plots
4.3
Visualizing Two or More Variables
4.3.1
Scatterplots
4.3.2
Line graphs and smoothing
4.3.3
Faceting
4.4
Customizing
4.4.1
Color
4.4.2
Labels and themes
4.4.3
Text annotations
4.4.4
Highlighting
Vignette: Choropleth Maps
Vignette: COVID-19
Exercises
5
Inference on the Mean
5.1
Sampling distribution of the sample mean
5.2
Confidence intervals for the mean
5.3
Hypothesis Tests of the Mean
5.4
One-sided Confidence Intervals and Hypothesis Tests
5.5
Simulations
5.5.1
Symmetric, light tailed
5.5.2
Skew
5.5.3
Heavy tails and outliers
5.5.4
Independence
5.5.5
Summary
5.6
Two sample hypothesis tests of
\(\mu_1 = \mu_2\)
5.7
Type II errors and power
5.7.1
Effect size
Vignette: A Permutation Test
Exercises
6
Rank Based Tests
6.1
One sample Wilcoxon Signed Rank Test
6.2
Two Sample Wilcoxon Tests
6.2.1
Paired Two Sample Test
6.2.2
Independent Two Sample Test
6.2.3
Ordinal Data
6.3
Power and Sample Size
6.3.1
Sample Size
6.4
Effect Size and Consistency
6.4.1
Effect Size
6.4.2
Consistency
6.5
Summary
Vignette: ROC Curves and the Wilcoxon Rank Sum Statistic
Exercises
7
Tabular Data
7.1
Tables and plots
7.2
Inference on a proportion
7.2.1
Exact binomial test
7.2.2
One sample test of proportions
7.3
\(\chi^2\)
tests
7.3.1
Given probabilities
7.4
\(\chi^2\)
goodness of fit
7.4.1
Simulations
7.5
\(\chi^2\)
test of independence
7.5.1
Two sample test for equality of proportions
7.6
Exact and Monte Carlo methods
Vignette: Tables
Exercises
8
Simple Linear Regression
8.1
Fitting a line
8.1.1
An introductory example
8.1.2
Least squares
8.1.3
Two examples of fitting lines
8.2
Correlation
8.3
Geometry of regression
8.4
Residual analysis
8.4.1
Linearity
8.4.2
Heteroscedasticity
8.4.3
Normality
8.4.4
Outliers and leverage
8.5
Inference
8.5.1
The summary command
8.5.2
Confidence Intervals for Parameters
8.5.3
Prediction Intervals for Response
8.5.4
Confidence intervals for Response
8.6
Simulations for Simple Linear Regression
8.6.1
Residuals
8.6.2
Prediction intervals
Vignette: Simple Logistic Regression
Exercises
9
Analysis of Variance and Comparison of Multiple Groups
9.1
ANOVA
9.1.1
Notation
9.1.2
The ANOVA model
9.1.3
Simulations
9.2
The ANOVA test
9.2.1
Example: THC Mice
9.2.2
Example: Humanization
9.3
Unequal variance
9.3.1
The oneway.test
9.3.2
Error simulations
9.4
Pairwise t-tests
9.4.1
Corrections and FWER
Vignette: Reproducibility
Exercises
10
Multiple Regression
10.1
Two explanatory variables
10.2
Categorical Variables
10.3
Variable Selection
Vignette: Data in Other Formats
Exercises
References
Published with bookdown
Foundations of Statistics with R
References