Statistical Programming Methods
1
Introduction
1.1
R
and
RStudio
1.1.1
Getting started with
R
1.1.2
Why
R
?
1.1.3
About RStudio
1.1.4
Conventions
1.1.5
Getting help
1.1.6
Installing packages
1.1.7
Additional References
1.2
Basic Probability and Statistics with
R
1.2.1
Simple calculations
1.2.2
Probability Distributions
1.2.3
Summary Statistics
1.3
Main References
1.4
License
I Foundation
2
RMarkdown
What is
literate
programming ?
What is
reproducible
research ?
2.1
Create an R Markdown file in RStudio
2.2
YAML Metadata
2.2.1
Subsections
2.3
Text
2.3.1
Headers
2.3.2
Lists
2.3.3
Hyperlinks
2.3.4
Blockquotes
2.3.5
Pictures
2.3.6
LaTeX
2.3.7
Cross-referencing Sections
2.3.8
Citations and Bibliography
2.3.9
Tables
2.3.10
Additional References
2.4
Code Chunks
2.4.1
Code Chunk Options
2.4.2
Comments
2.4.3
In-line R
2.4.4
Cache
2.5
Render Output
2.6
Addition Information
3
GitHub
3.1
Version Control
3.2
Git and GitHub
3.2.1
Git & RStudio Configuration
3.2.2
GitHub Setup
3.2.3
Connecting to RStudio
3.2.4
The basic workflow
3.2.5
Note about GitHub Student Developer Pack
3.3
Issues
3.4
Slack Integration
3.5
Additional References
II Introduction to R
4
Data Structures
4.1
Vectors
4.1.1
Type
4.1.2
Coercion
4.1.3
Subsetting
4.1.4
Attributes
4.1.5
Adding Labels
4.1.6
Working with Dates
4.1.7
Useful Functions with Vectors
4.1.8
Creating sequences
4.1.9
Example: Apple Stock Price
4.2
Matrices
4.2.1
Subsetting
4.2.2
Matrix Operators in R
4.2.3
Example: Summary Statistics with Matrix Notation
4.2.4
Example: Portfolio Optimization
4.3
Array
4.4
List
4.5
Dataframe
4.5.1
Combination
4.5.2
Subsetting
4.5.3
Example: Maps
5
Control Structures
5.1
Introduction
5.2
Selection control statements
5.2.1
Logical Operators
5.2.2
Selection Operators
5.2.3
Iterative Control Statements
5.3
Example: The Bootstrap
5.4
Example: Random Walk
5.5
Example: Monte-Carlo Integration
5.5.1
Introduction
5.5.2
Implementation
5.5.3
Application to the Normal Distribution
5.5.4
Application to Nonelementary Integrals
6
Functions
6.1
R functions
6.2
Creating functions in R
6.2.1
Function arguments
6.2.2
Function body
6.3
Function environment
6.4
Example (continued): Least-squares function
III Extending
7
Shiny Web Applications
7.1
Introduction
7.2
Step 1. Defining the R Code in the backend of the Shiny app
7.3
Step 2: User Interface (UI) / Frontend
Content Creation
Input Controls
Output Render Controls
7.4
Step 3: Implementing the backend (server)
7.5
Step 4: Connecting frontend and backend
7.6
Step 5: Customize
7.7
Example: Monte-Carlo Integration
7.8
Example: Buffon’s needle
7.8.1
Step 1: Backend
7.8.2
Step 2: Frontend
7.8.3
Step 3: Connecting frontend and backend
8
R Packages
8.1
Basic steps
8.1.1
Step 1: Create an “empty” R package
8.1.2
Step 2: Edit description file
8.1.3
Step 3: Move your R scripts into the R folder
8.1.4
Step 4: Documentation
8.1.5
Step 5: Test your package
8.1.6
Step 6: Add a “README.Rmd” file
8.1.7
Step 7: Create a github repo - possibly with the same name as package
8.2
Advanced
8.2.1
Adding a shiny app
8.2.2
Custom website
9
High performance computing
9.1
Rcpp: using C++ within R
9.1.1
Installation
9.1.2
A first program
9.1.3
Data structures
9.1.4
Control structures
9.1.5
Functions
9.1.6
Comparing with R
9.1.7
Example: Buffon’s needle (con’t)
9.1.8
C++ in an R package
10
Web scraping in
R
10.1
Web scraping overview
10.2
Denial-of-service (DoS), crawl rate, and robots.txt
10.3
Why web scraping could be bad?
10.4
How to avoid troubles?
10.5
Workflow
11
References
Appendix
A
Basic Probability and Statistics with
R
Published with bookdown
An Introduction to Statistical Programming Methods with R
Chapter 11
References