set.seed(123)
pop <- c(3, 6, 7, 9, 11, 14)
Mu <- mean(pop)
Mu
[1] 8.333333
Stdev <- sd(pop)
Stdev
[1] 3.88158
W <- numeric(1000)
S <- numeric(1000)
for(i in 1:1000) {
X <- rnorm(3, Mu, Stdev)
W[i] <- mean(X)
S[i] <- sd(X)
}
mean(W)
[1] 8.383122
mean(S)
[1] 3.423547
cdf <- function(x){(3/8) * x^2}
integrate(cdf, 0, 2)$value
[1] 1
integrate(cdf, 0, 1/5)$value
[1] 0.001
\(P(0 \leq Y \leq 1/5) = 0.001\)
A friend claims 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)
# a.
xfx <- function(x){x/10 * exp(-x/10)}
EX <- integrate(xfx, 0, 30)$value
EX
[1] 8.008517
# b.
sims <- 10^4
Y <- numeric(sims)
for(i in 1:sims){
Y[i] <- mean(rexp(30, 1/10))
}
mean(Y)
[1] 9.971208
mean(Y >= 12)
[1] 0.1341
It is not unusual to get a mean of 12 in a sample of size 30 from \(\text{Exp}(\lambda = 1/10)\).
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.\(W\sim N(36, 3.4157)\)
# b.
sims<- 10^4
W <- numeric(sims)
for(i in 1:sims){
X <- rnorm(10, 20, 8)
Y <- rnorm(15, 16, 7)
W[i] <- mean(X) + mean(Y)
}
mean(W)
[1] 35.95246
sd(W)
[1] 3.106992
# c.
sims<- 10^4
W <- numeric(sims)
for(i in 1:sims){
X <- rnorm(10, 20, 8)
Y <- rnorm(15, 16, 7)
W[i] <- X + Y
}
mean(W < 40)
[1] 0.6481
pnorm(39, 36, 3.4157)
[1] 0.8101088
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.\(W\sim N(-3, 1.756)\)
# part b.
sims <- 10^4
W <- numeric(sims)
for(i in 1:sims){
X <- rnorm(9, 7, 3)
Y <- rnorm(12, 10, 5)
W[i] <- mean(X) - mean(Y)
}
mean(W)
[1] -3.006878
sd(W)
[1] 1.761563
# part c.
# simulated answer
sims <- 10^4
W <- numeric(sims)
for(i in 1:sims) {
X <- rnorm(9, 7, 3)
Y <- rnorm(12, 10, 5)
W[i] <- X - Y
}
mean(W < -1.5)
[1] 0.6001
# Exact answer
pnorm(-1.4, -3, 1.756)
[1] 0.8188949
# a.
set.seed(123)
sims <- 10^4
W <- numeric(sims)
V <- numeric(sims)
for(i in 1:sims) {
X <- rnorm(2, 0, 1)
W[i] <- sum(X)
}
mean(W)
[1] -0.01147815
var(W)
[1] 2.002168
# b.
sims <- 10^4
W <- numeric(sims)
V <- numeric(sims)
for(i in 1:sims) {
X <- rnorm(4, 0, 1)
W[i] <- sum(X)
}
mean(W)
[1] 0.01407271
var(W)
[1] 3.97833
# c.
sims <- 10^4
W <- numeric(sims)
V <- numeric(sims)
for(i in 1:sims) {
X <- rnorm(5, 0, 1)
W[i] <- sum(X)
}
mean(W)
[1] 0.02408073
var(W)
[1] 4.850376
The sampling distribution is approximately normal, so n must be sufficiently large for this distribution.
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.
# a.
xfx <- function(x){x/20}
EX <- integrate(xfx, 40, 60)$value
yfy <- function(x){x/35}
EY <- integrate(yfy, 45, 80)$value
EX + EY
[1] 112.5
vx <- function(x){
(x - EX)^2 / 20
}
VX <- integrate(vx, 40, 60)$value
vy <- function(x){
(x - EY)^2 / 35
}
VY <- integrate(vy, 45, 80)$value
VX + VY
[1] 135.4167
# b.
sims <- 10^4
result_means <- numeric(sims)
result_var <- numeric(sims)
for(i in 1:sims) {
X <- runif(sims, 40, 60)
Y <- runif(sims, 45, 80)
result_means[i] <- mean(X) + mean(Y)
result_var[i] <- var(X) + var(Y)
}
mean(result_means)
[1] 112.5002
mean(result_var)
[1] 135.4123
\(P(X + Y < 90) = 0.125\)
# part c
# P(W < 90)
sims <- 10^4
result <- numeric(sims)
for(i in 1:sims) {
X <- runif(sims, 40, 60)
Y <- runif(sims, 40, 60)
result[i] <- X + Y
}
mean(result < 90)
[1] 0.1166