Pembangkitan Bilangan Acak dan Resampling

Similar documents
1 Probability Distributions

Generating Random Numbers

Using R in 200D Luke Sonnet

Transformations of Standard Uniform Distributions

GOV 2001/ 1002/ E-2001 Section 3 Theories of Inference

Stat 451 Lecture Notes Simulating Random Variables

Distributions of Functions of Random Variables. 5.1 Functions of One Random Variable

Outline. Unit 3: Inferential Statistics for Continuous Data. Outline. Inferential statistics for continuous data. Inferential statistics Preliminaries

Chapter Learning Objectives. Probability Distributions and Probability Density Functions. Continuous Random Variables

Lecture 1: Random number generation, permutation test, and the bootstrap. August 25, 2016

Special Discrete RV s. Then X = the number of successes is a binomial RV. X ~ Bin(n,p).

Lab 4. Normal Random Variables

STAT 430/510 Probability

Practice Problems Section Problems

EE/CpE 345. Modeling and Simulation. Fall Class 10 November 18, 2002

Collaborative Statistics: Symbols and their Meanings

Simulating Random Variables

Continuous random variables

Statistics for scientists and engineers

R Functions for Probability Distributions

MAS223 Statistical Inference and Modelling Exercises

Lecture 09: Sep 19, Randomness. Random Variables Sampling Probability Distributions Caching. James Balamuta STAT UIUC

Fall 2017 STAT 532 Homework Peter Hoff. 1. Let P be a probability measure on a collection of sets A.

EE/CpE 345. Modeling and Simulation. Fall Class 9

GOV 2001/ 1002/ Stat E-200 Section 1 Probability Review

Introduction to Bayesian computation (cont.)

, find P(X = 2 or 3) et) 5. )px (1 p) n x x = 0, 1, 2,..., n. 0 elsewhere = 40

Chapter 3 Common Families of Distributions

Probability theory and inference statistics! Dr. Paola Grosso! SNE research group!! (preferred!)!!

CDA6530: Performance Models of Computers and Networks. Chapter 2: Review of Practical Random Variables

Generating pseudo- random numbers

Review for the previous lecture

REFERENCES AND FURTHER STUDIES

Chapter 3: Methods for Generating Random Variables

Probability Distributions Columns (a) through (d)

BMIR Lecture Series on Probability and Statistics Fall 2015 Discrete RVs

CDA5530: Performance Models of Computers and Networks. Chapter 2: Review of Practical Random Variables

Sampling Distributions of Statistics Corresponds to Chapter 5 of Tamhane and Dunlop

Stat 451 Homework 05 Solutions 1

Inverse Transform Simulations

1. The number of eggs laid by Green Sea Turtles is approximately normal with mean 100 and standard deviation 20.

Continuous Probability Distributions. Uniform Distribution

Lecture 2: Repetition of probability theory and statistics

R Based Probability Distributions

Statistical Computing Session 4: Random Simulation

STAT 514 Solutions to Assignment #6

This does not cover everything on the final. Look at the posted practice problems for other topics.

Chapter 4 Multiple Random Variables

Development for Learning Modules on Data Science for Energy and Buildings Catherine R Dressler

Will Murray s Probability, XXXII. Moment-Generating Functions 1. We want to study functions of them:

f (1 0.5)/n Z =

Dr. Junchao Xia Center of Biophysics and Computational Biology. Fall /13/ /12

Continuous Random Variables. and Probability Distributions. Continuous Random Variables and Probability Distributions ( ) ( ) Chapter 4 4.

Appendix F. Computational Statistics Toolbox. The Computational Statistics Toolbox can be downloaded from:

Topic 15: Simple Hypotheses

Subject CS1 Actuarial Statistics 1 Core Principles

GENERALIZED ERROR DISTRIBUTION

Question Points Score Total: 76

Probability and Distributions

Lecture 3. Biostatistics in Veterinary Science. Feb 2, Jung-Jin Lee Drexel University. Biostatistics in Veterinary Science Lecture 3

S6880 #7. Generate Non-uniform Random Number #1

Preliminary Statistics. Lecture 3: Probability Models and Distributions

Problem 1. Problem 2. Problem 3. Problem 4

Random Variables. Definition: A random variable (r.v.) X on the probability space (Ω, F, P) is a mapping

Random variables, distributions and limit theorems

Continuous Random Variables. and Probability Distributions. Continuous Random Variables and Probability Distributions ( ) ( )

Continuous random variables

Probability Distributions for Continuous Variables. Probability Distributions for Continuous Variables

