Introduction to Monte Carlo Simulation (using Crystal...

Preview:

Citation preview

Introduction to Monte Carlo Simulation

(using Crystal Ball)

김 호

서울대학교 보건대학원

Motivation

• If X ~ N (m1, s12), Y ~ N (m2, s2

2 ),

then what is the distribution of X+Y ?

Statistical theory tells that

X+Y ~ N (m1+ m2, s12+s2

2 )

if X and Y are independent.

How to check this by simulation ?

data one ;do i=1 to 500;x=rannor(i)*10+ 5 ;y=rannor(i)*5+ 9 ;z=x+y ;output ;end;run;

proc univariate ;var x y z ;histogram x y z /normal (mu=est sigma=est)midpoints = -30 to 45 by 5;;run;

평균 표준편차

X 4.41 10.06

Y 9.33 5.16

Z 13. 11.47

평균 표준편차

X 4.41 10.06

Y 9.33 5.16

Z 13. 11.47

결과 이론상

약간 다르다 ?

하나의 처방 --- 반복을 한다.

평균 표준편차

X 5 10

Y 9 5

Z 14 15

data old ;run;%macro sim ;%do i=0 %to 100 ;%let j=&i*500 ;

data one ;do k=&j to &j+500;x=rannor(k)*10+ 5 ;y=rannor(k+500)*5+ 9 ;z=x+y ;output ;end;run;

proc means noprint ;var x y z ;output out=p mean=mx my mz ;run;data old;set old p ;run;%end;%mend;

%sim;

proc means data=old;var mx my mz;run;

The MEANS Procedure

Variable N Mean Std Dev

-------------------------------------------------------

mx 101 4.9654381 0.3952677 (5) (4.41)

my 101 8.9910255 0.2253016 (9) (9.33)

mz 101 13.9564636 0.4498997 (14) (13)

---------------------------------------------------------

• We know the distribution of X+Y from statistical theory.

• How about the other forms like (10*X**2+Y*30+20) / sin(X+Y) We can do some mathematics (mainly approximation)

• More practical way is computer simulation

data one ;do k=1 to 500;x=rannor(k)*10+ 5 ;y=rannor(k+500)*5+ 9 ;z=(10*X**2+Y*30+20) / sin(X+Y) ;output ;end;run;

proc univariate ;var z ;histogram z /cfill=blue;run;

Crystal Ball TutorialFutura Example

1 Start Crystal Ball

2 Open the FUTURA APARTMENT spread sheet from the Crystal Ball Example Folder

3 Choose Run from the Run menu on the menu bar

4 Choose stop from the Run menu on the forecast chart

5 Press the Tab key twice or select the left edit box on the forecast window

6 Type 0 and press the Enter key

Crystal Ball TutorialVision Research Example

• A business situation with uncertainty

• Development of new drug designed to correct nearsightedness

• Should complete development and test

• Should be approved by FDA

• Drug effect is marginal

• Use CB to decide whether to scrap or proceed…

1 Open the VISION RESEARCH spread sheet from the Crystal Ball Example Folder

* Defining Assumptions

1 Click cell C5

2 Choose Define Assumptions from the cell menu

3 Click the Uniform distribution

4 Min=3, Max=5, enter

* Defining Market Cost: Triangular Dist

1 Click cell C6

2 Choose Define Assumptions

3 Click Triangular Dist

4 Click OK

5 Min=12, likeliest=16, Max=18

* Defining Patients Cured: Binomial Dist

1 Click cell C10

2 Choose Define Assumptions

3 Click Binomial Dist

4 Click OK

5 Prob=.25, Trials=100

• Defining Growth Rate: Customer Dist

1 Click cell C15

2 Define Assumptions

3 Custom Dist

4 Value=0%, Value2=5%, Prob=75%

5 Click enter

For a Second Range

6 Value=-15%, Value2=-5%, Prob=25%

7 Click enter

• Defining market penetration: Normal

1 Cell C19

2 Define Assumptions -> Normal

3 Mean=8%, SD=2%

4 5% in the left end-point grabber box

• Defining Forecasts

1 C21=C16*C19*C20

2 Define Forecast

3 unit=millions , Display Window OK

* Calculate Net Profit

4 C23 = IF(C11,C21-C7,-C4-C5)

If the FDA approves the drug (C11 is true) then, then then calculate net profit by subtracting total costs(C7) from gross profit(C21).

However, if the FDA does not approve the drug(C11 is false), then calculate net profit by reducing both development costs (C4) and testing cost(C5) incurred to date.

5 Define Forecast

6 unit=millions, Display Window OK

* Running a simulation

1 Run Preferences

2 Max # of trials=500, Initial seed=999

Click Use Same Sequence of Random Numbers

• Practice Routine

1 Choose Run from the run menu

2 Choose Stop from the run menu

3 Choose Continue from the run menu

• View the forecast Charts

1 Click on the Gross Profit Run Preferences

2 Click Open All Forecast

3 Choose Continue from the run menu

• Defining the Certainty Level

1 Range minimum=0, Press enter

2 Range minimum=2, Press enter

3 Range minimum=4, Press enter

C23 = IF(C11,C21-C7,-C4-C5)

C23 = IF(C11,C21-C7,-C4-C5)

Recommended