0% found this document useful (0 votes)
21 views9 pages

ffPROB 3-4

Uploaded by

jainpranav3882
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views9 pages

ffPROB 3-4

Uploaded by

jainpranav3882
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

PRANAV JAIN 102203882 3CO20

ASSIGNMENT 3

Q1

n = 12
p = 1/6
# pbinom for prob of all quantities <= x
x1 = pbinom(9, n, p)
x2 = pbinom(6, n, p)
prob = x1 - x2
print(prob)
# dbinom for prob of x
x3 = dbinom(7, n, p)
x4 = dbinom(8, n, p)
x5 = dbinom(9, n, p)
prob2 = x3 + x4 + x5
print(prob2)
di (pbinom(c(6, 9), n, p))

OUTPUTS.

> n = 12
> p = 1/6
> # pbinom for prob of all quantities <= x
> x1 = pbinom(9, n, p)
> x2 = pbinom(6, n, p)
> prob = x1 - x2
> print(prob)
[1] 0.001291758
> # dbinom for prob of x
> x3 = dbinom(7, n, p)
> x4 = dbinom(8, n, p)
> x5 = dbinom(9, n, p)
> prob2 = x3 + x4 + x5
> print(prob2)
[1] 0.001291758
> diff(pbinom(c(6, 9), n, p))
[1] 0.001291758
ff
PRANAV JAIN 102203882 3CO20

Q2

mean = 72
std = 15.2
pnorm(84, mean, std, lower.tail = FALSE) # now it will calculate for > 84

OUTPUT

> mean = 72
> std = 15.2
> pnorm(84, mean, std, lower.tail = FALSE) # now it will
calculate for > 84
[1] 0.2149176

Q3

dpois(0, 5)
ppois(50, 50) - ppois(47, 50)
diff(ppois(c(47, 50), 50))

OUTPUTS

> dpois(0, 5)
[1] 0.006737947
> ppois(50, 50) - ppois(47, 50)
[1] 0.1678485
> diff(ppois(c(47, 50), 50))
[1] 0.1678485

Q4

m = 17 # defective
n = 250 - 17 # non-defective
k = 5 # sample size
dhyper(3, m, n, k) # hypergeometric distribution
PRANAV JAIN 102203882 3CO20

dhyper(3,17,233,5)

OUTPUTS
> m = 17 # defective
> n = 250 - 17 # non-defective
> k = 5 # sample size
> dhyper(3, m, n, k) # hypergeometric distribution
[1] 0.002351153
> dhyper(3,17,233,5)
[1] 0.002351153

Q5

a) binomial distribution

b)

n = 31
p = 0.447
x = 0:31
pmf = dbinom(x, n, p)
plot(x, pmf, type = 'l', col = 'purple')

Output

C)

cdf =
pbinom(x, n, p)
plot(x, cdf, type = 'l', col = ‘purple')
PRANAV JAIN 102203882 3CO20

OUTPUTS

D)

n = 31
p = 0.447
q = 1-p
x = 0:31
print(n * p)
print(n * p * q)
print(sqrt(n * p * q))

OUTPUTS

> n = 31
> p = 0.447
> q = 1-p
> x = 0:31
> print(n * p)
[1] 13.857
> print(n * p * q)
[1] 7.662921
> print(sqrt(n * p * q))
[1] 2.768198
PRANAV JAIN 102203882 3CO20
PRANAV JAIN 102203882 3CO20
ASSIGNMENT 4

Q1

x = c(0, 1, 2, 3, 4)
p = c(0.41, 0.37, 0.16, 0.05, 0.01)
E1 = weighted.mean(x, p)
e = c(x%*%p)
E1
e

OUTPUTS

> x = c(0, 1, 2, 3, 4)
> p = c(0.41, 0.37, 0.16, 0.05, 0.01)
> E1 = weighted.mean(x, p)
> e = c(x%*%p)
> E1
[1] 0.88
> e
[1] 0.88

Q2

f1 = function(t){t*0.1*exp(-0.1*t)}
E2 = integrate(f1, lower = 0, upper = Inf)
E2

OUTPUT

> f1 = function(t){t*0.1*exp(-0.1*t)}
> E2 = integrate(f1, lower = 0, upper = Inf)
> E2
10 with absolute error < 6.7e-05

Q3

x3 = c(0:3)
p3 = c(0.1, 0.2, 0.2, 0.5)
PRANAV JAIN 102203882 3CO20
y=function(x){

-18+12*x+(3-x)*2
}
Y = y(x3)
Y
E3 = sum(p3*Y)
E3

OUTPUTS

> x3 = c(0:3)
> p3 = c(0.1, 0.2, 0.2, 0.5)
> y=function(x){
+
+ -18+12*x+(3-x)*2
+ }
> Y = y(x3)
> Y
[1] -12 -2 8 18
> E3 = sum(p3*Y)
> E3
[1] 9

Q4

f4_1 = function(x){x*0.5*exp(-abs(x))}
moment1 = integrate(f4_1, lower = 1, upper = 10)$value
f4_2 = function(x){(x^2)*0.5*exp(-abs(x))}
moment2 = integrate(f4_2, lower = 1, upper = 10)$value
mean4 = moment1
variance4 = moment2 - mean4^2
moment1
moment2
variance4

OUTPUTS
PRANAV JAIN 102203882 3CO20

> f4_1 = function(x){x*0.5*exp(-abs(x))}


> moment1 = integrate(f4_1, lower = 1, upper = 10)$value
> f4_2 = function(x){(x^2)*0.5*exp(-abs(x))}
> moment2 = integrate(f4_2, lower = 1, upper = 10)$value
> mean4 = moment1
> variance4 = moment2 - mean4^2
> moment1
[1] 0.3676297
> moment2
[1] 0.9169292
> variance4
[1] 0.7817776

Q5

x = c(1, 2, 3, 4, 5)
y = x^2
f_x = function(x) {0.75 * (0.25) ^ (x-1)}
f_y = function(y) {0.75 * (0.25)^(sqrt(y) - 1)}
x1 = 3
y1 = x1^2
expected_mean = sum(f_y(y) * y)
print(f_y(y1))
print(expected_mean)
print(sum(f_y(y)*y^2) - expected_mean^2)

OUTPUTS
PRANAV JAIN 102203882 3CO20

> x = c(1, 2, 3, 4, 5)
> y = x^2
> f_x = function(x) {0.75 * (0.25) ^ (x-1)}
> f_y = function(y) {0.75 * (0.25)^(sqrt(y) - 1)}
> x1 = 3
> y1 = x1^2
> expected_mean = sum(f_y(y) * y)
> print(f_y(y1))
[1] 0.046875
> print(expected_mean)
[1] 2.182617
> print(sum(f_y(y)*y^2) - expected_mean^2)
[1] 7.614112

You might also like