Simulations and programming in R. Why to simulate and program in R at all? ADVANTAGES –All R facilities can be used in the simulations Random number generators.

Slides:



Advertisements
Similar presentations
Special random variables Chapter 5 Some discrete or continuous probability distributions.
Advertisements

Chapter 3 Some Special Distributions Math 6203 Fall 2009 Instructor: Ayona Chatterjee.
Exponential Distribution. = mean interval between consequent events = rate = mean number of counts in the unit interval > 0 X = distance between events.
Acknowledgement: Thanks to Professor Pagano
Statistics review of basic probability and statistics.
Random Variable A random variable X is a function that assign a real number, X(ζ), to each outcome ζ in the sample space of a random experiment. Domain.
Lecture (10) Mathematical Expectation. The expected value of a variable is the value of a descriptor when averaged over a large number theoretically infinite.
Review of Basic Probability and Statistics
Probability and Statistics for Engineers (ENGC 6310) Review.
Simulation Modeling and Analysis
1 Review of Probability Theory [Source: Stanford University]
A random variable that has the following pmf is said to be a binomial random variable with parameters n, p The Binomial random variable.
Probability Distributions Random Variables: Finite and Continuous Distribution Functions Expected value April 3 – 10, 2003.
The moment generating function of random variable X is given by Moment generating function.
Continuous Random Variables and Probability Distributions
Normal distribution.
Week 51 Relation between Binomial and Poisson Distributions Binomial distribution Model for number of success in n trails where P(success in any one trail)
Chapter 21 Random Variables Discrete: Bernoulli, Binomial, Geometric, Poisson Continuous: Uniform, Exponential, Gamma, Normal Expectation & Variance, Joint.
4-1 Continuous Random Variables 4-2 Probability Distributions and Probability Density Functions Figure 4-1 Density function of a loading on a long,
Stevenson and Ozgur First Edition Introduction to Management Science with Spreadsheets McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies,
Probability Distributions 2014/04/07 Maiko Narahara
1 1. Observations and random experiments Observations are viewed as outcomes of a random experiment.
Prof. SankarReview of Random Process1 Probability Sample Space (S) –Collection of all possible outcomes of a random experiment Sample Point –Each outcome.
Moment Generating Functions 1/33. Contents Review of Continuous Distribution Functions 2/33.
Fundamental Graphics in R Prof. Ke-Sheng Cheng Dept. of Bioenvironmental Systems Eng. National Taiwan University.
Random variables Petter Mostad Repetition Sample space, set theory, events, probability Conditional probability, Bayes theorem, independence,
 1  Outline  stages and topics in simulation  generation of random variates.
