I am trying to calculate the confidence intervals of some rates. I am using tidyverse and epitools to calculate CI from Byar's method.
I am almost certainly doing something wrong.
library (tidyverse)
library (epitools)
# here's my made up data
DISEASE = c("Marco Polio","Marco Polio","Marco Polio","Marco Polio","Marco Polio",
"Mumps","Mumps","Mumps","Mumps","Mumps",
"Chicky Pox","Chicky Pox","Chicky Pox","Chicky Pox","Chicky Pox")
YEAR = c(2011, 2012, 2013, 2014, 2015,
2011, 2012, 2013, 2014, 2015,
2011, 2012, 2013, 2014, 2015)
VALUE = c(82,89,79,51,51,
79,91,69,89,78,
71,69,95,61,87)
AREA =c("A", "B","C")
DATA = data.frame(DISEASE, YEAR, VALUE,AREA)
# this is a simplification, I have the population values in another table, which I've merged
# to give me the dataframe I then apply pois.byar to.
DATA$POPN = ifelse(DATA$AREA == "A",2.5,
ifelse(DATA$AREA == "B",3,
ifelse(DATA$AREA == "C",7,0)))
# this bit calculates the number of things per area
rates<-DATA%>%group_by(DISEASE,AREA,POPN)%>%
count(AREA)
Then if I want to calculate CI I thought this would work
rates<-DATA%>%group_by(DISEASE,AREA,POPN)%>%
count(AREA) %>%
mutate(pois.byar(rates$n,rates$POPN))
but i get
Error in mutate_impl(.data, dots) :
Evaluation error: arguments imply differing number of rows: 0, 1.
This however works:
pois.byar(rates$n,rates$POPN)
It seems daft to then say: "turn the results of the pois.byar function into a dataframe and then merge back to the original". I may have tried that just to get some data.... I don't want to do that. It's not the right way to do things.
Any advice gratefully received. I think it's a fairly basic problem. And indicative of my not sitting and learning but trying to do things as I go.
Here's what I want Disease Year n area popn x pt rate lower upper conf.level