Introduction to R
About this document
I Getting started
1
Background
1.1
What is R?
1.2
What is RStudio?
1.3
Software installation
1.4
References
2
Working with R
2.1
Starting R
2.2
Storing data as objects
2.2.1
About variable names
2.3
Data structure I: The vector
2.3.1
Example: simple descriptives
2.3.2
Example: simple plots
2.4
Non-numeric data
2.4.1
Descriptives for grouping data
2.4.2
Character vector vs factor
2.5
General data in R
2.5.1
Extracting parts of a data frame
2.5.2
Example: descriptive statistics
2.6
Meta-activity
2.6.1
Getting help
2.6.2
Keeping track of objects
2.6.3
Finding files
2.6.4
Quitting R
3
Working in RStudio
3.1
Getting started
3.2
A quick tour of the GUI
3.2.1
Console and friends
3.2.2
RStudio Console specials
3.2.3
Navigating the pane layout
3.2.4
The default upper pane
3.2.5
The default lower pane
3.3
Source pane & scripting
3.3.1
From console to source
3.3.2
The Source pane file editor
3.3.3
Displays
4
A simple example
4.1
Data import
4.2
Analysis
4.2.1
Descriptives
4.2.2
Blood pressure by salt intake
4.2.3
Salt intake by sex
4.2.4
Save results
4.3
Turning it into a script
4.4
Exporting results
II Working with data
5
Data types and structures
5.1
Overview
5.1.1
Data examples
5.2
Background
5.2.1
Recap
5.2.2
Motivation
5.3
More about vectors
5.3.1
Vector calculations
5.3.2
Indexing vectors by position
5.4
Logical data
5.4.1
Definition
5.4.2
Logical expressions
5.4.3
Logical vectors
5.4.4
Logical vectors for indexing
5.5
More on rectangular data
5.5.1
Data frame
5.5.2
Matrix
5.5.3
Extensions & alternatives
5.6
Helpers:
subset
and
transform
5.7
Free-style data: lists
5.7.1
Background
5.7.2
Basic list
5.7.3
Named lists
5.7.4
Example: data frames
6
Processing data
6.1
Overview
6.2
Groupwise statistics
6.3
Using your own functions
6.4
Split - Apply - Combine
6.5
Merging data sets
6.6
Using pipelines
6.7
Next steps
7
The
tidyverse
7.1
Overview
7.2
Example: Using
dplyr
for data processing
7.2.1
Overview
7.2.2
Basic data operations
7.2.3
Groupwise data operations
7.3
tidyverse
vs base R?
III Estimation, inference, modelling
8
Basic Statistics & Epidemiology
8.1
Descriptive statistics
8.1.1
In base R
8.1.2
Using package
summarytools
8.2
Confidence intervals
8.3
Statistical tests
8.4
Epidemiological risk measures
8.5
Improved display of descriptives
8.6
Next steps
9
Linear regression
9.1
Overview
9.2
Background
9.3
Simple linear regression
9.3.1
Looking at the data
9.3.2
Fitting a linear regression model
9.3.3
Regression table and inference
9.3.4
Prediction
9.3.5
Diagnostics
9.3.6
Binary predictor and dummy coding
9.3.7
Nicer regression tables
9.4
Multiple linear regression
9.4.1
Multiple predictors
9.4.2
Categorical predictors with
\(>\)
2 levels
9.4.3
Interactions
9.4.4
Splines
9.4.5
Model comparisons
10
More regression models
10.1
Logistic regression
10.1.1
Ex.: Birthweight & uterine irritability
10.2
Survival regression
10.2.1
Survival data
10.2.2
Survival curves
10.2.3
Cox regression
10.3
Other models
IV Graphics
11
Graphics in base R
11.1
Overview
11.2
Base plots
11.3
Graphical parameters
Vectorized graphical parameters
11.4
Displaying and saving plots
11.4.1
Controlling a device through
par
11.5
High- vs. low-level plotting
11.6
Using colors
11.6.1
Specifying colors by name
11.6.2
Specifying colors mathematically
11.6.3
Using sets of colors: palettes
11.7
Next steps
12
ggplot2: an alternative plotting system
12.1
Introduction
12.1.1
Concepts & basic usage
12.1.2
Practicalities
12.2
More about aesthetics and geoms
12.2.1
Optional aesthetics
12.2.2
Multiple geoms
12.2.3
Using geom arguments
12.3
Splitting plots by sub-groups
12.4
Changing the default appearance
12.4.1
Scales
12.4.2
Fixing aesthetics
12.4.3
Themes
12.4.4
Other
12.5
Complex layering and annotation
12.6
Extensions
12.6.1
Assemble multi-panel plots: patchwork
12.6.2
Others
12.7
Next steps
V Organizing the analysis
13
Generating nice tables
14
Dynamic documents
15
Scripting and workflow
Published with bookdown
Introduction to R
15
Scripting and workflow
UNDER CONSTRUCTION