SMUC
Preface
1
Introduction
1.1
What is simulation
1.1.1
A simple simulation model
1.1.2
Why simulate?
1.2
Types of simulations
1.2.1
Stochastic vs deterministic simulations
1.2.2
Static vs dynamic simulations
1.2.3
Discrete vs continuous simulations
1.3
Elements of a simulation model
1.3.1
Objects of the model
1.3.2
Organization of entities and resources
1.3.3
Operations of the objects
1.4
The donut shop example
1.5
Simulating a little health center
1.6
What’s next
2
R programming
2.1
Why R?
2.2
Section Bibliography
2.3
R basics
2.3.1
Introduction to R
2.3.2
R History
2.3.3
R Advantages
2.3.4
What do we mean by R?
2.3.5
Console Mode
2.3.6
Getting help in R
2.3.7
Packages in R
2.3.8
Built-in R libraries
2.3.9
Contents of Packages
2.3.10
Installing Packages
2.3.11
Command line versus scripts
2.3.12
RStudio
2.3.13
Working Directory
2.3.14
Exercise: Set up your Working Directory
2.4
Expressions, Objects and Symbols
2.4.1
Some examples to start with
2.5
R as a Calculator
2.5.1
Complex numbers in R
2.5.2
Rounding
2.5.3
Arithmetics
2.5.4
Modulo and integer quotients
2.5.5
Operators
2.6
R Basic Data types
2.6.1
Integers
2.6.2
Integer vs. Double
2.6.3
Logical operators
2.6.4
Real numbers equality
2.6.5
Logical arithmetic
2.6.6
Characters
2.6.7
Characters: letters vectors
2.6.8
Characters: Pasting strings together
2.6.9
Characters: Extracting parts of strings
2.6.10
Characters: Counting things within strings
2.6.11
Characters: Upper- and lower-case text
2.6.12
Dates and times
2.6.13
Dates and times: Reading time data from files
2.6.14
Dates and times: The
strptime
function
2.6.15
Dates and times: Summary
2.6.16
Testing and coercing
2.6.17
Missing values, infinity and things that are not numbers
2.7
R Basic Data Structures
2.7.1
Vectors
2.7.2
Sequences
2.7.3
Vector and Subscripts
2.7.4
Vector Operations
2.7.5
Vector Functions
2.7.6
Sets
2.7.7
Factors
2.7.8
Matrices and Arrays
2.7.9
Matrices
2.7.10
Lists
2.7.11
Data Frames
2.8
Control Flow
2.8.1
Conditional statements
2.8.2
Loops
2.8.3
Functions
2.8.4
The
apply
Family
2.8.5
apply
Family Examples
2.9
The pipe operator
2.10
Plotting
3
Probability Basics
3.1
Set theory
3.1.1
Sample Spaces
3.2
Probability
3.2.1
Independence
3.2.2
Conditional Probabilities
3.2.3
Conditional Probabilities and Independence
3.3
Random Variables
3.3.1
Distribution Functions
3.3.2
Random variable types
3.3.3
Discrete Random Variables
3.3.4
Continuous Random Variables
3.3.5
Expectation of a Random Variable
3.3.6
Variance of Random Variables
3.3.7
Sample Mean and Sample Variance
3.3.8
Covariance between Random Variables
3.4
Discrete Random Variables
3.4.1
Probability Mass Function
3.4.2
Cumulative Distribution Function
3.4.3
Summaries
3.5
Notable Discrete Variables
3.5.1
Bernoulli Distribution
3.5.2
Binomial Distribution
3.5.3
Geometric distribution
3.5.4
Poisson Distribution
3.5.5
Some Examples
3.6
Continuous Random Variables
3.6.1
Probability Density Function
3.6.2
Cumulative Distribution Function
3.6.3
Summaries
3.7
Notable Continuous Distribution
3.7.1
Uniform Distribution
3.7.2
Exponential Distribution
3.7.3
Normal Distribution
3.8
The Central Limit Theorem
4
Random Number Generation
4.1
Properties of Random Numbers
4.2
Pseudo Random Numbers
4.3
Generating Pseudo-Random Numbers
4.3.1
Generating Pseudo-Random Numbers in R
4.3.2
Linear Congruential Method
4.4
Testing Randomness
4.4.1
Testing Uniformity
4.4.2
Testing Independence
4.5
Random Variate Generation
4.5.1
Random Generation in R
4.5.2
The Inverse Transform Method
4.5.3
Simulating Bernoulli and Binomial
4.5.4
Simulating Other Distributions
4.6
Testing Generic Simulation Sequences
4.6.1
Testing Distribution Fit
4.6.2
Testing Independence
5
Monte Carlo Simulation
5.1
What does Monte Carlo simulation mean?
5.2
A bit of history
5.3
Steps of Monte Carlo simulation
5.3.1
Estimating
\(\pi\)
: step 1
5.3.2
Estimating
\(\pi\)
: step 2
5.3.3
Estimating
\(\pi\)
: step 3
5.3.4
Estimating
\(\pi\)
: step 4
5.3.5
Estimating
\(\pi\)
: step 5
5.3.6
Estimating
\(\pi\)
: conclusions
5.4
The
sample
function
5.5
A game of chance
5.6
Takeaways
6
Monte Carlo methods for inference
6.1
Monte Carlo for estimation
6.1.1
Sam and Annie from ‘Sleepless in Seattle’
6.2
General Case with Standard Normal Distributions
6.3
The taxi problem (comparing estimators)
7
Discrete Events Simulation with R
7.1
simmer
terminology
7.2
The Trajectory Object
7.3
The Simulation Enviroment
7.4
Monitoring and data retrieval
7.5
simmer
Example
8
Model Building
8.1
A simple model
8.2
Models as functions
8.2.1
Model Functions with Multiple Explanatory Variables
8.3
Reading a model
8.4
Model Design
8.4.1
The data
8.4.2
The response variable
8.4.3
Explanatory variables
8.4.4
Model terms
8.4.5
Swimming world records
8.5
Model notation
8.6
Daily Flights Example
9
Exploratory Data Analysis
9.1
Data Cleansing
9.1.1
Handling missing values
9.1.2
Handling missing values (deletion)
9.1.3
Handling missing values (imputation)
9.1.4
Outliers
9.1.5
Obvious inconsistencies
9.1.6
Dummy variables
9.2
Exploratory Data Analysis
9.2.1
Some terminology
9.2.2
Variation
9.2.3
Covariation
9.2.4
Patterns and models
9.3
Cross Validation
9.3.1
Train/Test split cross validation
9.3.2
Leave one out cross validation (LOOCV)
9.3.3
K-fold cross validation
9.3.4
Repeated K-fold cross validation
9.4
Exercises Solutions
Published with bookdown
Simulation and Modeling to Understand the Change
2.2
Section Bibliography
Crawley, M. J. (2012). The R book. John Wiley & Sons.