Computing a p-value of a 2-sided Chi-squared test for one variance Below is a simple question from a textbook. I answer the question by computing the critical values for a critical region $\alpha = 0.05$ for a Chi-squared distribution (42.95, 86.83) and then commenting that the chi-squared value (63.75) is within the interval. However, the book gives a p-value and I don't know how this is calculated.

Aflotoxins produced by mold on peanut crops in Virginia must be
monitored. A sample of 64 batches of peanuts reveals levels of 24.17
ppm, on average, with a variance of 4.25 ppm. Test the hypothesis that
$\sigma^2$ = 4.2 ppm against the alternative that $\sigma^2 \ne 4.2$
ppm. Use a P -value in your conclusion.

 A: It seems you are using the relationship
$$\frac{(n-1)S^2}{\sigma^2}\sim\mathsf{Chisq}(\nu=n-1),$$
where $S^2$ is the variance of a sample of size $n=64$
from a normal distribution with variance $\sigma^2,$
for your test of
$H_0:\sigma^2 = 4.2$
against
$H_a:\sigma^2\ne 4.2$
at the 5% level of significance.
The statistic $Q \sim \mathsf{Chisq}(63)$ has
$$P(42.95 < Q < 86.83) = 0.95,$$ so you reject $H_0$ at the 5%
level if $Q \le 42.95$ or $Q \ge 86.83.$ For your data
$Q = 63/75,$ which lies between the two critical values
$42.95$ and $86.83,$ so you do not reject $H_0.$ In R,
qchisq(c(.025,.975), 63)
[1] 42.95027 86.82959

In your problem the test statistic is
$$63S^2/4.2 = 63(4.25)/4.2 = 63.75$$
The probability of a more extreme result is the
probability in the right tail of $\mathsf{Chisq}(63)$
beyond $63.75,$ which is $0.45.$ This is the P-value
for a one-sided test (alternative $H_a: \sigma^2 > 4.2).$
It is customary to double that for a
two-sided test (alternative $H_a: \sigma^2 \ne 4.2),$ reporting P-value $0.90.$
1 - pchisq(63.75, 63)
[1] 0.4498938


Notes: (1) A second reference is here. See the P-value for the aquarium example, which is consistent with
doubling the P-value of a one-sided test to
get the P-value of a two-sided test.
pchisq(5.2094, 14)*2
[1] 0.03464066

(2) I do not find a test in the core of R for
a single variance. Here is output for
such a test from a recent version of Minitab (output edited for relevance).
Test for One Variance 

Method

Null hypothesis         σ-squared = 4.2
Alternative hypothesis  σ-squared ≠ 4.2

The chi-square method is only for the normal distribution.

Statistics

 N  StDev  Variance
64   2.06      4.25

                 Test
 Method      Statistic  DF  P-Value
 Chi-Square      63.75  63    0.900

