Take the 2-minute tour ×
Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. It's 100% free, no registration required.

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
share|improve this question
    
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 for the [self-study] tag. –  gung Feb 14 at 3: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 at 3: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 Feb 14 at 3: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 at 3: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 at 3:43
show 5 more comments

4 Answers 4

up vote 5 down vote accepted

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
share|improve this answer
    
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 at 3:00
1  
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). –  gung Feb 14 at 3:11
    
@gung but it gives the right answer. –  Mona Jalal Feb 14 at 3:32
3  
What is "the right answer" & how do you know it? –  gung Feb 14 at 3:33
    
We run the answer using script and we can verify the answer! –  Mona Jalal Feb 14 at 3:36
show 2 more comments

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.

share|improve this answer
add comment

@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

share|improve this answer
    
Questions about particular software implementations would normally be off-topic here, as you have already been told in stats.stackexchange.com/questions/86330/… ! –  Nick Cox Feb 14 at 13:36
add comment

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)
share|improve this answer
    
Thanks, this is correct. However I am not getting exactly when to use which test! Any light? –  Mona Jalal Feb 14 at 2:54
    
var.test() implements the F-test mentioned by @Pseudo_Scientist. A more robust test is ?levene.test in the car package. –  gung Feb 14 at 3:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.