In: Statistics and Probability
2. Assume that X1, . . . , Xn are independent copies of the random variable X = Y + V , where Y ∼ N(µ, σ2 ) and V ∼ U(−ν, ν), ν > 0, and Y and V are independent. We will consider the hypotheses
H0 : µ = µ0 and
HA : µ does not equal µ0.
(a) It can be shown that E(X) = µ and var(X) = σ2 + ν2/3. Set µ = 60, σ = 3, and ν = 4. Estimate E(X) and var(X) using Monte Carlo simulations based on drawing n = 105 i.i.d. copies of X. You can only use the runif function to generate draws from a distribution, so you will need to take the necessary steps to draw realizations from the appropriate distributions. Comment on the results.
(b) Let T = (√ n) * (Xbar − µ0)/S be the usual t-test test statistic. Perform a simulation to check whether the distribution of T is well approximated by a t-distribution with n−1 degrees of freedom when n = 20, µ = µ0 = 65, σ = 3, and ν = 4. Use a QQ-plot (you may use the qt function) and set reps = 1e4. Comment on the results.
(c) Set n = 20, µ0 = 68, µ = 66, ν = 5, and α = 0.05. Produce a plot of a simulated estimate of the power curve of this test formed by increasing σ from 0.5. Select the sequence of values for σ so that the simulated estimate of the power decreases from roughly 80% to roughly 20%. Comment on the results.
Given . Let
a) The R code to generate 105 RV from the given distributions arnd calculating mean and variance using simulation is given below.
n <- 105
sigma <- 3
mu <- 60
v <- 4
V <- runif(n,min = -v , max = v)
Y <- rnorm(n, mean = mu, sd = sigma)
X <- V + Y
EX <- mean(X)
EX
VarX <-var(X)
VarX
> EX
[1] 59.20977
> VarX
[1] 13.71963
The theoretical value of mean is , the simulated mean is .
The theoretical value of variance is , the simulated variance is . The theoretical and simulated values are approximately equal.
b) The R code to simulate 10000 repetitions of the statistic and plotting the density of and with theoretical T-distribution with 19 degrees of freedom given below.
m <- 10000
n <- 20
sigma <- 3
mu <- 60
mu0 <- mu
v <- 4
T <- array (dim = m)
for (i in 1:m)
{
V <- runif(n,min = -v , max = v)
Y <- rnorm(n, mean = mu, sd = sigma)
X <- V + Y
T[i] <- sqrt(n)*(mean(X)-mu0)/sd(X)
}
qqplot(T,qt(seq(-5,5, length = m),df= n-1),main = "QQ Plot", ylab =
"Density", col = "blue")
Both the distributions matches.
c ) The power of a test is .
The power is plotted against as given below.
R code below.
n <- 20
sigma <- 3
mu <- 66
mu0 <- 68
v <- 4
alpha <- 0.05
P <- function(x)
{
pnorm(qnorm(alpha/2)+(mu0-mu)*sqrt(n)/x)
}
curve(P(x), col="darkred", xlim = c(0.5, 10), main = "Power",
lwd=2)