-
Notifications
You must be signed in to change notification settings - Fork 19
Description
Hi,
I would like to ask you one question about the function VarTest() from the package DecsTools: What is the formula for computing the p-value of a two-sided alternative?
I expected classic formula for p.value = 2 * min(pchisq(q = X.squared, df = n - 1), 1 - pchisq(q = X.squared, df = n - 1)), but it does not fit.
For example, my dataset contains the following values:
data <- c(168, 174, 187, 170, 181, 177, 172, 176, 169, 175, 174, 175, 168, 172, 176, 183, 186, 172, 185, 171, 176, 178, 182, 161, 174, 177, 164, 180, 175, 176, 180, 172, 182, 181, 171, 183, 178, 188, 170, 187, 178, 178, 173, 184, 176, 174, 163, 171, 172, 169, 170, 172, 175, 175, 165, 168, 170, 174, 175, 166, 181, 170, 168, 157, 172, 173, 176, 183, 178, 181, 176, 167, 170, 185, 169, 175, 179, 175, 177, 170, 179, 173, 177, 176, 174, 185, 181, 175, 164, 171, 165, 169, 184, 181, 184, 180, 171, 170, 168, 175, 177, 183, 174, 165, 172, 171, 172, 162, 170) n <- length(data) # 109
The value of sigma = 7.052. Test the H0: sigma^2 = 7.052^2 vs H1: sigma^2 != 7.052^2
Significance level: alpha = 0.10.
Test statistic + critical value (OK):
alpha <- 0.10 (X.squared <- DescTools::VarTest(x = data, sigma.squared = 7.052 ^ 2, alternative = "two.sided", conf.level = 1 - alpha)$stat) # 83.99514 qchisq(p = alpha / 2, df = n - 1) # 85.0149 qchisq(p = 1 - alpha / 2, df = n - 1) # 133.2569
The X.squared = 83.995, W = <0; 85.0149> U <133.2569; Inf), H0 is rejected.
Confidence interval + c (OK):
DescTools::VarTest(x = data, sigma.squared = 7.052 ^ 2, alternative = "two.sided", conf.level = 1 - alpha)$conf.int[1:2] # 31.34651 49.13418
The CI = (31.34651; 49.13418), c = 7.052^2 = 49.7307, H0 is rejected.
The p-value + significance level (NOT OK):
DescTools::VarTest(x = data, sigma.squared = 7.052 ^ 2, alternative = "two.sided", conf.level = 1 - alpha)$p.val # 0.1034914
p.val = 0.1034914, alpha = 0.10, H0 IS NOT REJECTED.
My computation of p-value according to common formula 2 * min(pchisq(q = X.squared, df = n - 1), 1 - pchisq(q = X.squared, df = n - 1)):
2 * min(pchisq(q = X.squared, df = n - 1), 1 - pchisq(q = X.squared, df = n - 1)) # 0.08422791
p.val = 0.08422791, alpha = 0.10, H0 is rejected, OK
So, I would like to ask you if there is a possibility that the computation of the p-value for the two-sided alternative implemented in the VarTest() function contains a mistake or if there is some other way (method) how the p-value was computed. In the second case, I would like to ask you which method was used and why?
Thank you very much for your answer.