2

I am hoping to compare proportions from an experiment with a two-by-two factorial design. I use R for my stats.

I know how to compare two proportions, or do an ANOVA-like test on many proportions, by using prop.test.

For example,

num_positive = c(10, 30)
num_total = c(100,180)
prop.test(x = num_positive, num_total)

or for the one-way-ANOVA-like situation:

num_positive = c(10, 30, 80)
num_total = c(100,180, 200)
prop.test(x = num_positive, num_total)

But I don't know how to do this with a two-way situation. prop.test doesn't accept any sort of model structure and the data are proportion data so don't make sense to be analyzed using an ANOVA.

Ideally, I'd want a function that does something like this:

num_positive = c(10, 30, 80, 100)
num_total = c(100,180, 200, 200)
factorA = c("A","A","B","B")
factorZ = c("Z","Y","Z","Y")

prop.test(cbind(num_positive, num_total) ~ factorA * factorZ)

Thanks for any help!

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
jeremymchacon
  • 53
  • 1
  • 7

1 Answers1

3

There is no way to do exactly what you are thinking of, as far as I know - i.e. to compare proportions in this way.

However, you can use cbind to combine the proportions into one variable, which you then include in a generalized linear model (glm), e.g.

y <- cbind(num_positive, num_total)

Then you can compare your y variable against your factors, e.g.

model <- glm(y ~ factorA * factorZ, binomial)

I suggest reading up on the correct link function to use in the glm, also consider whether to enter your factors as a categorical (levels) variable.

pudspop
  • 97
  • 1
  • 7