Basic concepts of probability theory

Matematisk statistik allmän kurs, MASA01:A, HT-15 Laborationer

Statistics Ph.D. Qualifying Exam: Part I October 18, 2003

Introduction to R and Programming

Generation from simple discrete distributions

Review of Probabilities and Basic Statistics

Lecture 1 Bayesian inference

Introduction to Probability and Statistics (Continued)

Random variables. DS GA 1002 Probability and Statistics for Data Science.

Partial Solutions for h4/2014s: Sampling Distributions

Math/Stat 3850 Exam 1

STAT100 Elementary Statistics and Probability

ECE 650. Some MATLAB Help (addendum to Lecture 1) D. Van Alphen (Thanks to Prof. Katz for the Histogram PDF Notes!)

Stat 135, Fall 2006 A. Adhikari HOMEWORK 6 SOLUTIONS

z and t tests for the mean of a normal distribution Confidence intervals for the mean Binomial tests

Introduction to Probability and Statistics Slides 3 Chapter 3

6.1 Randomness: quantifying uncertainty

Gov Univariate Inference II: Interval Estimation and Testing

Applied Statistics and Probability for Engineers. Sixth Edition. Chapter 4 Continuous Random Variables and Probability Distributions.

Chapter 4 Continuous Random Variables and Probability Distributions

Continuous Probability Distributions. Uniform Distribution

Computer Science, Informatik 4 Communication and Distributed Systems. Simulation. Discrete-Event System Simulation. Dr.

Final Examination. STA 711: Probability & Measure Theory. Saturday, 2017 Dec 16, 7:00 10:00 pm

15 Discrete Distributions

Master s Written Examination

Chapter 5 continued. Chapter 5 sections

CDA6530: Performance Models of Computers and Networks. Chapter 2: Review of Practical Random

Basic concepts of probability theory

Random Variate Generation

Spring 2012 Math 541B Exam 1

Normal Distribution and Central Limit Theorem

Inference on distributions and quantiles using a finite-sample Dirichlet process

Transcription:

Pembangkitan Bilangan Acak dan Resampling τρ

Pembangkitan Bilangan Acak Resampling Jackknife Bootstrap Topics

Random Generators in R Distribution R name Additional Arguments beta beta shape1, shape2, ncp binomial binom size, prob Chauchy cauchy location, scale chi-squared chisq df, ncp exponential exp rate F f df1, df2, ncp gamma gamma shape, scale geometric geom prob hypergeometric hyper m, n, k log-normal lnorm meanlog, sdlog uniform unif min, max neg binomial nbinom size, prob normal norm mean, sd Poisson pois lambda Student s t t df, ncp

#pembangkitan bilangan acak x <- rnorm(10) #x~n(0,1) x1<- rnorm(10,3,2) #x1~n(3,sd=2) x2<- rbinom(10,1,0.4) #x2~bernoulli(0.4) #mencari nilai peluang suatu peubah acak p1 <- pnorm(1.645) #P(Z<1.645)=0.95 p2 <- pnorm(1.96) #P(Z<1.975)=0.975 p3 <- pnorm(-1.96) p4 <- pf(15,df1=10,df2=15) #mencari nilai peubah acak dgn diketahui peluang q1 <- qnorm(0.975) q2 <- qnorm(0.95,2,1) #X~N(2,1), P(X<x)=0.95 #mencari nilai density ##plot density normal a <- seq(-4,4,length=1000) da <- dnorm(a) plot(a,da)

Transformation Methods for Generating Random Numbers Direct Transformation ex : X~U 0,1 Y~U(a, b) Transformation Y = b 1 X + a Indirect Transformation The Inverse Transform Method The Acceptance-Rejection Method

Ilustrasi 1 Transformasi langsung Akan dibangkitkan 100 bilangan U(3,4) dari bilangan U(0,1) Misal X~U(0,1) akan diubah menjadi Y~U(3,4) Y = X+3 Maka X <- runif(100) #X~U(0,1) Y <- X+3

Indirect Transformation 1. The Inverse Transform Method If pdf r.v X f x and cdf r.v X F X X then F X X ~U(0,1) Algorithms for generating X with pdf f(x) : 1. Find F X X 2. U = F X X, U~U(0,1) 3. Find X = F X 1 (U) 4. So X have pdf f(x)

Ilustrasi 2 Simulate a random sample from the distribution with density f Y y = 3y 4 ; 1 y <

