Solved – Do you use a chi-squared test or a t-test for equality of variances

chi-squared-testrself-studyt-testvariance

How can I find if I should t-test or chi-squared test if I am given a problem like the following?

Consider testing $H_0: \sigma^2_X = \sigma^2_Y$ against $H_1: \sigma^2_X ≠ \sigma^2_Y$ from two independent samples from normal populations with unknown means $\mu_X$ and $\mu_Y$ and standard deviations $\sigma_X$ and $\sigma_Y$. The $X$'s are 11.4, 9.7, 11.4, 13.3, 7.4, 8.5, 13.4, 17.4, 12.7. The $Y$'s are 3.2, 2.7, 5.5, -0.9, -1.8. Find the value of the test statistic.

P.S.: I know how to do the chisq.test and t.test when I just one hypothesis ($H_0$)! How should I write R script to do the above problem when I have more than one hypothesis? What are some good external R related script to this question that I can cover for seeing similar example?

> X = c( 11.4, 9.7, 11.4, 13.3, 7.4, 8.5, 13.4, 17.4, 12.7)
> Y = c(3.2, 2.7, 5.5, -0.9, -1.8)
> ?t.test
> t.test(X, Y)

    Welch Two Sample t-test

data:  X and Y
t = 5.9114, df = 8.306, p-value = 0.0003089
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
  6.092637 13.805141
sample estimates:
mean of x mean of y 
 11.68889   1.74000 

> chisq.test(X, Y)
Error in chisq.test(X, Y) : 'x' and 'y' must have the same length

Best Answer

You do neither a T-test nor a $\chi^{2}$ test when testing $H_0: \sigma^{2}_X = \sigma^2_Y$ against $H_a: \sigma^{2}_X \neq \sigma^2_Y$. For testing the equality of variances between two normally distributed populations you use the F-test of equality of variances, which reformulates your test as $H_0: \frac{\sigma^{2}_X}{\sigma^2_Y} = 1$ against $H_a: \frac{\sigma^{2}_X}{\sigma^2_Y} \neq 1$. In R, you should run

> X=c( 11.4, 9.7, 11.4, 13.3, 7.4, 8.5, 13.4, 17.4, 12.7)
> Y=c(3.2, 2.7, 5.5, -0.9, -1.8)
> var.test(x,y)

F test to compare two variances

data:  X and Y
F = 0.979, num df = 8, denom df = 4, p-value = 0.9033
alternative hypothesis: true ratio of variances is not equal to 1
95 percent confidence interval:
0.109 4.947
sample estimates:
ratio of variances 
         0.979