# ggplot Chi Square for a DF and a special Level of Significance [closed]

I am working on Datascience course on R (Jupiter Notebook ), and I would like to plot the Chi Square for learner in order to let them feel the meaning of Null and Alternative hypothesis.

So I would like to graph (ggplot if possible ), with a grayed zone, a Chi Square for a special DF and a Level of significance on R program.

• If you have a question about a particular statistical test, based on known data, then please ask that. Questions that are primarily about using a particular program are 'off topic' here. – BruceET Oct 10 at 5:52
• Your body text says you have a "special level of significance" but then the diagram in your post indicates it's 5% (which seems anything but special). Is the "$\alpha$=0.05 on your plot not meant to be there? – Glen_b -Reinstate Monica Oct 10 at 11:14
• I updated my question, though I depicted in my previous version the R programming language (but it was written in small letter ). Thanks for your remarks. – SAM.Am Oct 11 at 6:42

The question has gaps and inconsistencies. I have made guesses in order to give an answer that I hope is helpful.

Although you do not say so, you may have a random sample of size $$n=25$$ from a normal population with sample variance $$S^2 = 12.25$$ and wish to do a test about the sample variance $$\sigma^2:$$ Specifically, to test $$H_0: \sigma^2 \ge 7.2^2$$ against $$H_a: \sigma^2 < 7.2^2$$ at the 5% level of significance.

Then then you have $$\frac{(n-1)S^2}{\sigma^2} \sim \mathsf{Chisq}(\nu=24).$$ Because quantile .05 of this distribution is 13.85, you reject $$H_0$$ at the 5% level because the test statistic $$\frac{24(12.25)}{7.2^2} = 5.67$$ is smaller than the critical value 13.85.[This is hardly a surprising result because the sample variance $$S^2 = 12.25$$ is much smaller than the hypothetical value of the population variance $$\sigma^2 = 7.2^2 = 51.84.]$$

qchisq(.05, 24)
[1] 13.84843

24*12.25/7.2^2
[1] 5.671296


The figure below shows the density function of $$\mathsf{Chisq}(\nu=24),$$ along with the critical value (dotted red line) and the test statistic (solid black). The area to the left of the red line is 0.05.

R code for figure:

curve(dchisq(x, 24), 0, 75, lwd=2,
ylab="PDF", xlab="Chi-sq", main="Density of CHISQ(24)")
abline(h=0, col="green2"); abline(v=0, col="green2")
abline(v=13.85, col="red", lwd=2, lty="dotted")
abline(v = 5.67, lwd=2)


Notes: There are inconsistencies in your graph. The axes are not labeled. The only chi-squared distribution for which the 5% critical value is 13.85 has 24 degrees of freedom, which does not match the shape of your density curve. (There is no chi-squared distribution with 5% lower critical value 5.67.) It seems that your figure reverses labels for the test statistic and the critical value.

Below is output from Minitab statistical software. [Some unnecessary items in the output have been edited out; Minitab shows a P-value rather than a critical value.]

Test for One Variance

Method

Null hypothesis         σ = 7.2
Alternative hypothesis  σ < 7.2

Statistics

N  StDev  Variance
25   3.50     12.25

Test

Test
Method      Statistic  DF  P-Value
Chi-Square       5.67  24    0.000