0
$\begingroup$

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!

$\endgroup$
9
  • 1
    $\begingroup$ You should tell your readers you are sampling from a dataset of 53,940 values. The code 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$
    – whuber
    Commented Dec 20, 2021 at 1:51
  • $\begingroup$ @Onyambu Re "not readily available in R:" On the contrary, see the help page for qchisq. This is part of the basic R 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$
    – whuber
    Commented Jan 2, 2022 at 18:48
  • $\begingroup$ @Onyambu Yes, 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$
    – whuber
    Commented Jan 2, 2022 at 18:55
  • $\begingroup$ @whuber in the link provided above, the value 14.6489 was computed from the inverse pdf. ie both 14.6489 and 15.35667 have the same density value. Is that not the inverting the pdf? We also have 17 degrees of freedom. Isnt that the way to compute p-value for two sided chi-sq test? or is the link wrong? $\endgroup$
    – Onyambu
    Commented Jan 2, 2022 at 19:22
  • 1
    $\begingroup$ @Onyambu That procedure is not inverting the pdf, although in a preliminary step it does indeed find an $x$ at which the pdf has a specified density (so I think I now understand why you might have characterized the test as you did). It is a test based on a shortest-length two-sided confidence interval. The actual p-value calculations invert the cdf, twice. $\endgroup$
    – whuber
    Commented Jan 3, 2022 at 3:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.