#Part 1
A. Explain each of the 3 distributions: Normal, inomial & Poisson
Normal Distribution is the most commonly seen form of distribution. Its key identifiers are a continuous bell shapw curve, that is symmetric and unimodal. When dealing with the standard form, the mean is centered at 0, with a SD of 1. We can quickly analyse the graph by utilizing the 68-95-99.7 rule, where it tells us how much of the data falls within 1, 2 and 3 SD’s of the mean.
Binomial Distribution deals with ID’ing the number of ‘successes’ in a fixed number of trials. Where each trial must result in either a success or a failure (according to Bernoulli), the trials are independent of one another as well as that the probability of a success must be the same for all the trials. There is also the Negative Binomial Distribution where the setup is reversed. The number of successes are fixed and we are trying to find out how mayn trials are needed to witness all those successes.
Lastly Poisson Distribution is a method for estimating the number of successful events occurring in a large population, over a predetermined period of time. It makes use of the lambda, where similarly to Binomial, the events need to be independent and share the same probability of success. Using poisson, we can find the probability of finding exactly k events, during the determined time period.
B. Explain what the pdf and cdf of a distribution measures.
Probability Density Function (PDF) is a tool for when dealing with continuous random variables. It takes into account all the possible values of X and measures how clustered or dispersed those values. The total area under the PDF adds up to 1. When looking at a particular value for random variable X, we want to look between 2 values P(a <= X <= b) or an interval, instead of a single spot.
The CDF, or Cumulative Distribution Function, tells us the probability that random variable X is less than or equal to a particular value of x, P( a <= X <= b). It accumulates the probabilities up to our chosen value of x. For a discrete distribution, like Poisson, this can be thought of as adding together the probabilities from the PMF up through that value. We can also use the CDF to find probabilities above a certain value by using the complement.
In regards to Poisson, deciding on using a PDF doesn’t make the most sense. PDF is ideal for when dealing with continuous events over an interval. Where as Poisson lets us find the probability of an exact number of events to happen over a time period. We can’t have a fraction of a case when dealing with Poisson, so the possible values would be discrete rather than continuous. We would be better off wokring with the PMF where we can pinpoint our desired value.
C. What are the key parameters that define the 3 distributions above (or a distribution from the list above)? Does R require these key parameters to be declared ?
Normal: Mean and Standard Deviation. Mean for where the data is centered and the SD is its probability spread. R doesn’t need any additional info besides the variable that is being analysed since it has default values for the mean (0) and SD (1).
Binomial: Number of Trials (n or size) and the probability of success (p or prob). R does need an input for these arguments.
Poisson: Average event rate (lambda) which also needs an input
D. Give Examples for each Distribution.
Normal: Since it deals with continuous values, we could use it for comparing peoples’ height, the weight of packages or standardized test scores.
Binomial: The number of made free-throws or field goals out of a set amount, the rate or number of faulty products in a shiping container or the number of successful sales calls out of x amount of cold calls.
Poisson: The amount of people entering a store over the course of the day (foot traffic), the amount of cars passing a toll over the course of an hour, the number of signs on a 5 mile strip.
E. PLot the Distributions
Normal: Male Height. Set mean of 70 inches. Set Standard Deviation of 1. I used the sequence function to generate 1000 observations, that varied 3 SD from the mean on both sides. The height is the density distribution from using the dnorm() function.
heightmean <- 70
heightSD <- 1
x <- seq(from = heightmean - 3*heightSD,
to = heightmean + 3*heightSD,
length.out = 1000)
heightPDF <- dnorm(x = x, mean = heightmean, sd = heightSD)
Then I used the plot command with the argument type = ‘l’ to make a line graph. As well as using the pnorm() functions to learn the probability area under the curve for 2 different parameters. The 1st one was to find the area under the curve that was within 1 SD from the mean (in both directions) The second one was to find the probability area for obersations that would lie more than 3 SD away from the mean. I needed to use the lower.tail = F on the lower/left side pnorm() so that R would like at the left side of X rather than the default right side.
plot(x = x, y = heightPDF, type = 'l', col = 'blue', lwd = 3, xlab = 'Height (in.)', ylab = 'Density', main = 'Normal Distribution of Male Height')
pnorm(q = heightmean + 1, mean = heightmean, sd = heightSD) - pnorm(q = heightmean - 1, mean = heightmean, sd = heightSD)
## [1] 0.6826895
pnorm(q = heightmean + 3, mean = heightmean, sd = heightSD, lower.tail = F) + pnorm(q = heightmean - 3, mean = heightmean, sd = heightSD)
## [1] 0.002699796
Binomial: I wanted to find the probability of rolling a 4 on a standard die, if I rolled it 7 times I started out using the dbinom() function.
rollprob4 <- dbinom(x = 4, size = 7, prob = 1/6)
rollprob4
## [1] 0.01562857
Then I used the PMF to find the probability of all the possible outcomes of rolling a 4, when the die is rolled 7 times.
rolls <- 0:7
pmf <- dbinom(x = rolls, size = 7, prob = 1/6)
pmf
## [1] 2.790816e-01 3.907143e-01 2.344286e-01 7.814286e-02 1.562857e-02
## [6] 1.875429e-03 1.250286e-04 3.572245e-06
To plot the distributions, I used the plot() function. I needed to use the names.arg = rolls so that the labels for each roll count showed up on the x axis.
rollprob <- 1/6
barplot(height = pmf, names.arg = rolls, col = "green", main = "Rolling 4 Binomial Distribution", xlab = "Number of 4's", ylab = "Probability")
Poisson: My made-up task was to fingure out the probability of seeing 60 cars pass through a Toll Booth over the course of 3 Hrs, when the avg is 25 cars per HR. So I setup a tolltrafficavg variable to house the value of 25. Simple math of mulitpying by 3, we should expect to see 75 cars pass through (lambda_tolltrafficavg). I then used the dpois() function, setting the x to 60 and the lamba to the previously mentioned avg variable.
tolltrafficavg <- 25
lambda_tolltrafficavg <- 3*tolltrafficavg
lambda_tolltrafficavg
## [1] 75
dpois(60, lambda_tolltrafficavg)
## [1] 0.01026632
Lastly to chagne it up I wanted to find the likelhood of seeing 60 cars or less within those 3 HRs. The ppois() function made that very streamlined to find out.
ppois(q = 60, lambda = lambda_tolltrafficavg)
## [1] 0.0433398
I used the histogram to plot out a generated 10,000 cases, based on the expected average of 75 cars over 3 hrs. Where each generated case is the hypothetical observation of the number of cars that went throught the toll over 3 hrs.
hist(rpois(n = 10000, lambda = lambda_tolltrafficavg))
#Part 2
My Values
Number of Local Procedures Performed (LN)
Number of Local Deaths (LD)
National Death Proportion (NPI) 115/200
Local Death Proportion (LPI) 160/250
LN <- 250
LD <- 160
115/200
## [1] 0.575
NPI <- 0.575
160/250
## [1] 0.64
LPI <- 0.64
Poisson
To start off making use of the Poisson Distribution, I first needed to determine the Lambda value for the National Rate of Deaths and apply it to the number of Local Procedure that took place. The lambda needs to be an expected number, not a proportion so I multiplied the Number of Local Procedures Performed by the National Death Proportion. Giving me the expected amount of deaths (based off the national proportion) for this population to be 143.75 or 144 deaths.
N_to_L_lambda <- LN * NPI
N_to_L_lambda
## [1] 143.75
Since we were taked with, ‘The probability should be greater than or equal to x.’ I can’t use the dpois() function since that is meant for finding an exact probability P(X = x). I will need to make use of the ppois() function instead, since that will give me the probability of a value that is less than or equal to x P(X ≤ x). But since it needs to be greater than, I will add in the lower.tail argument and set it to False, so R looks at the area to the right of x (LD).
ppois(q = 160, lambda = N_to_L_lambda, lower.tail = F)
## [1] 0.08305566
For the visualization, I used a histogram again to show the national proportion distribution applied to the local number of procedures. As well as using the adline() functions to mark out the mean and the number of local deaths.
hist(rpois(10000, lambda = N_to_L_lambda))
abline(v = LD, lwd = 2, col = 'red')
abline(v = N_to_L_lambda, lwd = 2, col = 'blue')
Binomial
Like with Poisson, I used the corresponding p function for binomial to account for wanting to the P(X ≥ 160)’s as well as adding in the lower.tail argument. Then I made a local_deaths variable to house all the possible number of deaths that could occur with the sample size (pmf) and used it as the vertical variable for the barplot().
pbinom(q = LD, size = LN, prob = NPI, lower.tail = F)
## [1] 0.01548721
local_deaths <- 0:250
deathpmf <- dbinom(x = local_deaths, size = LN, prob = NPI)
deathpmf
## [1] 1.250929e-93 4.231082e-91 7.126884e-89 7.970931e-87 6.659244e-85
## [6] 4.432706e-83 2.448853e-81 1.154871e-79 4.746009e-78 1.726555e-76
## [11] 5.629584e-75 1.661781e-73 4.477848e-72 1.109129e-70 2.540277e-69
## [16] 5.407304e-68 1.074503e-66 2.001029e-65 3.504417e-64 5.789340e-63
## [21] 9.046695e-62 1.340533e-60 1.887857e-59 2.531949e-58 3.240026e-57
## [26] 3.962743e-56 4.639637e-55 5.207714e-54 5.611422e-53 5.811748e-52
## [31] 5.792376e-51 5.561560e-50 5.149555e-49 4.602472e-48 3.974211e-47
## [36] 3.318299e-46 2.681207e-45 2.098077e-44 1.591096e-43 1.170163e-42
## [41] 8.351179e-42 5.787116e-41 3.896172e-40 2.549834e-39 1.622962e-38
## [46] 1.005176e-37 6.060619e-37 3.559002e-36 2.036395e-35 1.135785e-34
## [51] 6.177335e-34 3.277479e-33 1.696948e-32 8.577026e-32 4.233388e-31
## [56] 2.041082e-30 9.615811e-30 4.427838e-29 1.993425e-28 8.776636e-28
## [61] 3.779977e-27 1.592912e-26 6.569629e-26 2.652388e-25 1.048522e-24
## [66] 4.059346e-24 1.539440e-23 5.719851e-23 2.082600e-22 7.432023e-22
## [71] 2.599959e-21 8.917837e-21 2.999570e-20 9.895439e-20 3.202252e-19
## [76] 1.016684e-18 3.167300e-18 9.683372e-18 2.905742e-17 8.559282e-17
## [81] 2.475269e-16 7.028541e-16 1.959823e-15 5.366944e-15 1.443588e-14
## [86] 3.814268e-14 9.900922e-14 2.525103e-13 6.327949e-13 1.558357e-12
## [91] 3.771631e-12 8.971947e-12 2.097852e-11 4.822008e-11 1.089629e-10
## [96] 2.420798e-10 5.288079e-10 1.135863e-09 2.399220e-09 4.983764e-09
## [101] 1.018154e-08 2.045795e-08 4.043218e-08 7.860144e-08 1.503119e-07
## [106] 2.827717e-07 5.233316e-07 9.528720e-07 1.706970e-06 3.008614e-06
## [111] 5.217613e-06 8.903399e-06 1.494967e-05 2.470080e-05 4.016111e-05
## [116] 6.425778e-05 1.011767e-04 1.567755e-04 2.390710e-04 3.587837e-04
## [121] 5.299094e-04 7.702622e-04 1.101913e-03 1.551426e-03 2.149770e-03
## [126] 2.931781e-03 3.935047e-03 5.198126e-03 6.758041e-03 8.647088e-03
## [131] 1.088907e-02 1.349521e-02 1.646007e-02 1.975791e-02 2.334000e-02
## [136] 2.713339e-02 3.104144e-02 3.494661e-02 3.871536e-02 4.220515e-02
## [141] 4.527301e-02 4.778502e-02 4.962596e-02 5.070789e-02 5.097717e-02
## [146] 5.041880e-02 4.905778e-02 4.695726e-02 4.421373e-02 4.094963e-02
## [151] 3.730431e-02 3.342420e-02 2.945313e-02 2.552379e-02 2.175079e-02
## [156] 1.822609e-02 1.501659e-02 1.216406e-02 9.686866e-03 7.583207e-03
## [161] 5.835166e-03 4.413151e-03 3.280218e-03 2.395944e-03 1.719614e-03
## [166] 1.212619e-03 8.400674e-04 5.716838e-04 3.821234e-04 2.508474e-04
## [171] 1.617055e-04 1.023523e-04 6.360262e-05 3.879738e-05 2.322859e-05
## [176] 1.364826e-05 7.868733e-06 4.450842e-06 2.469585e-06 1.343948e-06
## [181] 7.172112e-07 3.752714e-07 1.924873e-07 9.676957e-08 4.767324e-08
## [186] 2.301049e-08 1.087941e-08 5.037586e-09 2.283937e-09 1.013661e-09
## [191] 4.402993e-10 1.871306e-10 7.779909e-11 3.163181e-11 1.257408e-11
## [196] 4.885494e-12 1.854787e-12 6.878606e-13 2.491094e-13 8.806822e-14
## [201] 3.038354e-14 1.022566e-14 3.355945e-15 1.073591e-15 3.346459e-16
## [206] 1.015941e-16 3.002566e-17 8.634832e-18 2.415115e-18 6.566286e-19
## [211] 1.734456e-19 4.448563e-20 1.107203e-20 2.672454e-21 6.251398e-22
## [216] 1.416185e-22 3.104655e-23 6.581296e-24 1.347869e-24 2.664603e-25
## [221] 5.079846e-26 9.329501e-27 1.648855e-27 2.801009e-28 4.567821e-29
## [226] 7.141326e-30 1.068782e-30 1.528810e-31 2.086534e-32 2.712012e-33
## [231] 3.350133e-34 3.924271e-35 4.348139e-36 4.544635e-37 4.466948e-38
## [236] 4.114736e-39 3.538345e-40 2.827866e-41 2.089797e-42 1.419601e-43
## [241] 8.802919e-45 4.941839e-46 2.486535e-47 1.107534e-48 4.298772e-50
## [246] 1.424323e-51 3.916718e-53 8.581520e-55 1.404471e-56 1.526238e-58
## [251] 8.259641e-61
barplot(height = deathpmf, names.arg = local_deaths, col = "green", main = "Death Probability Distribution", xlab = "Number of Deaths", ylab = "Probability")
Since the boxplot was soo dense and covered a wide spread of x axis values, I decided to make a ‘zoomed in’ version of the local_deaths variable so that the distributions would stay the same, but the x axis is focused on the main bulk of the distribution.
local_deaths_zoom <- 105:180
deathpmf <- dbinom(x = local_deaths_zoom, size = LN, prob = NPI)
barplot(height = deathpmf, names.arg = local_deaths_zoom, col = "green", main = "Death Probability Distribution V2", xlab = "Number of Deaths Zoom", ylab = "Probability")
So when finding the probability of P(X ≥ 160) I got a difference of about 6.76%.
Poisson: about 8.31%
Binomial: about 1.55%
I think the difference in percentage is due to the fact that with Poisson, I had to have additional conversions for the lambda as well as the fact that the fake probability of death was expected to happen most of the time (being over 50%). Yes Poisson works well with large sample size, but the probability of success (success meaning death in this case) needed to be much smaller.
ppois(q = 160, lambda = N_to_L_lambda, lower.tail = F)
## [1] 0.08305566
pbinom(q = LD, size = LN, prob = NPI, lower.tail = F)
## [1] 0.01548721
8.31 - 1.55
## [1] 6.76