I have a table where column A is trials, and the remaining columns are successes on different steps. Row C is a control, and row T is a test.
A B C D E F G
C 19144 2537 2395 2366 2310 2256 2234
T 19133 2269 2058 2032 2007 1960 1942
I want to perform a prop.test comparing control versus test for each step (С vs T for B; С vs T for C, С vs T for В and so on). 6 steps in total. I want to save p-value for each step in a third row.
Is there a way to compute a p-value for each step without writing a prop.test code 6 times for each step?
If you can write the code to do any one of the 6, that could be straightforwardly adapted to repeat for the others.
If you provide the code, I will show you how. We can also verify that the solution that does all 6, contains the value for the one that you found.
so this is the core of what you would do, repeatedly, changing 2 to 3 to 4 to 5 to 6 where it appears in the first df[] clause.
So the approach would be to make that into a function where a variable stands in for that number; and use an iterator, (apply*) family of functions, or (purrr if tidyverse is favoured).
For example
(my_pvalues <- sapply(2:6, function(x_){
prop.test(x=c(df[,x_]), n=c(df[,1]), p = NULL,
alternative = c("two.sided"),
conf.level = 0.95, correct = FALSE)$p.value
}))