You are on page 1of 19

UNIVERSITI TUNKU ABDUL RAHMAN

FACULTY OF SCIENCE

UDPS3213 STATISTICAL SIMULATION


Academic Year 2019/2020
May 2019 Trimester

Assignment

Lecturer’s Name : Dr. Lim Huai Tein

Student Name Student ID


Lim Xue Qi 16ADB03823

Loo Xin Yi 16ADB04027


Question 1
a) Uniform distribution with parameters a=2 and b=8

1
{
f ( x )= b−a
,a≤ x≤b
0 ,otherwise
x
1
F ( x )=∫ dy
a b−a

y x
¿ [ ]
b−a a

x −a
¿
b−a

0 , x <a
F ( x )= x
{
−a
b−a
,a ≤ x ≤ b
1 , x >b

u=F ( x )
x −a
¿
b−a

x=a+ ( b−a ) u

a=2 ; b=8

SAS code:
Data Q1a;
a=2;
b=8;
Do i=1 to 1000;
u=ranuni(55555);
x=a+(b-a)*u;
output;
End;
run;

proc means;
var x;
run;
Analysis Variable : x
N Mean Std Dev Minimum Maximum
1000 5.0038915 1.7299146 2.0003241 7.9972109

Simulated mean and variance:


E ( X ) =5.0038915
2
Var ( X )=( 1.7299146 ) =2.99260452

Exact mean and variance:


a+b
E ( X )=
2
2+ 8
¿
2
¿ 5.0000

( b−a )2
Var ( X )=
12

( 8−2 )2
¿
12
¿ 3.0000

∴ The simulated mean and variance are almost the same as the exact answer.
b) Exponential distribution with mean 0.5.

f ( x )= λ e−λx , x>0
x
F ( x )=∫ λ e−λy dy
0
x
¿ [ −e− λy ] 0
¿ 1−e−λx , x >0

u=F ( x )
¿ 1−e−λx
1
x=−
λ()ln ( 1−u )

u U ( 0 ,1 ) ∧( 1−u ) U ( 0 ,1 ) . Replaced ln ( 1−u ) with ln ( u )


1
mean=0.5=
2
1 1
=
λ 2
λ=2

SAS code:
Data Q1b;
lamda=2;
Do i=1 to 1000;
u=ranuni(55555);
x=-(1/lamda)*log(u);
output;
End;
run;

proc means;
var x;
run;

Analysis Variable: x
N Mean Std Dev Minimum Maximum
1000 0.5000478 0.5052911 0.000232481 4.9130612
Simulated mean and variance:
E ( X ) =0.5000478
2
Var ( X )=( 0.5052911 ) =0.255319096

Exact mean and variance:


1
E ( X )=
λ
1
¿
2
¿ 0.5000
1
Var ( X )=
λ2
1
¿
22
¿ 0.2500

∴ The simulated mean and variance are almost the same as the exact answer.
Question 2
π π
4 4

θ=∫ ∫ x2 y 2 sin ( x + y ) ln ( x + y ) dxdy


0 0

2 2
g ( xy )=x y sin ( x+ y ) ln ( x + y )

x−0 4 x π
Let a= = → x= a
π π 4
−0
4
da 4 π
= → dx= da
dx π 4

y−0 4 y π
Let b= = → y= b
π π 4
−0
4
db 4 π
= → dy= db
dy π 4

Let g( xy )=x 2 y 2 sin ( x+ y ) ln ( x + y )


π π
4 4 1 1

∫∫ g(xy ) dxdy=∫ ∫ g(( π4 a)( π4 b)) π4 da π4 db


0 0 0 0

1 1
π π π 2
¿ ∫ ∫ g((
0 0 4
a)( b))
4 4() dadb

1 1
π π π 2
∴ θ=∫ ∫ g
0 0
( a∙ b
4 4 4 )( )
dadb

π 2 π π
¿∑
k () [
4
∙ g a∙ b
4 4 ]
i=1 k

SAS code:
Data Q2;
k=2000;
Pi=constant("pi");
Do i=1 to k;
a=ranuni(55555);
b=ranuni(55555);
x=Pi/4*a;
y=Pi/4*b;
ans=((Pi/4)**2)*((x**2)*(y**2)*sin(x+y)*log (x+y));
output;
End;
run;

proc means;
var ans;
run;

Analysis Variable : ans


N Mean Std Dev Minimum Maximum
2000 0.0042366 0.0132692 -0.0025319 0.0990287

Simulated mean and variance:

E ( X ) =0.0042366

Var ( X )=( 0.0132692)2=0.000176071


Question 3

f ( x )= 2 x , 0≤ x ≤ 1
{0 , otherwise

g ( x )=1 ,0 ≤ x ≤ 1
f (x)

2 .0

1 .5
g( x )
1 .0

0 .5

0 .2 0 .4 0 .6 0 .8 1 .0

f (x )
=2 x
g (x)

f ( x)
Since is a straight line, based on the graph, we can see that it does not consist of any
g(x)
inflation point. Thus, differentiation is not necessary to find the maximum point. By taking
x=1, it gives the highest possible c which is c=2. Note that c is a scalar greater than 1. cg(x) is
proposal distribution and f(x) is target distribution.

2 .0
cg (x)
f (x)
1 .5

1 .0

0 .5

0 .2 0 .4 0 .6 0 .8 1 .0
f x
c=max ( (( )) )
gx

¿ max ( 21x ) ,0 ≤ x ≤ 1
f ( x)
=x
c g( x )

Thus, the rejection procedure is as follows:

Step 1: Generate random number U 1 and U 2.

Step 2: If U 2 ≤U 1, stop and set X =U 1 , otherwise return to step 1.


Question 4
Data original;
input number;
datalines;
81
32
49
54
44
74
98
42
54
51
69
49
43
5
1
5
35
55
4
20
25
34
31
65
46
92
2
4
41
38
;

Data bootsamp;
Do sampnum=1 to 200;
Do i=1 to nobs;
x=round(ranuni(55555)*nobs);
set original
nobs=nobs
point=x;
output;
End;
End;
stop;
run;

ods trace on/listing;


proc means data=bootsamp;
var number;
class sampnum;
ods output Summary=mean_output;
run;
ods trace off;

proc means data=mean_output;


var number_Mean;
run;

Data msecalc;
no=200;
xbar=41.4;
msesum=0;
Do i=1 to no;
set mean_output;
if _n_=1 then xbarest=number_Mean;
msesum=msesum+(xbarest-xbar)**2;
End;
mse=msesum/no;
run;
proc print data=msecalc;
var mse;
run;

proc sort
data=mean_output;
by number_Mean;
run;

Data ci_perc;

set mean_output end=eof;


retain conf_lo conf_hi;
if _n_= 5 then conf_lo=number_Mean;
if _n_= 195 then conf_hi=number_Mean;
if eof then output;
keep conf_lo conf_hi;
run;
proc print data=ci_perc;
run;
Analysis Variable: number
sampnum N Obs N Mean Std Dev Minimum Maximum
1 30 30 41.2666667 27.8678326 2.0000000 98.0000000
2 30 30 43.5000000 23.1513014 1.0000000 98.0000000
3 30 30 37.8666667 21.3100807 1.0000000 81.0000000
4 30 30 41.3666667 26.2868570 1.0000000 92.0000000
5 30 30 52.9000000 33.2040193 4.0000000 98.0000000
6 30 30 36.9666667 21.3984907 2.0000000 74.0000000
7 30 30 41.5000000 25.0265376 4.0000000 98.0000000
8 30 30 49.7666667 21.0281967 5.0000000 98.0000000
9 30 30 43.6000000 27.3780682 1.0000000 92.0000000
10 30 30 40.2333333 25.0553640 1.0000000 98.0000000
11 30 30 44.8000000 25.3817746 4.0000000 98.0000000
12 30 30 50.6333333 21.9065151 2.0000000 98.0000000
13 30 30 49.3666667 22.8540849 1.0000000 98.0000000
14 30 30 40.3000000 19.3749750 2.0000000 74.0000000
15 30 30 40.9666667 23.0239505 1.0000000 98.0000000
16 30 30 49.3000000 28.7031778 4.0000000 98.0000000
17 30 30 41.3000000 26.7918541 1.0000000 92.0000000
18 30 30 33.2000000 24.2706009 1.0000000 92.0000000
19 30 30 40.8000000 26.0151150 2.0000000 98.0000000
20 30 30 37.1000000 23.0566768 4.0000000 98.0000000
21 30 30 39.9666667 22.9849776 4.0000000 81.0000000
22 30 30 45.5000000 25.2719689 2.0000000 92.0000000
23 30 30 44.5333333 23.6172546 2.0000000 92.0000000
24 30 30 40.9000000 24.5122770 1.0000000 98.0000000
25 30 30 44.2000000 28.3346991 1.0000000 98.0000000
26 30 30 41.1666667 26.1125988 1.0000000 98.0000000
27 30 30 41.6666667 25.9898300 2.0000000 98.0000000
28 30 30 42.6000000 27.0779208 1.0000000 92.0000000
Analysis Variable: number
sampnum N Obs N Mean Std Dev Minimum Maximum
29 30 30 41.0333333 20.9851891 4.0000000 92.0000000
30 30 30 37.5666667 24.6837701 1.0000000 98.0000000
31 30 30 35.9333333 26.0436415 1.0000000 98.0000000
32 30 30 46.2666667 29.8651375 4.0000000 98.0000000
33 30 30 41.0000000 26.6069734 1.0000000 92.0000000
34 30 30 43.1666667 23.0083693 2.0000000 98.0000000
35 30 30 47.5000000 30.8620401 1.0000000 98.0000000
36 30 30 49.3666667 30.0866374 4.0000000 98.0000000
37 30 30 38.1666667 26.1059953 1.0000000 81.0000000
38 30 30 43.9666667 31.1309618 2.0000000 98.0000000
39 30 30 47.2666667 32.7960609 1.0000000 98.0000000
40 30 30 39.4000000 29.1755684 1.0000000 98.0000000
41 30 30 39.0000000 27.0987975 2.0000000 98.0000000
42 30 30 38.8333333 25.4098587 1.0000000 98.0000000
43 30 30 36.2666667 27.2952356 1.0000000 98.0000000
44 30 30 41.6666667 23.9846694 1.0000000 98.0000000
45 30 30 41.8666667 25.1639224 1.0000000 98.0000000
46 30 30 35.0000000 26.5836351 1.0000000 92.0000000
47 30 30 33.7666667 23.4324905 1.0000000 81.0000000
48 30 30 44.3000000 27.3926116 2.0000000 98.0000000
49 30 30 41.5333333 28.8667967 1.0000000 98.0000000
50 30 30 38.8666667 25.3237429 2.0000000 81.0000000
51 30 30 48.4000000 28.2166495 1.0000000 98.0000000
52 30 30 46.1666667 28.7042990 1.0000000 98.0000000
53 30 30 37.7666667 26.4584037 1.0000000 98.0000000
54 30 30 44.9666667 23.6679375 2.0000000 81.0000000
55 30 30 33.8666667 22.3263156 1.0000000 92.0000000
56 30 30 42.5666667 28.7110256 1.0000000 98.0000000
57 30 30 39.1333333 28.8393091 1.0000000 98.0000000
58 30 30 39.1333333 28.2680926 1.0000000 92.0000000
59 30 30 48.0666667 25.1956938 1.0000000 98.0000000
60 30 30 45.1666667 24.0632548 1.0000000 92.0000000
Analysis Variable: number
sampnum N Obs N Mean Std Dev Minimum Maximum
61 30 30 36.8333333 24.5259656 1.0000000 98.0000000
62 30 30 32.9000000 25.7311699 1.0000000 98.0000000
63 30 30 49.6666667 24.4784681 5.0000000 98.0000000
64 30 30 43.8666667 29.7584915 1.0000000 98.0000000
65 30 30 38.2666667 24.5060631 1.0000000 74.0000000
66 30 30 42.0666667 33.1204004 1.0000000 98.0000000
67 30 30 40.1000000 22.2592096 1.0000000 92.0000000
68 30 30 32.8000000 23.0208301 2.0000000 92.0000000
69 30 30 33.6333333 23.4189480 2.0000000 74.0000000
70 30 30 31.1333333 23.5617067 2.0000000 92.0000000
71 30 30 35.7666667 30.9021630 2.0000000 98.0000000
72 30 30 44.5666667 27.5301507 2.0000000 98.0000000
73 30 30 41.2000000 29.4833676 1.0000000 98.0000000
74 30 30 54.2333333 29.9478666 1.0000000 98.0000000
75 30 30 43.1333333 29.0561090 1.0000000 98.0000000
76 30 30 39.1333333 27.2557913 1.0000000 98.0000000
77 30 30 50.3666667 27.7469891 4.0000000 98.0000000
78 30 30 31.9000000 29.3508503 1.0000000 98.0000000
79 30 30 38.3000000 28.6767357 1.0000000 98.0000000
80 30 30 40.6666667 27.8683275 1.0000000 98.0000000
81 30 30 44.2333333 28.9669054 1.0000000 98.0000000
82 30 30 42.2666667 22.2694058 4.0000000 98.0000000
83 30 30 48.1000000 32.7807239 1.0000000 98.0000000
84 30 30 42.3666667 22.0571098 1.0000000 92.0000000
85 30 30 39.0000000 29.3422139 2.0000000 92.0000000
86 30 30 42.0333333 18.8487324 4.0000000 81.0000000
87 30 30 35.5666667 28.6581316 1.0000000 98.0000000
88 30 30 41.4666667 22.3386681 2.0000000 92.0000000
89 30 30 41.8333333 24.7192279 4.0000000 92.0000000
90 30 30 43.2666667 24.0630398 1.0000000 92.0000000
91 30 30 40.0000000 27.3003726 2.0000000 98.0000000
92 30 30 45.2666667 17.3482253 4.0000000 92.0000000
Analysis Variable: number
sampnum N Obs N Mean Std Dev Minimum Maximum
93 30 30 41.3333333 21.5939540 1.0000000 81.0000000
94 30 30 44.9333333 24.6897065 1.0000000 92.0000000
95 30 30 34.6333333 21.3823700 1.0000000 74.0000000
96 30 30 44.8000000 29.0284046 1.0000000 98.0000000
97 30 30 52.7666667 24.2397271 1.0000000 92.0000000
98 30 30 38.1666667 22.2448496 1.0000000 92.0000000
99 30 30 42.6000000 25.6791879 1.0000000 98.0000000
100 30 30 38.0000000 19.2246250 2.0000000 81.0000000
101 30 30 44.1333333 26.6027395 1.0000000 98.0000000
102 30 30 39.6666667 20.6570241 2.0000000 81.0000000
103 30 30 43.1333333 31.3035564 1.0000000 98.0000000
104 30 30 50.2333333 26.1067878 2.0000000 98.0000000
105 30 30 41.7333333 26.7413323 2.0000000 98.0000000
106 30 30 37.4333333 29.1839391 1.0000000 98.0000000
107 30 30 41.2666667 24.9550400 2.0000000 98.0000000
108 30 30 46.1333333 32.7432366 1.0000000 98.0000000
109 30 30 42.5000000 28.1385121 1.0000000 98.0000000
110 30 30 42.1333333 20.3516217 4.0000000 92.0000000
111 30 30 42.8666667 25.4053121 2.0000000 92.0000000
112 30 30 51.8000000 26.5945289 2.0000000 98.0000000
113 30 30 45.9333333 25.9175527 2.0000000 98.0000000
114 30 30 40.3000000 27.4441753 2.0000000 92.0000000
115 30 30 36.1666667 27.7377911 1.0000000 98.0000000
116 30 30 37.5333333 26.2478023 1.0000000 98.0000000
117 30 30 45.3000000 17.5069444 2.0000000 98.0000000
118 30 30 39.9333333 24.2201588 2.0000000 98.0000000
119 30 30 45.1333333 25.2924049 1.0000000 98.0000000
120 30 30 44.3000000 27.8148435 1.0000000 98.0000000
121 30 30 41.7333333 27.4602325 4.0000000 98.0000000
122 30 30 36.2000000 23.6444934 1.0000000 98.0000000
123 30 30 40.6666667 25.9167544 1.0000000 92.0000000
124 30 30 38.7666667 20.3989238 4.0000000 74.0000000
Analysis Variable: number
sampnum N Obs N Mean Std Dev Minimum Maximum
125 30 30 29.3666667 23.7697045 1.0000000 74.0000000
126 30 30 32.0000000 28.0295411 1.0000000 98.0000000
127 30 30 41.0000000 28.7809803 1.0000000 98.0000000
128 30 30 42.0000000 28.2427897 1.0000000 92.0000000
129 30 30 40.6000000 29.1519207 1.0000000 98.0000000
130 30 30 43.9000000 30.4566962 1.0000000 98.0000000
131 30 30 38.9333333 27.1584537 1.0000000 92.0000000
132 30 30 41.2000000 18.4865282 1.0000000 81.0000000
133 30 30 40.1666667 27.1421333 1.0000000 81.0000000
134 30 30 39.9666667 28.0915785 2.0000000 98.0000000
135 30 30 40.6333333 21.2594536 4.0000000 81.0000000
136 30 30 37.7000000 23.7372833 4.0000000 81.0000000
137 30 30 41.1666667 25.6327960 2.0000000 92.0000000
138 30 30 46.4333333 24.9740325 2.0000000 98.0000000
139 30 30 44.0666667 23.5576085 2.0000000 92.0000000
140 30 30 38.5000000 27.0972069 1.0000000 92.0000000
141 30 30 45.3333333 29.1338568 1.0000000 98.0000000
142 30 30 36.0000000 26.6639366 1.0000000 98.0000000
143 30 30 40.6333333 30.6745804 1.0000000 98.0000000
144 30 30 41.5333333 24.9478537 1.0000000 98.0000000
145 30 30 45.1000000 22.1800625 4.0000000 92.0000000
146 30 30 42.9333333 30.4358379 2.0000000 98.0000000
147 30 30 35.3666667 26.7922832 1.0000000 98.0000000
148 30 30 47.6000000 26.6634193 1.0000000 98.0000000
149 30 30 45.7000000 30.4915477 1.0000000 92.0000000
150 30 30 36.0666667 24.7176237 4.0000000 92.0000000
151 30 30 35.3666667 29.1245640 4.0000000 98.0000000
152 30 30 33.7333333 23.9999042 1.0000000 81.0000000
153 30 30 43.3666667 19.9697760 5.0000000 92.0000000
154 30 30 41.1333333 27.2583215 1.0000000 98.0000000
155 30 30 36.6333333 24.9654704 1.0000000 92.0000000
156 30 30 41.3333333 19.7385206 2.0000000 81.0000000
Analysis Variable: number
sampnum N Obs N Mean Std Dev Minimum Maximum
157 30 30 45.7000000 25.4248724 1.0000000 98.0000000
158 30 30 40.1666667 29.7241146 1.0000000 98.0000000
159 30 30 41.5000000 28.8572587 1.0000000 98.0000000
160 30 30 35.9000000 23.5259944 1.0000000 98.0000000
161 30 30 46.1333333 30.2777184 1.0000000 98.0000000
162 30 30 37.2000000 23.2087974 2.0000000 81.0000000
163 30 30 43.2000000 25.1291835 1.0000000 98.0000000
164 30 30 41.0666667 31.8811731 1.0000000 98.0000000
165 30 30 48.5000000 28.2412635 4.0000000 98.0000000
166 30 30 51.9333333 25.5800749 4.0000000 98.0000000
167 30 30 47.7000000 31.0651707 1.0000000 98.0000000
168 30 30 45.7333333 28.2109459 1.0000000 98.0000000
169 30 30 34.0000000 23.1859053 1.0000000 81.0000000
170 30 30 43.2333333 26.0287419 1.0000000 92.0000000
171 30 30 43.0333333 21.5366301 4.0000000 92.0000000
172 30 30 39.3666667 26.9629162 1.0000000 98.0000000
173 30 30 35.6666667 27.1500725 1.0000000 81.0000000
174 30 30 33.2333333 24.7744074 1.0000000 81.0000000
175 30 30 38.7666667 25.8426049 1.0000000 98.0000000
176 30 30 48.6333333 33.6743874 1.0000000 98.0000000
177 30 30 43.5000000 26.3644876 4.0000000 98.0000000
178 30 30 37.1333333 23.7148772 1.0000000 81.0000000
179 30 30 39.1333333 23.4060607 1.0000000 98.0000000
180 30 30 40.0000000 26.5745536 1.0000000 98.0000000
181 30 30 53.7666667 29.1744850 1.0000000 98.0000000
182 30 30 50.1666667 31.4182940 1.0000000 98.0000000
183 30 30 41.2000000 23.3288337 2.0000000 98.0000000
184 30 30 42.1333333 25.2760393 1.0000000 81.0000000
185 30 30 40.5666667 26.0830019 1.0000000 98.0000000
186 30 30 47.3666667 19.1644127 5.0000000 92.0000000
187 30 30 42.7000000 23.0399204 1.0000000 98.0000000
188 30 30 37.1666667 22.7688283 1.0000000 81.0000000
Analysis Variable: number
sampnum N Obs N Mean Std Dev Minimum Maximum
189 30 30 43.9333333 25.6514211 2.0000000 98.0000000
190 30 30 36.7333333 26.9097256 2.0000000 92.0000000
191 30 30 41.5666667 20.7525376 1.0000000 98.0000000
192 30 30 42.1666667 26.5980079 1.0000000 92.0000000
193 30 30 44.3666667 24.0509278 1.0000000 81.0000000
194 30 30 40.2333333 23.7104420 1.0000000 98.0000000
195 30 30 46.5666667 28.8512037 1.0000000 98.0000000
196 30 30 43.7000000 23.0399204 4.0000000 92.0000000
197 30 30 49.9000000 26.7895373 1.0000000 98.0000000
198 30 30 40.2000000 26.6799679 2.0000000 98.0000000
199 30 30 41.3333333 25.4874321 4.0000000 98.0000000
200 30 30 52.7333333 30.4890408 1.0000000 98.0000000

Analysis Variable : number_Mean Mean


N Mean Std Dev Minimum Maximum
200 41.7340000 4.7268115 29.3666667 54.2333333

Obs mse
1 22.3426

Obs conf_lo conf_hi


1 32.8 51.9333

Simulated mean and variance:


E ( X ) =41.7340000
2
Var ( X )=( 4.7268115 ) =22.34274696

Mean Square Error:


MSE=22.3426

95% Confidence Interval:


(32.8000 , 51.9333)

You might also like