I feel a little stupid for asking this question, but somehow I can't figure it out!
I am trying to see if participants are equally randomly assigned to two groups, so the contingency table looks like the below
Condition A Condition B
30 40
The main data look like the one below
Variable 1
P1 Condition A
P2 Condition B
P3 Condition A
P4 Condition A
P5 Condition B
P6 Condition A
. .
. .
. .
What would be the best way/function to check (using R) that they were equally distributed to either of the conditions?
Thank you a lot!
You want a chisq.test()
, which operates on a contingency table, not the raw vector of groups. The usage is simply like this:
> x = factor(sample(c('A', 'B'), 1000, replace = TRUE, prob = c(0.6, 0.4)))
> table(x)
x
A B
605 395
> chisq.test(table(x))
Chi-squared test for given probabilities
data: table(x)
X-squared = 44.1, df = 1, p-value = 3.12e-11