1

I am attempting to draw out confidence limits from some count data I have. I can do this manually, for example

poisson.test(53,conf.level = 0.95)

LCI = 39.7, UCI = 69.3

So I have some basics! I have some very very basic test data to practice on, but I am having trouble applying poisson.test for each row and then extracting the LCI/UCI. The dataset is:

region <- c("A","B")
count <- c(53,36)
data <- data.frame(region,count)

Ideally, my output would look like this:

enter image description here

I have tried using apply() but that hasn't quite worked. Any tips on how to get this out and into a table without having to perform the manual calculation and enter it into a spreadsheet? Thanks in advance!

JamesW
  • 127
  • 3

1 Answers1

1

Select the count column and apply poisson.test on each of its element with sapply.

data[c("LCI", "UCI")] <- t(sapply(data[["count"]], function(x) poisson.test(x)$conf.int))

#   region count      LCI      UCI
# 1      A    53 39.70064 69.32530
# 2      B    36 25.21396 49.83917
Maël
  • 45,206
  • 3
  • 29
  • 67