0
$\begingroup$

I would like to ask whether you could suggest me a test for the following situation:

I have two groups (A and B). Both groups have data for a categorical variable called X that has 3 categories. I would like to test whether the answers for each of the category are different between two groups. For example, I want to know if the number of observations in the first category is significantly greater in group A compared to the number of observations in the same category in group B.

$\endgroup$

1 Answer 1

1
$\begingroup$

If I understand correctly, it sounds like you should be able to take your data and produce a table like this one (I'm using fake data here):

x A B
level_1 500 450
level_2 300 200
level_3 200 350

Basically a table showing the counts across each level and group. Based on this table, we see that we have 1,000 people in each group. We can also see that, in the sample, $\frac{500}{500+300+200}=50\%$ of people in group A have x = level_1. You want to find out (i.e. test) whether this proportion is significantly different from the proportion of x = level_1 in group B, which in this case is $\frac{450}{450+200+350}=45\%$. And then you want to repeat this test for each level.

A simple way to do this is by carrying out a test of proportions using prop.test() in R. For example, for level_1 it would be:

prop.test(c(500, 450), c(500+300+200, 450+200+350))

### Output ###

    2-sample test for equality of proportions with continuity correction

data:  c(500, 450) out of c(500 + 300 + 200, 450 + 200 + 350)
X-squared = 4.814, df = 1, p-value = 0.02823
alternative hypothesis: two.sided
95 percent confidence interval:
 0.005283576 0.094716424
sample estimates:
prop 1 prop 2 
  0.50   0.45 

This gives you:

  1. The estimated proportions at the bottom (0.50 vs 0.45)
  2. The 95% confidence interval for the difference in proportions (0.005283576 0.094716424)
  3. The $\chi^2$ statistic for your test (4.814)
  4. The p-value for your test (0.02823)

So with this made-up data, we would conclude that the proportion of people with x = level_1 in group A is significantly different from group B's (at the 5% significance level). Then we would repeat this for the other two levels.

Note that if you were only interested in whether a proportion was greater in group A than in group B, you would need to set the alternative = 'greater' in prop.test(). This would make your test a one-sided one (the default test is two-sided).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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