Home > Mobile >  How do I conduct an exact test to test if 3 levels of an outcome are equal to certain proportions in
How do I conduct an exact test to test if 3 levels of an outcome are equal to certain proportions in

Time:10-07

I have 3 levels of depression in my data with the following observed frequencies: none (481), minor (136), and major (128). I want to test if the proportions of the 3 levels in my data are = 0.5, 0.3, and 0.2 respectively.

To do a chi-squared test in R, I did

chisq.test(x = c(481, 136, 128),
           p = c(0.5, 0.3, 0.2))

which gave me this output

Chi-squared test for given probabilities

data:  c(481, 136, 128)
X-squared = 68.819, df = 2, p-value = 1.138e-15

I want to also do an exact test. I tried

fisher.test(x = c(481, 136, 128),
            y = c(0.5, 0.3, 0.2))

which gives me this

Fisher's Exact Test for Count Data

data:  c(481, 136, 128) and c(0.5, 0.3, 0.2)
p-value = 1
alternative hypothesis: two.sided

What am I missing here?

CodePudding user response:

One way to do a similar test is to use prop.test(). I put the vector of successes in first, then the probabilities to test them against, and then the sample size in the n (the same length as x and n is the sum of x ). I would check the help documentation of ?prop.test for more information on the test.

prop.test(x =c(481,136,128), p = c(.5,.3,.2), n = c(745,745,745))

CodePudding user response:

Probably not the best way to do this, but a workaround is doing the fischer.test() with observed counts in one column and expected counts in another like this:

obs_exp <- matrix(c(481, 136, 128, 745 * 0.5, 745 * 0.3, 745 * 0.2), 3, 2)
obs_exp

     [,1]  [,2]
[1,]  481 372.5
[2,]  136 223.5
[3,]  128 149.0

fisher.test(obs_exp)

Warning in fisher.test(obs_exp) :
  'x' has been rounded to integer: Mean relative difference: 0.001677852

    Fisher's Exact Test for Count Data

data:  obs_exp
p-value = 8.152e-09
alternative hypothesis: two.sided
  • Related