Jawaban 2 ##Y~ 3y^(-4)n --> F(y) = 1-y^(-3) ### Y = (1-U)^(-1/3) U <- runif(100) #U~U(0,1) Y1 <- (1-U)^(-1/3) #FUNGSI yy <- function(n,fyu) { u <- runif(n) y <- fyu(u) return(y) } fyu <- function(u) {y = (1-u)^(-1/3)} #1000 bil acak Y hasil <- yy(1000,fyu)

We need to generate (x, y) on this Accept x if (x, y) on the curve Reject x if (x, y) on the outside of curve Indirect Transformation (2) 2. The Acceptance-Rejection Method Basic idea : y = f(x) x criteria

Algorithms for generating X ~ pdf f(x) with x 0 < x < x 1 : 1. Generate x from U(x 0, x 1 ) 2. Find F so f x F for x 0 < x < x 1 3. Generate y 1 from U(0, F) 4. Find y 2 = f(x) 5. If y 1 y 2, accept x

Ilustrasi 3 Simulate a random sample from the distribution with density f Y y = 3y 2 ; 0 < y < 1 using Acceptance- Rejection Method

Jawaban 3 #ACCEPTANCE REJECTION METHOD #FUNGSI ar <- function(n,x0,x1,f) { xx <- seq(x0,x1,length=10000) F <- max(f(xx)) terima <- 0 iterasi <- 0 hasil <- numeric(n) while(terima<n) { x <- runif(1,x0,x1) y1<- runif(1,0,f) y2<- f(x) if(y1<=y2) { terima <- terima+1 hasil[terima]<-x } iterasi <- iterasi+1 } list(hasil,iterasi) } set.seed(10) f <- function(x) {3*x^2} yyy <- ar(10,0,1,f)

Resampling Alternative methods when we dealed small sample for taking inferences Jacknife Bootstrap Useful function in R Sample takes a sample of the specified size from the elements of x using either with or without replacement sample(x, size, replace = FALSE, prob = NULL)

Bootstrap Jacknife We have a sample y = (y 1,, y n ) to estimate θ with the estimator θ = f(y) The leave-one-out observation samples y (i) = (y 1,, y i 1, y i+1,, y n ) for i = 1,, n are called jacknife samples Jacknife statistics are θ (i) = f(y (i) ) Jacknife estimators θ jack = nθ n 1 θ. V jack θ = n 1 n n i=1 θ i θ. 2 θ (.) = 1 n n i=1 θ (i)

Ilustrasi 4 Using data BOD in R, find the jacknife estimator for the mean and SE of demand. Algorithm: 1. Compute θ = y 2. Take jacknife sample y i ; i = 1,, n 3. Compute jacknife estimator θ jack = nθ n 1 θ. = ny n 1 n V jack θ = n 1 n n i=1 y i 1 n n i=1 y i n i=1 2 y i

Jawaban 4 #JACKKNIFE data(bod) demand <- BOD$demand ##fungsi jackknife sjk <- function(data) { n <- length(data) sampel.j <- NULL for(i in 1:n) { sampel.j<-cbind(sampel.j,data[-i]) } return(sampel.j) } sj <- sjk(demand) ##jackknife statistics mean.sjk <- apply(sj,2,mean) ##jackknife estimator n <- length(demand) mean.jack <- n*mean(demand)-(n-1)*mean(mean.sjk) var.jack <- ((n-1)/n)*sum((mean.sjk-mean(mean.sjk))^2) se.jack <- sqrt(var.jack)

Jacknife Bootstrap We have a sample y = (y 1,, y n ) to estimate θ with the estimator θ = f(y) Steps Repeatedly simulate sample of size n from y y b (i) Compute statistic of interest θ b (i) = f(y b (i) ) Study behavior of statistic over N repetitions Bootstrap estimators N θ b = 1 N i=1 θ b (i) V b θ = 1 N 1 N i=1 θ b (i) θ b 2

Ilustrasi 5 Lakukan proses bootstrap pada data BOD untuk menduga rataan dan SE dari demand Algorithm: 1. Resample data with replacement, and the size of the resample must be equal to the size of the original data set. 2. Compute statistic μ 3. Repeat point 1 and 2, N times 4. Plot histogram of μ i ; i = 1,2,, N

Jawaban 5 #BOOTSTRAP bs <- function(data,ulangan) { n <- length(data) sb <- NULL for(i in 1:ulangan) { sb <- cbind(sb,sample(data,n,replace=t)) } msb <- apply(sb,2,mean) mean.b <- mean(msb) var.b <- var(msb) se.b <- sqrt(var.b) return(list(mean.b,var.b,se.b)) } hasil.b <- bs(demand,50)