1

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!

John Colby
  • 22,169
  • 4
  • 57
  • 69
user240313
  • 17
  • 6
  • `table(x$Variable1)`? – r2evans May 16 '19 at 20:58
  • thanks for the quick reply - would there be a way to statistically check the difference? – user240313 May 16 '19 at 21:00
  • If you are trying to check both the variable with `p = p1 p2 ...` then use `table(x$p, x$Variable1` – akash87 May 16 '19 at 21:00
  • I'd think a chi-squared test would be appropriate (`chisq.test` in R). If you want more discussion on the statistical testing required to confirm/refute distributional claims, then it is a little more appropriate at [Cross Validated](https://stats.stackexchange.com/). – r2evans May 16 '19 at 21:05
  • thanks for the reply, but it seems to me that table(x$participantID, x$variable 1) does not give a statistical result – user240313 May 16 '19 at 21:06
  • You are right, `table` does not give a statistical result. `chisq.test` does, and tends to operate on contingency tables such as the output of `table`. – r2evans May 16 '19 at 21:08
  • Thank you for the reply & I will keep that in mind in the future!! Please correct me if I am wrong, but wouldn't a chi-square test require at least two cateogorical IVs? I still can't seem to wrap my head around it. – user240313 May 16 '19 at 21:18
  • @r2evans after reading up some documents, I figured binom.test could be used - thanks for your help – user240313 May 17 '19 at 06:43
  • That sounds reasonable. – r2evans May 17 '19 at 09:12

1 Answers1

1

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
John Colby
  • 22,169
  • 4
  • 57
  • 69