School

Worcester Polytechnic Institute **We aren't endorsed by this school

Course

ECON MISC

Subject

Mathematics

Date

Nov 13, 2023

Type

Other

Pages

4

Uploaded by pntzanetos on coursehero.com

Lab 3
2023-02-13
Name:Peter Tzanetos Section: CX07
1A
rbinom(
10
,
1
,
0.2
)
##
[1] 0 0 0 1 0 0 0 0 0 0
The relative frequency of heads in this test was 3/10.
For 10 Heads 0 Tails Probability=0.0000001024
For 9 Heads 1 Tail Probability=0.0000004096
For 8 Heads 2 Tails Probability=0.000002048
For 7 Heads 3 Tails Probability= 0.0000065536
For 6 Heads 4 Tails Probability=0.0000262144
For 5 Heads 5 Tails Probability=0.0001048576
For 4 Heads 6 Tails Probability=0.0004194304
For 3 Heads 7 Tails Probability=0.0016777216
For 2 Heads 8 Tails Probability=0.0067108864
For 1 Heads 9 Tails Probability=0.0268435456
For 0 Heads 10 Tails Probability=0.1073741824
1B.
coin
.10000
<-
sample(c(
0
,
1
),
10000
,
replace =
T,
prob =
c(
0.8
,
0.2
))
heads
.10000
<-
cumsum(coin
.10000
==
1
)
# sequentially record the number of heads
heads.prop
<-
heads
.10000
/(
1
:
10000
)
# record the proportion of heads
plot(
1
:
10000
, heads.prop,
type=
"l"
,
xlab=
"Number of Flips"
,
ylab=
"Frequency o
f Heads"
)
lines(
1
:
10000
, rep(
0.2
,
10000
),
col=
"red"
)

2A. The probability
of P(X > 2) and P(X ≤ 4) is 20 percent. 2B. The expected value is 0
0.3+2
0.2+4
0.2+6
.03=3
2C.The Variance is 6.667 and the Standard Deviation is 2.58 2D.
X
<-
sample(c(
0
,
2
,
4
,
6
),
10000
,
replace=
T,
prob =
c(
0.3
,
0.2
,
0.2
,
0.3
))
table(X)/
10000
# calculating the observed frequencies
## X
##
0
2
4
6
## 0.3037 0.1984 0.2023 0.2956
sum(X>
2
)/
10000
# observed frequency of X less than 3
## [1] 0.4979
sum(X<=
4
)/
10000
# observed frequency of X less than 3
## [1] 0.7044
sum(X<=
4
)/
10000
-sum(X>
2
)/
10000
## [1] 0.2065
The probability in the simulation came out to 19.59% which is very close to my predicted
20 percent.
mean(X)
## [1] 2.9796

var(X)
## [1] 5.794563
The expected value came out extremely close to my projection of 3 and the variance was
close to my projection of 6.667, but a little bit off. This was the most likely to be farther off
as variance is varies the most of the three. 2E.
Y
<-
table(X)
# create table of discrete random variable X
names(Y)
<-
c(
"0"
,
"2"
,
"4"
,
"6"
)
# assign label names
barplot(Y,
main=
"Bar Chart of 10000 Samples"
,
col=
c(
"purple"
,
"orange"
,
"green"
,
"blue"
),
xlab=
"Category"
,
ylab=
"Frequency"
)
# create bar chart
3A.
Y
<-
rbinom(
20000
,
8
,
0.5
)
sum(Y==
5
)/
20000
## [1] 0.22095
The chances of it equaling 5 are 22.04%. 3B.
sum(Y>=
4
)/
20000
## [1] 0.63885
sum(Y<
7
)/
20000
-sum(Y>=
4
)/
20000
## [1] 0.3267

The chances of it being above 4 and below 7 are 32.93%.
X
<-
rbinom(
2000
,
8
,
0.5
)
barplot(table(X),
col=
c(
"yellow"
,
"red"
,
"green"
,
"purple"
,
"orange"
),
xlab=
"Catego
ry"
,
ylab=
"Frequency"
,
main=
"Bar Chart of 20000 Samples"
)