6

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
gung - Reinstate Monica
  • 132,789
  • 81
  • 357
  • 650
Mona Jalal
  • 514
  • 6
  • 17
  • This appears to be a homework question, @MonaJalal. We welcome questions like this, but we treat them differently. Please tell us what you understand thus far, what you've tried & where you are stuck, & we'll try to provide hints to get you unstuck. To better understand the process, you should read the [wiki](http://stats.stackexchange.com/tags/self-study/info) for the `[self-study]` tag. – gung - Reinstate Monica Feb 14 '14 at 03:25
  • @gung How can I consider number of successes in the chi-test? (or any other test) when I have to deal with two hypothesis? the manual is not speaking of number of successes! – Mona Jalal Feb 14 '14 at 03:33
  • I can't follow your question. What "number of successes" are you referring to? Are you still talking about how to test for equality of variances? Do you want to know if to proportions have the same variances? Something else? – gung - Reinstate Monica Feb 14 '14 at 03:36
  • @gung my bad! I was talking about finding the p-value when the two different hypothesis have two different p one equal to alpha and one not equal to alpha! H_0:: p=alpha and H1:: P >< alpha. I know we should use chisq.test for this case but don't know how to consider `number of successes` in the formula! – Mona Jalal Feb 14 '14 at 03:39
  • @gung I could find this but am not sure if can be of use at all `success=dbinom(38,56,0.5)` – Mona Jalal Feb 14 '14 at 03:43
  • I still have no idea what you are asking, @Mona. – gung - Reinstate Monica Feb 14 '14 at 03:43
  • suppose that we want to test H_0: p = 0.1 against H_1: p ≠ 0.1, given that there were 10 successes in a sample of size 32. How can we find the p-value? ....should I use success=dbinom(10,32,0.1) at all? how to start thinking about this problem? – Mona Jalal Feb 14 '14 at 03:45
  • What does this have to do with testing equality of variances b/t groups? – gung - Reinstate Monica Feb 14 '14 at 03:47
  • I am not a stat person and if I knew I wouldn't have asked it! – Mona Jalal Feb 14 '14 at 03:52
  • You're asking about two unrelated things, in such a way that it's difficult to understand what you want. You're required to ask questions that are clear enough to be answered, or they will likely be closed. – Glen_b Feb 14 '14 at 06:35

4 Answers4

10

The test you get with chisq.test is for counts - used to compare proportions or test for independence with categorical data, that kind of thing.

On the other hand, t-tests are usually for comparing means.

There is a test involving variances (a one sample variance test) with normal data that is a chisquare test but you don't get that test with that command.

With two samples and normal data there's a corresponding ratio-of-variances F test for testing equality of variances, but it's generally not recommended (it's not robust to violations of normality). Levene or Browne-Forsythe -- or a few others -- are more often used, typically corresponding to a form of ANOVA on deviations from some measure of location.

When those deviations are bigger on average it would correspond (under some reasonable assumptions) to the variances being bigger.

An equivalent to Levene or Browne-Forsythe could be performed with two-samples (on deviations from the mean or median, respectively) and could even be done as a t-test rather than an ANOVA.

Glen_b
  • 257,508
  • 32
  • 553
  • 939
6

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
Pseudo_Scientist
  • 504
  • 3
  • 11
  • What kind of test should I use if `H_0: p = alpha against H_1: p ≠ alpha` ? How do you contain the number of `successes` in the `R` code? – Mona Jalal Feb 14 '14 at 03:00
  • 2
    This is a possible, but poor, strategy. It is recommended that you use Levene's test or the Brown-Forsythe test for this (see my answer [here](http://stats.stackexchange.com/questions/24022/why-levene-test-of-equality-of-variances-rather-than-f-ratio/24024#24024)). – gung - Reinstate Monica Feb 14 '14 at 03:11
  • @gung but it gives the right answer. – Mona Jalal Feb 14 '14 at 03:32
  • 4
    What is "the right answer" & how do you know it? – gung - Reinstate Monica Feb 14 '14 at 03:33
  • We run the answer using script and we can verify the answer! – Mona Jalal Feb 14 '14 at 03:36
  • How do you "verify the answer"? When you run the script, you get output, but what do you verify it *against*, & what makes you believe that whatever that is, it is "the answer"? – gung - Reinstate Monica Feb 14 '14 at 03:42
  • @Pseudo_Scientist, Its not necessary. While testing for equaltiy of variances we also use Bartlett's Test which is essentially a Chi-Square test. Please refer here(http://en.wikipedia.org/wiki/Bartlett's_test) – NG_21 Feb 14 '14 at 04:41
3

@Mona Jalal, There are various tests used for equality of variances, suited for different situations each having its advantages and limitations. The most common ones are

  1. Bartlett's Test of Sphericity
  2. Levene's test
  3. F- Test

While the post is continuously going back and forth here, may be you want to discuss them in a chat to elaborate about the problem you are facing or you can read about all three of them on Wikipedia.

After that if you face difficulty in implementing those test or interpreting the results in R or Python, you can ask them here by rewording your question

Nick Cox
  • 48,377
  • 8
  • 110
  • 156
NG_21
  • 1,436
  • 3
  • 17
  • 25
  • Questions about particular software implementations would normally be off-topic here, as you have already been told in http://stats.stackexchange.com/questions/86330/offering-data-analytics-as-a-tool-combining-r-and-python ! – Nick Cox Feb 14 '14 at 13:36
1

Note that t.test is for a difference of means, when you actually want to test for a difference of variances based on the null and alternative hypotheses you set up. See:

?var.test
var.test(x, y)
dmartin
  • 3,010
  • 3
  • 22
  • 27
  • Thanks, this is correct. However I am not getting exactly when to use which test! Any light? – Mona Jalal Feb 14 '14 at 02:54
  • `var.test()` implements the F-test mentioned by @Pseudo_Scientist. A more robust test is [?levene.test](http://hosho.ees.hokudai.ac.jp/~kubo/Rdoc/library/car/html/levene.test.html) in the car package. – gung - Reinstate Monica Feb 14 '14 at 03:16