STAT 362 Statistics R Language Questions

Stat 362: Chapter 3 WorksheetName:
UIN:
Show all of your work / code. No credit will be given if there is no work / code.
For each of the below questions, report your code and results.
1. In a regional spelling bee, the 8 finalists consist of 3 boys and 5 girls. Find the number of
sample points in the sample space S for the number of possible orders at the conclusion of
the contest for
(a) all 8 finalists;
(b) the first 3 positions.
2. How many ways are there to select 3 candidates from 8 equally qualified recent graduates for
openings in an accounting firm?
3. A president and a treasurer are to be chosen from a student club consisting of 50 people. How
many different choices of officers are possible if
(a) there are no restrictions?
(b) Abe will serve only if he is president?
4. In testing a certain kind of truck tire over rugged terrain, it is found that 25% of the trucks fail
to complete the test run without a blowout. Of the next 15 trucks tested, find the probability
that (Hint: Binomial Distribution)
(a) less than 4 have blowouts;
(b) from 3 to 6 (inclusive) have blowouts.
5. An automobile manufacturer is concerned about a fault in the braking mechanism of a particular model. The fault can, on rare occasions, cause a catastrophe at high speed. The
distribution of the number of cars per year that will experience the catastrophe is a Poisson
random variable with λ = 5. What is the probability that greater than 1 car per year will
experience a catastrophe?
6. Suppose P(T > k) = 0.05, where T comes from the t-distribution with 10 degrees of freedom.
Find k. Hint: Use the function qt()
7. Generate a sample of size 30 from the Gamma Distribution with parameters α = 3 and β = 5
(scale parameter). We want to be able to replicate this sample, so use a seed of 15. Report
the sample mean and sample variance along with your code.
2
Probability and Distributions
Chapter 3
Stat 362
1 / 21
Outline
1 Random Sampling
2 Probability Calculations and Combinatorics
3 Discrete Distributions
4 Continuous Distributions
2 / 21
Random Sampling
3 / 21
Types of Sampling
Why random sample?
Types of random sampling:
Simple Random Sample (SRS)
Stratified Sampling (STSRS)
Cluster Sampling
Systematic Sampling
Multistage Sampling
4 / 21
Simple Random Sampling
Simple Random Sample:
sample(x, size, replace = FALSE, prob = NULL)
x: vector of numbers to select from
size: how many numbers you want to get
replace: sample with replacement (TRUE), sample without
replacement (FALSE)
prob: vector of probabilities. Default is uniform (each value has the
same probability of being selected)
5 / 21
How to generate a replicable series of random variables
Set a random number seed. Allows for replication to generate the
exact same dataset each time you run your code. Must be run right
before the random sample generation.
set.seed()
Example
set.seed(16)
round(rnorm(n = 10, mean = 30, sd = 5),2)
## round() rounds values to a certain
## number of decimal places
Output:
32.38 29.37 35.48 22.78 35.74
27.66 24.97 30.32 35.12 32.87
See Additional R Code: Random Sampling
6 / 21
Probability Calculations and Combinatorics
7 / 21
Permutations, Combinations
Permutations can be written as a division of factorials.
factorial() returns the value of a factorial.
Example: factorial(4) = 4(3)(2)(1) = 24.
prod() gives the product of the values inside the function.
Example: prod(c(3,4)) = 3(4) = 12.
Combinations can be written with factorials, products, or the
binomial coefficient.
choose(n,k) returns the value of
n
k

See Additional R Code: Probability calculation and combinatorics
8 / 21
Discrete Distributions
9 / 21
Binomial Distribution
Let X represent the number of successes in n Bernoulli trials. Then
X ∼ Bin(n, p).
PDF:
 
n x
P(X = x) =
p (1 − p)n−x , x = 0, 1, 2, . . . , n.
x
Expected Value:
E(X ) = np
Variance:
V(X ) = σ 2 = np(1 − p)
Standard Deviation:
SD(X ) = σ =
p
np(1 − p)
10 / 21
Binomial Distribution: R Functions
PDF: dbinom(x, size = , prob = )
CDF: pbinom(x, size = , prob = )
Quantile: qbinom(q, size = , prob = )
The smallest value x such that F (x) ≥ p,
where F is the distribution function.
Generate Random Sample: rbinom(n, size = , prob = )
Example
Suppose X ∼ Bin(20, 0.3)
P(X = 5): dbinom(5, size = 20, prob = 0.3)
P(X ≤ 5): pbinom(5, size = 20, prob = 0.3, lower.tail= TRUE)
50th percentile (median): qbinom(0.5, 20, 0.3, lower.tail = TRUE)
Generate a random sample of size 10:
rbinom(n = 10, size = 20, p = 0.3)
Note: lower.tail = TRUE is optional in the pbinom and qbinom functions
because it is the default setting.
11 / 21
Poisson Distribution
Let X represent the number of outcomes occurring in a given time
interval or specified region. Let λ represent the average number of
outcomes per unit time, distance, area, or volume. Then X ∼ Pois(λ).
PDF:
P(X = x) =
e −λ λx
, x = 0, 1, 2, . . . .
x!
Expected Value:
E(X ) = λ
Variance:
V(X ) = σ 2 = λ
Standard Deviation:

SD(X ) = σ =
λ
12 / 21
Poisson Distribution: R Functions
PDF: dpois(x,λ)
CDF: ppois(x,λ)
Quantile: qpois(q,λ)
It is the smallest integer x such that P(X ≤ x) ≥ p.
Generate Random Sample: rpois(n,λ)
Example
Suppose X ∼ Pois(λ = 2.5).
P(X = 1): dpois(1,2.5)
P(X ≤ 5): ppois(5,2.5, lower.tail = TRUE)
50% percentile (median): qpois(0.5,2.5, lower.tail = TRUE)
Generate a random sample of size 10: rpois(10,2.5)
Note: lower.tail = TRUE is optional because it is the default setting.
13 / 21
Continuous Distributions
14 / 21
Normal (Gaussian) Distribution
Let X ∼ N(µ, σ 2 ).
PDF:
f (x) =
2
1 − (X −µ)
2σ 2 ,
−∞

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper
Still stressed from student homework?
Get quality assistance from academic writers!

Order your essay today and save 25% with the discount code LAVENDER