#### Overview of this book

Data Science with R aims to teach you how to begin performing data science tasks by taking advantage of Rs powerful ecosystem of packages. R being the most widely used programming language when used with data science can be a powerful combination to solve complexities involved with varied data sets in the real world. The book will provide a computational and methodological framework for statistical simulation to the users. Through this book, you will get in grips with the software environment R. After getting to know the background of popular methods in the area of computational statistics, you will see some applications in R to better understand the methods as well as gaining experience of working with real-world data and real-world problems. This book helps uncover the large-scale patterns in complex systems where interdependencies and variation are critical. An effective simulation is driven by data generating processes that accurately reflect real physical populations. You will learn how to plan and structure a simulation project to aid in the decision-making process as well as the presentation of results. By the end of this book, you reader will get in touch with the software environment R. After getting background on popular methods in the area, you will see applications in R to better understand the methods as well as to gain experience when working on real-world data and real-world problems.
Simulation for Data Science with R
Credits
www.PacktPub.com
Preface
Free Chapter
Introduction
R and High-Performance Computing
The Discrepancy between Pencil-Driven Theory and Data-Driven Computational Solutions
Simulation of Random Numbers
Monte Carlo Methods for Optimization Problems
Probability Theory Shown by Simulation
Resampling Methods
Applications of Resampling Methods and Monte Carlo Tests
The EM Algorithm
Simulation with Complex Data
System Dynamics and Agent-Based Models
Index

## The basic EM algorithm

Before we give a formal definition of the EM algorithm, let's discuss some basics about likelihood and maximum likelihood. This is necessary in order to understand the definitions. After satisfying these prerequisites, we will give a formal definition of the EM algorithm according to the problems of missing values imputation. This is where the EM algorithm originates (Dempster, Laird, and Rubin 1977). We will see that the complex formal definition is easy to catch with an introductory example.

### Some prerequisites

Before we start with the EM algorithm we need to remind ourselves of some of the basics about likelihood and maximum likelihood.

For this we start by flipping a coin. If we have two possible outcomes, event A ('head') and A' ('tail'), our parameter of interest is , the probability of tossing the heads side of the coin. The probability of tossing the tails side of the coin is then .

Let's assume that we tossed the coin 10 times and the results were head, tail, head...