LIS 4273 Module #6 Assignment
#1 Ice Cream Purchases Population
#A Define the population
population <- c(8, 14, 16, 10, 11)
#B Calculate the mean
population_mean <- mean(population)
population_mean
[1] 11.8
#C Select a random sample of size 2
sample_size_2 <- sample(population, 2)
sample_size_2
[1] 14 10
# Calculate the sample mean
sample_mean <- mean(sample_size_2)
sample_mean
[1] 12
# Calculate the sample standard deviation
sample_sd <- sd(sample_size_2)
sample_sd
[1] 2.828427
#D Calculate the population standard deviation
population_sd <- sd(population)
population_sd
[1] 3.193744
#2 Sampling Distribution of Proportion
Does the sample proportion p have approximately a normal distribution? Explain.
Since both and is greater than 5, the sampling distribution of will be approximately normal.
What is the smallest value of n for which the sampling distribution of p is approximately normal? 100
# Given values
n <- 100
p <- 0.95
q <- 1 - p
# Check np and nq
np <- n * p
nq <- n * q
np
[1] 95
nq
[1] 5
# Solve for minimum n where np and nq are >= 5
n_min <- 5 / min(p, q)
n_min
[1] 100
#3 Simulated Coin Tossing
Simulated coin tossing: is probability better done using function called rbinom than using function called sample?
In R, the rbinom() function simulates binomial distributions, which is better suited for probability experiments than sample() because rbinom() accounts for the number of trials and the probability of success directly.
# Simulate 100 coin tosses with a fair coin (p = 0.5)
coin_tosses_rbinom <- rbinom(100, size = 1, prob = 0.5)
table(coin_tosses_rbinom)
0 1
49 51
# Simulate 100 coin tosses using sample function
coin_tosses_sample <- sample(c(0, 1), 100, replace = TRUE, prob = c(0.5, 0.5))
table(coin_tosses_sample)
0 1
55 45
Comments
Post a Comment