-1

I am trying to do the proportion test, but an error is appearing and I cannot solve it. My DF refers to people who have been treated for stroke in two different hospitals. The first column is from the ICD. My DF:

ICD <- c ("I64", "I609", "I638", "I694", "I671", "I618", "I652", "I639", "I620", "I629")
HOSP1 <- c (1286,39,66,54,23,43,16,12,3,16)
HOSP2 <-c (818,28,7,27,5,19,11,20,27,4)
DF <- data.frame (ICD, HOSP1, HOSP2)

My testing:

prop.test(x=(DF$HOSP1,DF$HOSP2))

My mistake:

Error: unexpected ',' in "prop.test (x = (DF $ HOSP1,"

I would like to help to solve this test of proportion. What am I missing?

Bruno Avila
  • 296
  • 2
  • 10

1 Answers1

1

There are a couple of options, which you can learn more about with ?prop.test.

You can separately specify a vector x listing numbers of successes (strokes in hospital 1) and a vector n listing numbers of trials (total strokes), like so:

prop.test(x = DF$HOSP1, n = DF$HOSP1 + DF$HOSP2)

Or, you can specify a matrix x whose first column lists numbers of successes (strokes in hospital 1) and whose second column lists numbers of failures (strokes in hospital 2), like so:

prop.test(x = as.matrix(DF[, c("HOSP1", "HOSP2")]))
Mikael Jagan
  • 9,012
  • 2
  • 17
  • 48
  • Thanks for the sugestion. However, your suggestion tells me that hospitals are dependent, which is not true, they are independent. My question is: Are the proportional stroke rates in the two hospitals independent? So, what is your suggestion for using the prop.test? – Bruno Avila Aug 12 '20 at 16:25
  • `prop.test()` assesses the null hypothesis that the proportion of strokes occurring in hospital 1 is the same across stroke categories. If you want to assess the null hypothesis that the distribution of strokes across stroke categories is the same between hospitals, then you can use `chisq.test()`, specifically `chisq.test(x = as.matrix(DF[, c("HOSP1", "HOSP2")]))`. However, you will find that `chisq.test()` returns the same chi-squared statistic and degrees of freedom as `prop.test()`, because, under the hood, they are doing the same thing. – Mikael Jagan Aug 12 '20 at 18:43
  • If you have further statistical questions, then I suggest you ask over at [Cross Validated](https://stats.stackexchange.com/). – Mikael Jagan Aug 12 '20 at 18:47