1. Consider the population \(\{3, 6, 7, 9, 11, 14\}\). For samples of size 3 without replacement, find (and plot) the sampling distribution of the minimum. What is the mean of the sampling distribution?
Pop <- c(3, 6, 7, 9, 11, 14)
Min <- apply(combn(Pop, 3), 2, min)
Min
 [1] 3 3 3 3 3 3 3 3 3 3 6 6 6 6 6 6 7 7 7 9
mean(Min)  # mean of the sampling distribution
[1] 4.8
ggplot(data = data.frame(x = Min), aes(x = x)) + geom_density() 

  1. Let \(X_1, X_2, \ldots, X_n\) be a random sample from some distribution and suppose \(Y = T(X_1, X_2, \ldots, X_n)\) is a statistic. Suppose the sampling distribution of \(Y\) has pdf \(f(y) = (3/8)y^2\) for \(0 \leq y \leq 2.\) Find \(P(0 \leq Y \leq 1/5)\).
# Your code here
f <- function(x){
  (3/8)*x^2
  }
integrate(f, 0, 2)$value
[1] 1
integrate(f, 0, 1/5)$value
[1] 0.001
curve(f)
abline(v=0)
abline(v=1/5)
abline(h=0)

\(P(0 \leq Y \leq 1/5) =\) 0.001

  1. A friend claim that she has drawn a random sample of size 30, from the exponential distribution with \(\lambda = 1/10\). The mean of her sample is 12.

    1. What is the expected value of a sample mean?
    2. Run a simulation by drawing 10,000 random samples, each of size 30, from \(\text{Exp}(\lambda = 1/10)\) and then compute the mean. What proportion of the sample means are as large as or larger than 12?
    3. Is a mean of 12 unusual for a sample of size 30 from \(\text{Exp}(\lambda = 1/10)\)?
library(tidyverse)
set.seed(123)
# Your code here
sims <- 1000
xbar <- numeric(sims)
for(i in 1:sims){
  xbar[i] <- mean(rexp(30, 1/10))
}
mean(xbar)
[1] 10.02618
mean(xbar >= 12)
[1] 0.142
  1. The expected value of a sample mean is 1/(1/10) which is 10.

  2. The proportion of sample means that are as large or larger than 12 are 0.126.

  3. Because the proportion of sample means at 0.126 is greater than 0.05, we cannot say that the mean of 12 is unusual.

  1. Let \(X_1, X_2, \ldots , X_{10} \overset{i.i.d}\sim N(20, 8)\) and \(Y_1, Y_2, \ldots, Y_{15} \overset{i.i.d}\sim N(16, 7)\). Let \(W = \bar{X} + \bar{Y}.\)

    1. Give the exact sampling distribution of \(W\)
    2. Simulate the sampling distribution in R and plot your results. Check that the simulated mean and standard error are close to the theoretical mean and standard error.
    3. Use your simulation to find \(P(W < 40).\) Calculate an exact answer and compare.
xbar <- numeric(1000)
ybar <- numeric(1000)
for(i in 1:1000)
{
  xbar[i] <- mean(rnorm(10, 20, 8))       # draw 10 from N(20, 8^2)
  ybar[i] <- mean(rnorm(15, 16, 7))    # draw 15 from M(16, 7^2)
}
W <- xbar + ybar

hist(W)

mean(W)
[1] 36.05247
sd(W)
[1] 2.939159
mean(W < 40)
[1] 0.915
  1. The exact sampling distribution is mean = 35.79982 and sd = 3.21752.
  2. check histogram
  3. The probability that W < 40 is 0.907.
  1. Let \(X_1, X_2, \ldots , X_{9} \overset{i.i.d}\sim N(7, 3)\) and \(Y_1, Y_2, \ldots, Y_{12} \overset{i.i.d}\sim N(10, 5)\). Let \(W = \bar{X} - \bar{Y}.\)

    1. GIve the exact sampling distribution of \(W\).
    2. Simulate the sampling distribution of \(W\) in R and plot your results using ggplot2. Check that the simulated mean and the standard error are close to the theoretical mean and the standard error.
    3. Use your simulation to find \(P(W < -1.5)\). Calculate an exact answer and compare.
