Lab-2: Probability Distributions Name: Objective:To Compute Probability Density Function (PDF) and Cumulative Distribution Function (CDF) Outcomes
Lab-2: Probability Distributions Name: Objective:To Compute Probability Density Function (PDF) and Cumulative Distribution Function (CDF) Outcomes
Outcomes:
Binomial Distribution
Poisson Distribution
Exponential Distribution
Normal Distribution
Chi-squared Distribution
Student t Distribution
F Distribution
Functions for Probability Distributions:
R
Every distribution that R handles has four functions. There is a root name, for
example, the root name for the normal distribution is norm. This root is prefixed by
one of the letters
For the normal distribution, these functions are pnorm, qnorm, dnorm, and rnorm. For
the binomial distribution, these functions are pbinom, qbinom, dbinom, and rbinom.
And so forth.
For a continuous distribution (like the normal), the most useful functions for doing
problems involving probability calculations are the "p" and "q" functions (c. d. f. and
inverse c. d. f.), because the the density (p. d. f.) calculated by the "d" function can
only be used to calculate probabilities via integrals and R doesn't do integrals.
For a discrete distribution (like the binomial), the "d" function calculates the density
(p. f.), which in this case is a probability
f(x) = P(X = x)
R has functions to handle many probability distributions. The table below gives the
names of the functions for each distribution.
Table-1:Probability Distributions
Distribution Functions
F pf qf df rf
Student t pt qt dt rt
Procedure:
1. Open RStudio
2. Go to RConsole (>)
3. Probability distribution in R
Probability Distributions in R:
[dpqr]distribution_abbreviation ()
where the first letter refers to the aspect of the distribution returned:
d = density
p = distribution function
q = quantile function
1. Binomial Distribution
Problem
Suppose there are twelve multiple choice questions in an English class quiz. Each
question has five possible answers, and only one of them is correct. Find the
probability of having four or less correct answers if a student attempts to answer every
question at random.
Example Solution:
Since only one out of five possible answers is correct, the probability of answering a
question correctly by random is 1/5=0.2. We can find the probability of having
exactly 4 correct answers by random attempts as follows.
To find the probability of having four or less correct answers by random attempts, we
apply the function dbinom with x = 0,…,4.
2. Poisson Distribution
Problem
If there are twelve cars crossing a bridge per minute on average, find the probability
of having seventeen or more cars crossing the bridge in a particular minute.
Solution
Answer: If there are twelve cars crossing a bridge per minute on average, the probability
of having seventeen or more cars crossing the bridge in a particular minute is 10.1%.
Problem
Solution
Answer: We
use the generation function runif() of the uniform distribution to generate ten random
numbers between one and three.
4. Exponential Distribution
Problem
Suppose the mean checkout time of a supermarket cashier is three minutes. Find the
probability of a customer checkout being completed by the cashier in less than two
minutes.
Solution
5.Normal Distribution
The normal distribution is important because of the Central Limit Theorem, which
states that the population of all possible samples of size n from a population with
mean μ and variance σ2 approaches a normal distribution with mean μ and σ2⁄n when n
approaches infinity.
Problem
Assume that the test scores of a college entrance exam fits a normal distribution.
Furthermore, the mean test score is 72, and the standard deviation is 15.2. What is the
percentage of students scoring 84 or more in the exam?
Solution
Answer: The percentage of students scoring 84 or more in the college entrance exam
is 21.5%.
6.Chi-squared Distribution
Solution
8.Student t Distribution
Assume that a random variable Z has the standard normal distribution, and another
random variable V has the Chi-Squared distribution with m degrees of freedom.
Assume further that Z and V are independent, then the following quantity follows a
Student t distribution with m degrees of freedom.
Find the 2.5th and 97.5thpercentiles of the Student t distribution with 5 degrees of
freedom.
Solution
8. F Distribution
If V 1 and V 2 are two independent random variables having the Chi-Squared
distribution with m1 and m2 degrees of freedom respectively, then the following
quantity follows an F distribution with m1 numerator degrees of freedom and m2
denominator degrees of freedom, i.e., (m1,m2) degrees of freedom.
Solution
> qf(0.95,5,2)
[1] 19.29641
Answer: The 95th percentile of the F distribution with (5, 2) degrees of freedom is
19.296.
1.
hist(x, probability=TRUE)
> pnorm(19,17.46,19.38)
[1] 0.531668
3. Interpret the following
Interpretation:
In the first line, we are calculating the area to the left of 1.96, while in the second line
we are calculating the area to the right of 1.96
set.seed(3000)
xseq<- seq(-4,4,.01)
densities<-dnorm(xseq, 0,1)
cumulative<-pnorm(xseq, 0, 1)
randomdeviates<-rnorm(1000,0,1)
par(mfrow=c(1,3), mar=c(3,4,4,2))
Output:
Explanation:
Let’s make up some data, where I add noise by using rnorm() – here I’m generating
the same amount of random numbers as is the length of the xseq vector, with a mean
of 0 and a standard deviation of 5.5.
xseq<-seq(-4,4,.01)
y<-2*xseq + rnorm(length(xseq),0,5.5)
And now we can plot a histogram of y and add a curve() function to the plot using the
mean and standard deviation of y as the parameters:
Here, the curve() function takes as its first parameter a function itself (or an
expression) that must be written as some function of x. Our function here is dnorm().
The x in the dnorm() function is not an object we have created; rather, it’s indicating
that there’s a variable that is being evaluated, and the evaluation is the normal density
at the mean of y and standard deviation of y. Make sure to include add=TRUE so that
Note: Complete your write-up with conclusion and upload your outputs on Google
classroom.