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!
hist(replicate(5e2, var(sample(diamonds$carat, 1e3))))
(which takes less than a second to run) will give you the information you need to answer your questions. $\endgroup$qchisq
. This is part of the basicR
installation. Second, the pdf is not invertible when the degrees of freedom value exceeds $1,$ nor is it applicable in this context anyway. You probably meant to refer to the inverse cdf. $\endgroup$qchisq
inverts the cdf, which is what is needed here. That's simply incorrect that you want to invert the pdf. As I pointed out, the pdf isn't even invertible. It is not involved in computing two-tailed p-values (unless you actually integrate it to compute the cdf!). $\endgroup$