rm(list = ls())
gc()
## used (Mb) gc trigger (Mb) max used (Mb)
## Ncells 521518 27.9 1159858 62 660385 35.3
## Vcells 948685 7.3 8388608 64 1769939 13.6
cat("\f")
#Packages list
library(ggplot2)
library(graphics)
Normal: the normal distribution describes a symmetric around the mean, bell-shaped curve. It is a listing of all outcomes and their probabilities. The probability of an outcome is between 0 and 1 and the sum of all possible outcomes is equal to 1.
Binomial: describes the probability of having success in specified number of independent trials. The outcomes are independent and mutually exclusive.
Piosson: describes the number of times an event occurs during a interval of time. The intervals are independent to each other and the probability is proportional to the length of the interval.
PDF: measures the density for any given x. In other words, the corresponding y value to any x
CDF: measures the probability of less than x. In other words, the are under the PDF to the left of x
?distribution
## starting httpd help server ... done
#Normal distribution formula
?dnorm()
If mean or sd are not specified they assume
the default values of 0 and 1, respectively.
The parameters don’t have to be specified.
#Binomial distribution formula
?dbinom()
If size is not an integer, NaN is returned. The
parameters must be specified
#Poisson distribution
?dpois()
The parameters must be specified.
Normal: is used to model values where the random variable are expected to be clustered at the middle. Some examples can be the height of the US population, overall GPA of a class, wages in the US.
Binomial: is used to model to model experiments with only two outcomes. Some examples can be; analyzing which crops died or survived during the winter, a new medical treatment cures cancer or not, marital status of people in the US.
Poisson: is used to model events that occur over a period of time. Some examples; bugs that occur in a computer OS, defects that occur in a plastic production line.
?plot()
Normal
# Set the mean and standard deviation
mu <- 120
sigma <- 2
# Generate a range of values around the mean
x <- seq(from = mu - 3*sigma,
to = mu + 3*sigma,
length.out = 2500)
# Calculate the PDF
pdf <- dnorm(x = x,
mean = mu,
sd = sigma)
plot(x = x,
y = pdf,
type = 'l',
col = 'black',
lwd = 4,
xlab = 'Temperature',
ylab = 'Density',
main = 'Normal Distribution with Mean 120 and SD 2')
Binomial
# Number of trials
n <- 10
# Probability of success
p <- 0.5
# Generate values for x (number of successes)
x <- 0:n
# Calculate the probabilities for each value of x
probabilities <- dbinom(x = x,
size = n,
prob = p)
# Plot the binomial distribution
barplot(height = probabilities,
names.arg = x,
col = "lightyellow",
main = "Binomial Distribution",
xlab = "Number of Successes",
ylab = "Probability")
Poisson
# Parameters
lambda <- 3
# Generate x values
x_values <- 0:100
# Calculate the PMF using dpois
pmf_values <- dpois(x = x_values,
lambda = lambda)
# Plot the PMF
plot(x = x_values,
y = pmf_values,
type = "h",
lwd = 4,
col = "blue",
xlab = "Number of Events",
ylab = "Probability",
main = "Poisson Distribution PMF")
Binomial distribution
#Using PDF
n <- 2000
x <- 200:n
p <- .12
prob <- sum(dbinom(x = x,
size = n,
prob = p))
print(prob)
## [1] 0.9978207
# Using 1 - pbinom
1 - pbinom(q = 199,
size = 2000,
prob = .12)
## [1] 0.9978207
#Using compliment PDF
1 - sum(dbinom(x = 0:199,
size = 2000,
prob = .12))
## [1] 0.9978207
probabilities <- dbinom(x = 0:2000,
size = n,
prob = p)
barplot(height = probabilities,
names.arg = 0:2000,
col = "lightyellow",
main = "Binomial Distribution",
xlab = "Number of Successes",
ylab = "Probability")
Poisson distribution
lambda_approx <- n * p
print(lambda_approx)
## [1] 240
sum(dpois(x = 200:2000,
lambda = lambda_approx))
## [1] 0.9963453
#Using 1 - ppois
1 - ppois(q = 199,
lambda = lambda_approx,
lower.tail=T)
## [1] 0.9963453
#Using compliment PMF
1 - sum(dpois(x = 0:199,
lambda = lambda_approx))
## [1] 0.9963453
probs <- dpois(x = 0:2000,
lambda = lambda_approx)
plot(x = 0:2000,
y = probs,
type = "h",
lwd = 2,
col = "blue",
xlab = "Number of Events",
ylab = "Probability",
main = "Poisson Distribution PMF")
Poisson = 0.9963453
Binomial = 0.9978207
I get very similar answers when I perform the probabilities using the two different types of distributions. My best guess as to why the similar results is because as n increases, the two distributions will get similar to each other since the poisson is an approximation of the binomial distribution.