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()
# 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
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.
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
The expected value of a sample mean is 1/(1/10) which is 10.
The proportion of sample means that are as large or larger than 12 are 0.126.
Because the proportion of sample means at 0.126 is greater than 0.05, we cannot say that the mean of 12 is unusual.
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}.\)
R and plot your results. Check that the simulated mean and standard error are close to the theoretical mean and standard error.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
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}.\)
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.#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
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.
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.
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.