Template For Lab Assignment 4: Bailey Sinclair November 4th, 2019

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Template for Lab Assignment 4

Bailey Sinclair

November 4th, 2019

Contents

1 Problem 1: 1

1.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

1.2 First way . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

1.3 Second way . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

1.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

2 Problem 2: 2

2.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

2.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

3 Problem 3: 2

3.1 Bernoulli Distribution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

3.2 Uniform (0,1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

3.3 Poisson (1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

1 Problem 1:

1.1

dbinom(c(7,8,9),100,0.01)

## [1] 6.286346e-05 7.381694e-06 7.621951e-07

1.2 First way

sum(dbinom(10:29,100,0.01))

## [1] 7.631588e-08

1.3 Second way

pbinom(29,100,0.01)-pbinom(9,100,0.01)

## [1] 7.631588e-08

1.4

x=dbinom(0:10,100,0.01)

y=dpois(0:10,1)

matplot(cbind(x,y),type='o',pch=20)

1
0.3
cbind(x, y)

0.2
0.1
0.0

2 4 6 8 10

2 Problem 2:

2.1

firstrn=c(rnorm(10000, mean =50 , sd = 4))

2.2

mean(firstrn)

## [1] 50.02341

var(firstrn)

## [1] 16.09301

3 Problem 3:

3.1 Bernoulli Distribution

N = 1000

n = 2000

2
mu = .5

sigma = sqrt(.25)

y = rep(NA, N)

for(i in 1:N){

x = rbinom(n, 1, 0.5)

y[i] = (sum(x) - n*mu)/sqrt(n*sigma^2)

hist(y, main= "Bernoulli (0.5)", freq = F, breaks = 100)

x = seq(-4,4,0.01)

points(x, dnorm(x), type = "l", col = "red")

Bernoulli (0.5)
0.0 0.1 0.2 0.3 0.4 0.5 0.6
Density

−3 −2 −1 0 1 2 3

3.2 Uniform (0,1)

N = 1000

n = 2000

mu = .5

sigma = sqrt(1/12)

y = rep(NA, N)

for(i in 1:N){

x = runif(n=2000, min=0, max=1)

y[i] = (sum(x) - n*mu)/sqrt(n*sigma^2)

hist(y, main= "Uniform (0,1) ", freq = F, breaks = 100)

x = seq(-4,4,0.01)

3
points(x, dnorm(x), type = "l", col = "red")

Uniform (0,1)
0.6
0.5
0.4
Density

0.3
0.2
0.1
0.0

−3 −2 −1 0 1 2 3

3.3 Poisson (1)

N = 1000

n = 2000

mu = 1

sigma = 1

y = rep(NA, N)

for(i in 1:N){

x = rexp(n)

y[i] = (sum(x) - n*mu)/sqrt(n*sigma^2)

hist(y, main= "Poisson (1)", freq = F, breaks = 100)

x = seq(-4,4,0.01)

points(x, dnorm(x), type = "l", col = "red")

4
Density

0.0 0.1 0.2 0.3 0.4 0.5

−3
−2
−1

5
y
0
Poisson (1)

1
2
3

You might also like