I would like to ask for your lights on the following questions (especially B).
Also, I am not sure for (A), since the sample is not normally distributed (should I ignore this, given its large size?)
Using only base R...
Get a random sample of 1000 from diamonds$carat (ggplot2 package).
A. Test 0: ^2 = 0.225 versus 1: ^2 ≠ 0.225, at significance level 4%.
B. If the true value of the population variance (for the distribution of carats) is 0.231, calculate the power of the control.
My attempt for (A):
set.seed(1)
sp_car = sample(diamonds$carat, 1000, replace = F)
alpha = 0.04
df = length(sp_car) - 1
#upper
qchisq(1 - alpha / 2, df)
#lower
qchisq(alpha / 2, df)
samp_var = var(sp_car)
var0 = 0.225
#T stat
Tst = (df) * samp_var / var0
Tst > qchisq(1 - alpha / 2, df)
Tst < qchisq(alpha / 2, df)
My attempt for B:
var1 = 0.231
# probability of rejecting H0
beta = sum(pchisq(var0 * qchisq(alpha / 2, df) / var1, df),
1 - pchisq(var0 * qchisq(1 - alpha / 2, df) / var1, df))
# power
1 - beta
Thank you for your time!