#part a.
# The exact sampling distribution mean is -3.032, standard deviation is 1.75 
library(ggplot2)
# part b.
for (i in 1:1000)
  {
  x <- rnorm(9, 7, 3)
  y<-rnorm(12, 10, 5)
  W[i]<-mean(x)-mean(y)
}
mean(W) #-3.032
[1] -3.001672
sd(W)#1.75
[1] 1.770889
ggplot(data = data.frame(x = W), aes(x = x)) + geom_density() + theme_bw() 

# part c.
# simulated answer
mean(W<-1.5)#1.5
[1] 1.5
# Exact answer
pnorm(-1.5, -3, sqrt(3/9 + 5/12)) #.96
[1] 0.9583677
#The simulated answer has a 96% error
  1. Let \(X_1, X_2, \ldots , X_n\) be a random sample from \(N(0, 1)\). Let \(W = X_1^2 + X_2^2 + \cdots + X_N^2.\) Describe the sampling distribution of \(W\) by running a simulation, using \(n = 2.\) What is the mean and variance of the sampling distribution of \(W\)? Repeat using \(n = 4, n = 5.\) What observations or conjectures do you have for general \(n\)?
set.seed(13)
sims <- 10000
WE2 <- numeric(sims)
WE4 <- numeric(sims)
WE5 <- numeric(sims)

for (i in 1:sims) {
  WE2[i] <- sum(rnorm(2)^2)
  WE4[i] <- sum(rnorm(4)^2)
  WE5[i] <- sum(rnorm(5)^2)
}

mean(WE2)
[1] 2.006991
mean(WE4)
[1] 3.95115
mean(WE5)
[1] 5.024684
var(WE2)
[1] 4.051355
var(WE4)
[1] 7.957447
var(WE5)
[1] 9.772532

The mean of W is approximately n and the variance is 2n.

  1. Let \(X\) be a uniform random variable on the interval \([40, 60]\) and \(Y\) a uniform random variable on \([45, 80].\) Assume that \(X\) and \(Y\) are independent.

    1. Compute the expected value and variance of \(X + Y\).
    2. Simulate the sampling distribution of \(X + Y.\) Desribe the graph of the distribution of \(X + Y\). Compute the mean and variance of the sampling distribution and compare this to the theoretical mean and variance.
    3. Suppose the time (in minutes) Jack takes to complete his statistics homework is \(\text{Unif}[40, 60]\) and the time JIll takes is \(\text{Unif}[40, 60].\) Assume they work independently. One day they announce that their total time to finish an assignment was less than 90 min. How likely is this?

SAME AS YESTERDAY

Exp_x <- (40+60)/2
Var_x <- (60-40)/sqrt(12)
Exp_y <- (45+80)/2
Var_y <- (80-45)/sqrt(12)

Exp_xy <- Exp_x + Exp_y
Exp_xy
[1] 112.5
Var_xy <- (Var_x)^2 + (Var_y)^2
Var_xy
[1] 135.4167
# The mean is 112.5 and the Variance is 135.4167


# sampling distribution of X + Y
X <- runif(1000, 40, 60)
Y <- runif(1000, 45, 80)
total <- X + Y
hist(total)

mean(total)
[1] 112.2367
var(total)
[1] 137.4734
# The distribution if closely symmetric around the mean value. The mean is 112.72 and the variance is 144.6432 of the simulated distribution, which is very close to the theoretical mean and variance. 

\(P(X + Y < 90) =?\)

X <- runif(1000, 40, 60)
Y <- runif(1000, 40, 60) 

total <- X+Y

mean(total < 90)
[1] 0.126
# It is 12.6% likely that Jill and Jake will finish their statistics homework under 90 minutes.