Week 41 Continuous Probability Spaces Ω is not countable. Outcomes can be any real number or part of an interval of R, e.g. heights, weights and lifetimes.
Chapter 5 Statistical Models in Simulation
Tch-prob1 Chap 3. Random Variables The outcome of a random experiment need not be a number. However, we are usually interested in some measurement or numeric.
Winter 2006EE384x1 Review of Probability Theory Review Session 1 EE384X.
Random Variables & Probability Distributions Outcomes of experiments are, in part, random E.g. Let X 7 be the gender of the 7 th randomly selected student.
Continuous Probability Distributions  Continuous Random Variable  A random variable whose space (set of possible values) is an entire interval of numbers.
Statistics for Engineer Week II and Week III: Random Variables and Probability Distribution.
5-1 Business Statistics: A Decision-Making Approach 8 th Edition Chapter 5 Discrete Probability Distributions.
Moment Generating Functions
CIS 2033 based on Dekking et al. A Modern Introduction to Probability and Statistics Michael Baron. Probability and Statistics for Computer Scientists,
Lecture 19 Nov10, 2010 Discrete event simulation (Ross) discrete and continuous distributions computationally generating random variable following various.
Discrete Probability Distributions. Random Variable Random variable is a variable whose value is subject to variations due to chance. A random variable.
Probability & Statistics I IE 254 Summer 1999 Chapter 4  Continuous Random Variables  What is the difference between a discrete & a continuous R.V.?
1 Since everything is a reflection of our minds, everything can be changed by our minds.
STA347 - week 31 Random Variables Example: We roll a fair die 6 times. Suppose we are interested in the number of 5’s in the 6 rolls. Let X = number of.
Copyright ©2011 Pearson Education, Inc. publishing as Prentice Hall 5-1 Business Statistics: A Decision-Making Approach 8 th Edition Chapter 5 Discrete.
Distributions, Iteration, Simulation Why R will rock your world (if it hasn’t already)
Definition A random variable is a variable whose value is determined by the outcome of a random experiment/chance situation.
Stats Probability Theory Summary. The sample Space, S The sample space, S, for a random phenomena is the set of all possible outcomes.
Probability Refresher COMP5416 Advanced Network Technologies.
381 More on Continuous Probability Distributions QSCI 381 – Lecture 20.
Random Variable The outcome of an experiment need not be a number, for example, the outcome when a coin is tossed can be 'heads' or 'tails'. However, we.
STATISTICS Univariate Distributions Professor Ke-Sheng Cheng Department of Bioenvironmental Systems Engineering National Taiwan University.
School of Information Technologies Poisson-1 The Poisson Process Poisson process, rate parameter e.g. packets/second Three equivalent viewpoints of the.
Computing for Research I Spring 2013
4.3 More Discrete Probability Distributions NOTES Coach Bridges.
Sampling and estimation Petter Mostad
Statistics 2: generalized linear models. General linear model: Y ~ a + b 1 * x 1 + … + b n * x n + ε There are many cases when general linear models are.
Continuous Random Variables and Probability Distributions
Introduction Paul J. Hurtado Mathematical Biosciences Institute (MBI), The Ohio State University 19 May 2014 (Monday a.m.)
3.1 Statistical Distributions. Random Variable Observation = Variable Outcome = Random Variable Examples: – Weight/Size of animals – Animal surveys: detection.
Module 9.4 Random Numbers from Various Distributions -MC requires the use of unbiased random numbers.
PH24010 MathCAD Statistics, Random Numbers & Histograms.
4-1 Continuous Random Variables 4-2 Probability Distributions and Probability Density Functions Figure 4-1 Density function of a loading on a long,
Probability Distributions: a review
From the binomial to the normal
Chapter 4 Continuous Random Variables and Probability Distributions
Multinomial Distribution
Probability Review for Financial Engineers
Lecture 5 b Faten alamri.
Continuous Random Variable Normal Distribution
Chapter 3 : Random Variables
Each Distribution for Random Variables Has:
Presentation transcript:

Simulations and programming in R

Why to simulate and program in R at all? ADVANTAGES –All R facilities can be used in the simulations Random number generators Easy to create own R-functions –Simulation results are readily in R to be visualized and analyzed DISADVANTAGES –Loops may be slow Alternative solution –Compile C-code under R

Random numbers Random numbers are numbers drawn from a specific probability distribution Area of a bar approximates the probability of getting a number in that interval. These probabilities sum up to one.

Most common distributions CONTINUOUS Normal distribution: e.g. weight and length of an individual Exponential distribution: 'waiting time', e.g. lifetime of an individual Uniform distribution: flat distribution, i.e. values do not concentrate around some peak but are spread randomly within an interval DISCRETE Poisson distribution: number count, e.g. number of fish caught Binomial: 0 or 1, e.g. outcome of tossing coin, choice to metamorphose or not (Multinomial: same as binomial except more than two possible outcomes)

Random number generators Random number tools for normal distribution –rnorm() random number generator –dnorm() density function (probability function for discrete distributions) –pnorm() distribution function –qnorm() quantile function Similarly for binomial, Poisson, exponential, multinomial, uniform distributions… (and many others), e.g. –runif(), rexp(), rpois(), rbinom() -> DEMO 1

Creating an R-function “Name of the function” = function ( input parameters ){…} Procedures to be carried out All the input stuff needed for the procedures the function will perform DEMO 2

Basic programming loops in R Much of simulations is based on three loops: for ( ‘index’ in ‘index vector’ ) {…} –Repeats the procedure for all the indices while (‘a logical proposition’) {…} –Repeats the procedure until the logical proposition is FALSE if (‘a logical proposition’) {…} else {…} –If the condition holds, does the first procedure, otherwise the second. DEMO 3