Statistics
Problem 1
The goal of this problem is to create your own function which calculates binomial probabil-
ities. Your function can be called whatever you want, and should take in arguments X, n, p,
and return a single binomial probability of
n 1′ TL-CB
P(X=x)= ??? p (1-29)
You may not use any built in R function such as dbinom although you may use
this function to check your work. You must build your own function.
Then, run your function for the following values of X, n, p (and show your functions output):
(a) x=20, n=2000, p=0.01
(b) x=500, n=1000, p=0.50
(c) x=450, n=500, p=0.90
Problem 2
Modify your existing function from Problem 1 so that you can input a vector of values for
X, and your function will return a vector of probabilities.
For example, if X = C(O, 1), n = 1, p = 0.70, your function should return 0.25 0.75
Then, run your function for the following values of X, n, p (and show your functions output):
(a) x=0210 n=10, p=O.1O
(b) x=O:6, n=6, p=.2
(c) x=O:3, n=3, p=.5
Problem 3
Create another function that finds the probability that a binomial random variable X is
within k standard deviations from its mean. l.e, your function should find the probability
that
P<np-kr* WW1 -p) = X = ????|?:? \/????? -p))
Notice that you can use your function from Problem 2 to help you find the probabilities.
Your function should take in values k, n, and p.
Then, run your function for the following values of k, n, p (and show your functions output):
(a) k=1 n=20, p=0.25
(b) k=2, n=20, p=0.25
(c) k=3, n=20, p=0.25
Problem 4
The goal of this problem is to simulate a geometric random variable (which will be covered
on Friday, Feb 6th in lecture). We will break this problem into two parts.
Part a
Build a function which takes in p. This function should repeat a Bernoulli trial until a
“success” (defaulted to a 1 in R) occurs, and return the trial number on which the first
success occurred (i.e., if the 3rd trial resulted in a “success”, this function should return 3).
Use your function with the following values of p (and show your functions output):
i. p = 0.02
ii. p = 0.10
iii. p = 0.50
Part b
Build another function which takes in p, r, and N. This function will calculate the probability
that the first “success” occurred on the rt” trial, based on N simulations.
Notice you can use your function from Part a in this function.
Use your function with the following values of p, r, and N (and show your functions output):
i. p = 0.02, r = 10, N = 500000
ii. p = 0.10, r = 10, N = 500000
iii. p = 0.20, r = 10, N = 500000
These simulations may take a few minutes (or more depending on your computer)
to run, but they should not crash your computer. Remember that you can always
use the computer labs to complete simulations.

+1 862 207 3288 