How does what we observe compare to what would happen if the null hypothesis were true and you repeat the process many number of times?
funcE <- function(x){
lambda <- (1/5)
x*(lambda*exp(-lambda*x))
}
E_x <- integrate(funcE, lower = 0, upper = Inf)$value
E_x
## [1] 5
E_xhat <- integrate(funcE, lower = 0, upper = Inf)$value
E_xhat
## [1] 5
funcV <- function(x){
lambda <- (1/5)
((x - E_x)^2)*(lambda*exp(-lambda*x))
}
V_x <- integrate(funcV, lower = 0, upper = Inf)$value
V_x
## [1] 25
V_xhat <- integrate(funcV, lower = 0, upper = Inf)$value
V_xhat
## [1] 25
\(E(x) = 5\)
\(E(\hat x) = 5\)
\(V(x) = 25\)
\(V(\hat x) = 25\)
sims <- 10^4 -1
X <- numeric(sims)
for (i in 1:sims) {
X[i] <- mean(rexp(25, rate = 1/5))
}
E_xbar <- mean(X)
E_xbar
## [1] 4.989852
V_xbar <- var(X)
V_xbar
## [1] 1.011517
\(\hat {E(\hat x)} = 4.988124\)
\(\hat {V(\hat x)} = 0.9792322\)
P <- (sum(X >= 7) + 1) / (sims + 1)
P
## [1] 0.0337