I have my data summarized in a table and want to run poisson.exact tests on each summarized row. I am reading my data from a csv file. I can get the desired output if I run the query on just one row of data. I'm having trouble figuring out how to run a poisson test for each row separately, though. enter image description here
results <- tribble(
~group, ~a, ~b, ~c, ~d,
1, 302, 70137, 180541.2398, 3158205.224,
2, 3673, 66766, 1298973.019, 2039773.445,
3, 16142, 54297, 958777.9383, 2379968.526,
4, 50322, 20117, 900454.267, 2438292.197
)
The results2 code works for one row and contains all the output I'm looking for.
results <- tribble(
~group, ~a, ~b, ~c, ~d,
1, 302, 70137, 180541.2398, 3158205.224
)
results2 <- do(results, tidy(poisson.test(c(.$a,.$b),c(.$c,.$d))))
I can get the df2 code to work on the multiple rows version but it calculates a rate for a/b and I'm looking for a rate ratio plus all the other fields from poisson.test above.
results <- tribble(
~group, ~a, ~b, ~c, ~d,
1, 302, 70137, 180541.2398, 3158205.224,
2, 3673, 66766, 1298973.019, 2039773.445,
3, 16142, 54297, 958777.9383, 2379968.526,
4, 50322, 20117, 900454.267, 2438292.197
)
df2=results %>%
mutate (rate = map2_dbl(.$a,.$b, ~poisson.exact(.x, .y)$estimate))
Can anyone help me get the first output for every row in my table?