Quidest?

Two-sample tests of proportions

· Lorenzo Drumond

What if we have more than one sample? And in each sample, we could have more than one response categories. E.g. two different gender groups expressing their preference on the websites A, B and C.

This is the case of two-sample tests of proportions (or n-sample).

Another test that is getting popular is the G test, which is also an asymptotic test, which is meant to be more accurate.

An exact test for this kind of scenario is the Fishers’ exact test. It was originally developed for 2x2 tests, but can be generalized.

Similarly to before, even if see that there is significant differences in the proportions, we need to run post-hoc tests to determine where they lie.

 1prefsABCsex = read.csv("prefsABCsex.csv")
 2View(prefsABCsex)
 3prefsABCsex$Subject = factor(prefsABCsex$Subject) # convert to nominal factor
 4prefsABCsex$Pref = factor(prefsABCsex$Pref) # Rv4
 5prefsABCsex$Sex = factor(prefsABCsex$Sex) # Rv4
 6summary(prefsABCsex)
 7plot(prefsABCsex[prefsABCsex$Sex == "M",]$Pref)
 8plot(prefsABCsex[prefsABCsex$Sex == "F",]$Pref)
 9
10prfs = xtabs( ~ Pref + Sex, data=prefsABCsex)
11View(prfs)
12chisq.test(prfs)
13
14library(RVAideMemoire)
15G.test(prfs)
16
17fisher.test(prfs)
18
19ma = binom.test(sum(prefsABCsex[prefsABCsex$Sex == "M",]$Pref == "A"), nrow(prefsABCsex[prefsABCsex$Sex == "M",]), p=1/3)
20mb = binom.test(sum(prefsABCsex[prefsABCsex$Sex == "M",]$Pref == "B"), nrow(prefsABCsex[prefsABCsex$Sex == "M",]), p=1/3)
21mc = binom.test(sum(prefsABCsex[prefsABCsex$Sex == "M",]$Pref == "C"), nrow(prefsABCsex[prefsABCsex$Sex == "M",]), p=1/3)
22p.adjust(c(ma$p.value, mb$p.value, mc$p.value), method="holm") # correct for multiple comparisons
23
24fa = binom.test(sum(prefsABCsex[prefsABCsex$Sex == "F",]$Pref == "A"), nrow(prefsABCsex[prefsABCsex$Sex == "F",]), p=1/3)
25fb = binom.test(sum(prefsABCsex[prefsABCsex$Sex == "F",]$Pref == "B"), nrow(prefsABCsex[prefsABCsex$Sex == "F",]), p=1/3)
26fc = binom.test(sum(prefsABCsex[prefsABCsex$Sex == "F",]$Pref == "C"), nrow(prefsABCsex[prefsABCsex$Sex == "F",]), p=1/3)
27p.adjust(c(fa$p.value, fb$p.value, fc$p.value), method="holm") # correct for multiple comparisons

References

Next -> example-analysis-of-an-ab-test

#statistics #designing_running_and_analyzing_experiments #theory #experiment #test #week2 #proportions #design #rlang #coursera